Tuesday, 31 January 2012

Enable IP forwarding in Linux

This can be done in different ways, here are some of the most common.

Use procfs
This is maybe the most used way, it is a temporary change, and you need to enable it after every reboot.
sudo echo 1 > /proc/sys/net/ipv4/ip_forward
You can add this line to /etc/rc.local file, and that way, each time you reboot your computer it will be enabled again.

You can check if IP forwarding is enabled or disabled by checking the content of /proc/sys/net/ipv4/ip_forward file:
cat /proc/sys/net/ipv4/ip_forward
If the output is 1, it is enabled if 0, then it is disabled.

Use sysctl
sysctl let’s you change Kernel values on the fly, so you can use it, to change the IP forward behaviour.

First, let’s check if it is enabled or disabled, as root run:
sysctl -a | grep net.ipv4.ip_forward
Now you can set its value to 1, to enable ip forwarding.
sysctl -w net.ipv4.ip_forward=1
This is also temporary, if you want it to be permanent, you can edit the file /etc/sysctl.conf:

sudo vi  /etc/sysctl.conf
And uncomment or add this line:
net.ipv4.ip_forward = 1
To make it effective you have to use this command
sudo sysctl -p

Possibly Related Posts

No comments:

Post a Comment