IP forwarding lets a Linux server pass packets between network interfaces. It is needed for some routers, gateways and VPN servers, but enabling it alone does not configure routes, firewall rules or address translation.
Check the current settings
sysctl net.ipv4.ip_forward
sysctl net.ipv6.conf.all.forwardingA value of 1 enables forwarding; 0 disables it.
Enable forwarding temporarily
With administrative access, enable only the protocols your network needs:
sudo sysctl -w net.ipv4.ip_forward=1
sudo sysctl -w net.ipv6.conf.all.forwarding=1These runtime changes do not make the settings persistent. A restart or another network configuration process can replace them.
Make the settings persistent
On a distribution using sysctl.d, create or edit /etc/sysctl.d/99-ip-forwarding.conf. Retain any existing settings and add the required lines:
net.ipv4.ip_forward = 1
net.ipv6.conf.all.forwarding = 1Apply this file:
sudo sysctl -p /etc/sysctl.d/99-ip-forwarding.confCheck the values again and test the intended network path. Conflicting settings in other files or network management software may override them at startup.
Review firewall forwarding rules and routes before enabling this feature. IPv6 forwarding changes how router advertisements are handled, which can affect connectivity on servers that obtain their IPv6 route that way. Arrange a recovery route before changing a remotely managed server.
To undo the change, restore the previous persistent configuration and runtime values, then verify connectivity.