IP forwarding is a concept to make Linux machine to send data from one network to other, this is same as a router(A router is a device to send packets from one point to other point depending on the packet destination/rules etc).
Why we need IP forwarding on a Linux machine?
Ans : We need IP forwarding on a Linux machine because to make it as a router or proxy server to share one internet connection to many client machines.
Let me explain how this will work with small example.
You have 2 machines which are in different network(PC1 in 10.0.0.0/255.0.0.0 network and PC2 in 192.168.0.0/255.255.255.0 network) and connected with a Linux machine(which is having two network interfaces). The IP address is as follows..
PC1: 192.168.0.1/255.255.255.0 default gateway:192.168.0.2
PC2: 10.0.0.1/255.0.0.0 default gateway:10.0.0.2
Linuxbox eth0 : 192.168.0.2/255.255.255.0
eth1 : 10.0.0.2/255.0.0.0
and Linuxbox is having two LAN cards which are connected to both the machines as shown below
So do you think PC1 is capable of communicating with PC2?
Ans : The answer to this question is No.
How to make PC1 to communicate with PC2?
Ans : The answer is enable ip forwarding on Linux machine. Some times this is known as bridging two networks.
To make IP forwarding we have to edit /etc/sysctl.conf as shown below. Open sysctl.conf and change the value of “net.ipv4.ip_forward” from 0 to 1 and save the file
net.ipv4.ip_forward = 0
net.ipv4.ip_forward = 1
Once it's done still you are not able to ping from PC1 to PC2. We have to restart the linuxbox to take this update to kernel.
Why to restart if it's a production machine try below command to make your linuxbox aware of IP forwarding without a restart.
echo 1 > /proc/sys/net/ipv4/ip_forward
Now try to ping from PC1 to PC2 which will ping successfully.
Please visit https://www.linuxnix.com for more Linux admin stuffThe following two tabs change content below.Mr Surendra Anne is from Vijayawada, Andhra Pradesh, India. He is a Linux/Open source supporter who believes in Hard work, A down to earth person, Likes to share knowledge with others, Loves dogs, Likes photography. He works as Devops Engineer with Taggle systems, an IOT automatic water metering company, Sydney . You can contact him at surendra (@) linuxnix dot com.
Latest posts by Surendra Anne (see all)
- FREE: JOIN OUR DEVOPS TELEGRAM GROUPS - August 2, 2019
- Review: Whizlabs Practice Tests for AWS Certified Solutions Architect Professional (CSAP) - August 27, 2018
- How to use ohai/chef-shell to get node attributes - July 19, 2018
- wget download a file to a directory in Linux/Unix - June 4, 2018
- GIT: How to compare two GIT branches? - June 3, 2018