GOOGLE Search

Google
 

Wednesday, March 26, 2008

Linux Tip No. 36: How to Enable IP Forwarding

Enable IP Forwarding

1. Check if IP Forwarding is enabled

Using sysctl:

[root@proxy ~]# sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 0

or just checking out the value in the /proc system:

[root@proxy ~]# cat /proc/sys/net/ipv4/ip_forward
0

Value 0 means it is disabled.

2. Enable IP Forwarding on the fly

[root@proxy ~]#sysctl -w net.ipv4.ip_forward=1

or

[root@proxy ~]#echo 1 > /proc/sys/net/ipv4/ip_forward

the setting is changed instantly; the result will not be preserved after rebooting the system.


3. Permanent setting using /etc/sysctl.conf

If we want to make this configuration permanent the best way to do it is using the file /etc/sysctl.conf where we can add a line containing net.ipv4.ip_forward = 1

[root@proxy ~]#vi /etc/sysctl.conf 
# Controls IP packet forwarding
net.ipv4.ip_forward = 1


if you already have an entry net.ipv4.ip_forward with the value 0 you can change that 1.

To enable the changes made in sysctl.conf you will need to run the command:

[root@proxy ~]#sysctl -p /etc/sysctl.conf

Restart the network service

[root@proxy ~]#service network restart

0 comments: