Interfaces and addresses
sysctl
Reads and sets kernel settings, such as whether this device forwards packets like a router.
Linux only forwards packets between its cards when net.ipv4.ip_forward is 1: that setting is the
difference between a host with two cards and a router. Other settings worth knowing: rp_filter (drop packets
arriving on a card the reply would not leave by) and net.ipv6.conf.all.forwarding. The same values are files under
/proc/sys/.
sysctl command usage
sysctl NAME sysctl -w NAME=VALUE sysctl -a
Options
-
-w - write a new value
-
-a - print every setting (pipe it through grep)
-
-n - print the value only
sysctl examples
-
sysctl net.ipv4.ip_forward - Shows whether this device forwards IPv4 packets between its cards.
-
sysctl -w net.ipv4.ip_forward=1 - Turns packet forwarding on: the device now routes.
-
sysctl -a | grep rp_filter - Shows the reverse-path filter setting of every card.
Reading the output
$ sysctl net.ipv4.ip_forward net.ipv4.ip_forward = 1
1: packets arriving for another address are routed on.0: they are dropped, silently.
Pitfalls
- A router with
ip_forward = 0still answers pings to its own addresses, so it looks alive while it passes nothing on. - In a container some settings are read-only (
/proc/sysis mounted read-only): they are set when it is created.