Linux Networking 101 : Connecting two machines through a Linux router.



We have the below scenario for connecting two machines via a router:


On the Linux router machine, we set up the two interfaces "eth0" and "eth1" as below. 
First we enable the "eth1" interface:


Then we assign an IP address to it:


We also set up the "eth0" interface in the same way:


And we assign an IP address to it:


We then connect the interface "eth0" of the Host B to the "eth1" interface of the Linux router.

Configuration of Host B interface:

We enable the "eth0" interface of the Host B as below:


Then we give it an IP address:


We then add a default route on Host B, so the packet on Host B would know where to "go" when they leave the local subnet:


Enable routing on Linux router:

To enable our Linux router machine to act as a router, we need to set up the IP forwarding as shown in the below command:


Then we run the below command so that the changes would persist after booting the machine:


Configuration of the interface on Host A:

We start by enabling the interface "eth0":


Then we give it an IP address:


We then add a default route on Host A using the below command:


Remark:

The default route is used, when no specific route is set for a given IP address destination.

Comments

Leave as a comment:

Archive