How to change kernel parameters per individual network interface

Solution Verified - Updated -


Red Hat Enterprise Linux 5
Red Hat Enterprise Linux 6


How kernel parameters related to networking ("accept_source_route" for example) can be set on a per-interface basis?


Per-interface setting of kernel parameters is possible. The full name for the parameter will be "net.ipv4.conf.<interface_name>.<parameter_name>" for IPv4 address space and "net.ipv6.conf.<interface_name>.<parameter_name>" for IPv6.

Example here is "accept_source_route" kernel parameter. Please see below all interfaces for which it is defined:

# sysctl -a | grep accept_source
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.conf.lo.accept_source_route = 0
net.ipv4.conf.eth0.accept_source_route = 0
net.ipv4.conf.eth1.accept_source_route = 0
net.ipv4.conf.eth2.accept_source_route = 0

There are 2 special interface names 'all' and 'default' which are self-explanatory. You can see all kernel parameters which can be changed for the given interface ('eth0' here) and given address space (IPv4 here) like:

# sysctl -a | grep net.ipv4.conf.eth0
net.ipv4.conf.eth0.forwarding = 0
net.ipv4.conf.eth0.promote_secondaries = 0
net.ipv4.conf.eth0.accept_local = 0

To set "accept_source_route" kernel parameter to "1" for "eth0" interface temporary (until the reboot) use the command:

# sysctl -w net.ipv4.conf.eth0.accept_source_route=1

For a permanent change add the line "net.ipv4.conf.eth0.accept_source_route = 1" to "/etc/sysctl.conf" file and apply it by running "sysctl -p" command or reboot the server.

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.