IPv6 Kernel: Bagaimana mengakses /proc-filesystem

From OnnoWiki
Revision as of 10:35, 27 June 2013 by Onnowpurbo (talk | contribs)
Jump to navigation Jump to search

Menggunakan “cat” dan “echo”

Menggunakan “cat” dan “echo” adalah cara yang paling sederhana untuk mengakses filesistem /proc, akan tetapi beberapa pra-syarat dibutuhkan agar itu bisa dilakukan,

  • Filesistem /proc harus di enable di kernel, oleh karenanya waktu compile harus di set agar
CONFIG_PROC_FS=y
  • Filesistem /proc harus di mount sebelumnya, dapat di test menggunakan
# mount | grep "type proc"
proc on /proc type proc (rw,noexec,nosuid,nodev)
  • Kita perlu ijin untuk read, dan kadang-kadang write (biasanya hanya root) ke filesistem /proc

Biasanya, hanya /proc/sys/* yang bisa di write, sementara lainnya biasanya readonly dan hanya bisa di baca informasinya saja.


Membaca Nilai

Nilai dari sebuah parameter dapat di baca menggunakan “cat”:

# cat /proc/sys/net/ipv6/conf/all/forwarding
0

Menset Nilai

Nilai baru dapat di set (jika parameter tersebut writeable) menggunakan “echo”:

# echo "1" >/proc/sys/net/ipv6/conf/all/forwarding


Menggunakan “sysctl”

Menggunakan program “sysctl” untuk mengakses switch kernel adalah cara modern yang digunakan sekarang.Kita dapat menggunakan cara tersebut jika filesystem /proc tidak di mount. Tapi kita hanya bisa mengakses /proc/sys/*!

Program “sysctl” termasuk dalam paket “procps” (di Red Hat Linux).

The sysctl-interface had to be enabled in kernel, means on compiling following switch has to be set

CONFIG_SYSCTL=y

11.1.2.1. Retrieving a value

The value of an entry can be retrieved now:

# sysctl net.ipv6.conf.all.forwarding
net.ipv6.conf.all.forwarding = 0

11.1.2.2. Setting a value

A new value can be set (if entry is writable):

# sysctl -w net.ipv6.conf.all.forwarding=1
net.ipv6.conf.all.forwarding = 1

Note: Don't use spaces around the “=” on setting values. Also on multiple values per line, quote them like e.g.

# sysctl -w net.ipv4.ip_local_port_range="32768 61000"
net.ipv4.ip_local_port_range = 32768 61000

11.1.2.3. Additionals

Note: There are sysctl versions in the wild which displaying “/” instead of the “.”

For more details take a look into sysctl's manpage.

Hint: for digging fast into the settings, use the option “-a” (display all entries) in conjunction with “grep”.

11.1.3. Values found in /proc-filesystems

There are several formats seen in /proc-filesystem:

  • BOOLEAN: simple a “0” (false) or a “1” (true)
  • INTEGER: an integer value, can be unsigned, too
   more sophisticated lines with several values: sometimes a header line is displayed also, if not, have a look into the kernel source to retrieve information about the meaning of each value...