Tuesday 7 May 2013

How to make a Linux Machine as Bridge/Router between client and server.


Client

ifconfig eth0 10.0.1.1 netmask 255.255.255.0 up

Server

ifconfig eth0 10.0.2.1 netmask 255.255.255.0 up

Router/Bridge

1. Ethernet Interface 1
ifconfig eth0 10.0.1.2 netmask 255.255.255.0 up
2. Ethernet Interface 2
ifconfig eth2 10.0.2.2 netmask 255.255.255.0 up

To make the settings persistent, /etc/network/interfaces file has to be modified.

Client
auto eth0
iface eth0 inet static
address 10.0.1.1
netmask 255.255.255.0
broadcast 10.0.1.255
gateway 10.0.1.2

Server
auto eth0
iface eth0 inet static
address 10.0.2.1
netmask 255.255.255.0
broadcast 10.0.2.255
gateway 10.0.2.2

Router/Bridge
auto eth0
iface eth0 inet static
address 10.0.1.2
nemask 255.255.255.0
broadcast 10.0.1.255
gateway 10.0.1.0
auto eth2
iface eth2 inet static
address 10.0.2.2
netmask 255.255.255.0
broadcast 10.0.2.255
gateway 10.0.2.0

Establish static routers between client and server
route add –net 10.0.2.0 netmask 255.255.255.0 gw 10.0.1.2
route add –net 10.0.1.0 netmask 255.255.255.0 gw 10.0.2.2

To enable IP routing/forwarding in the bridge, locate the line containing net.ipv4.ip_forward in the /etc/syscl.conf file and make the following change.
net.ipv4.ip_forward=1

Reboot after settings are done :)