By installation default, Linux distribution such as Redhat, CentOS, White OS, and Fedora comes with IP Forwarding disabled. The reason for this is that default linux installation, whether desktop or server, does not consider a default OS installation of forwarding IP packets and request by default, as the linux OS is not fully aware of how the users are planning to make use of the Linux OS installation or even if the users need to enable /IP for
The need to forward IP packets from one source to another using linux as the default gateway or linux router, IP forwarding should be enabled from this considerations. IP Forwarding can be done in many different ways that aims to only one thing, enable IP forwarding.
IP Forwarding Initial Verification
Now, to check for current status of IP forwarding on IPv4 IP class
# cat /proc/sys/net/ipv4/ip_forward
If IP forwarding is disabled, a value of 0 would be displayed and if IP forwarding was recently enabled, linux should be displaying a numerical value of 1.
Alternatively, on most rpm-based linux distributions, checking IP forward status could also be viewed from /etc/sysctl.conf file after initial reboot.
# cat /etc/sysctl.conf | grep net.ipv4.ip_forward
A direct command using kernel sysctl command from terminal would be
# sysctrl net.ipv4.ip_forward
Once again, net.ipv4.ip_forward network parameter should be displaying a value of 1 if IP forwarding is enabled. If you try to view the file, the file should be displaying the below similar line
net.ipv4.ip_forward = 1
Enabling IP Forward Directly from Terminal
If you wish to enable IP Forward from linux,
# echo 1 > net.ipv4.ip_forward = 1
Alternatively, you can use system kernel command to achieve the same effect
# sysctrl -w net.ipv4.ip_forward=1
However, the above command take effect immediately but would not be a permanent change between reboots unles you include them to linux start up files like /etc/rc.local or with other external script called from linux start up process.
Permanent Change for IP Forwarding
To make the changes permanently between reboots, simply backup and edit /etc/sysctl.conf and make sure that the below lines appears from /etc/sysctl.conf
net.ipv4.ip_forward = 1
Save and exit.
With RedHat, CentOs and Fedora, a restart of network service is needed for IP forwarding to take effect when changing values from /etc/sysctrl.conf
# service network restart
Checking IP Forward Changes
# cat /proc/sys/net/ipv4/ip_forward
With the above changes, you would now be able to forward IP packets and request going to another network destination and interface.
Disable IP Forwarding
Disable IP forwarding from linux, simply change the ip_forward kernel directive from 1 to 0 , that is
net.ipv4.ip_forward = 1
Save and exit.
Restart the network service again.
All is done.
0 comments:
Post a Comment