Enabling and Disabling Forwarding
As mentioned earlier in this chapter, the kernel exports parameters via /proc that can be used to enable and disable IP forwarding, both globally and on a per-device basis. In this chapter, we will address only IPv4 forwarding.
Even though an administrator can change the forwarding state globally, there really is no global forwarding state. The routing code uses only the per-device forwarding states: global configuration changes are just a convenient way to apply the same change to all devices in one shot. In particular, when the kernel receives an IP packet whose destination address does not belong to the local system, it either forwards the packet or drops it based on the forwarding state of the receiving interface. This is not a decision made on a global basis or on the forwarding state of the device that would be used to transmit the packet out toward its destination.
It is important to understand the relationship between per-device and global configurations, to know how the system is going to behave when you change their values. Here are the relevant /proc files:
-
/proc/sys/net/ipv4/conf/
device_name/ forwarding Enable and disable forwarding on the device
device_name. A value of zero means disabled; any other value means enabled.- /proc/sys/net/ipv4/conf/all/forwarding
Changes to this file are applied to all network devices (including the ones not in the UP state) but do not affect the forwarding state of devices registered in the future.
- /proc/sys/net/ipv4/conf/default/forwarding ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access