Hello Friends,
In this article I am going to configure a Linux Machine as Router .
With the help of this, We can share the internet connection and also we can connect or communicate between two different Network.
For example, My network is having the IP address range of 192.168.11.0/24 and I have a different network which has a network addresses in range 192.168.1.0/24 .
Β For communication between above networks i need two configure a router,
βIf You are going to replace a device, say, a router, You need to replace it with something that can provide the same functionality. In this case, You can chose a Linux server.β
We need to physical Lan Card for Configure that, I have eth0(IP address provided by ISP provider) and eth1 (My other local Networks)
Set the Gateway for all interface :-
#vim /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=linux.sahil.com
GATEWAY=192.168.11.1
:wq!
Save and Quit
Configuration of eth0 (ISP) :-
[root@linux ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
# Please read /usr/share/doc/initscripts-*/sysconfig.txt
# for the documentation of these parameters.
TYPE=Ethernet
DEVICE=eth0
HWADDR=00:1c:c0:1a:61:d0
BOOTPROTO=none
ONBOOT=yes
SLAVE=no
USERCTL=no
PEERDNS=yes
NETMASK=255.255.255.0
IPADDR=192.168.11.10
GATEWAY=192.168.11.1 ==========> Gateway provided by My ISP
Configuration of eth1 My Local Network:-
[root@linux ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1
# VIA Technologies, Inc. VT6105/VT6106S [Rhine-III]
DEVICE=eth1
ONBOOT=yes
HWADDR=00:19:5b:fc:d2:07
BOOTPROTO=none
PEERDNS=yes
ONBOOT=yes
USERCTL=no
TYPE=Ethernet
SLAVE=no
NETMASK=255.255.255.0
IPADDR=192.168.1.3
Now Enable IP forwarding :-
#echo 1 > /proc/sys/net/ipv4/ip_forward
The above method will enable IP forwarding temporarily. If you want to make it permanent, you will have to update the kernel configuration file /etc/sysctl.conf.
Open /etc/sysctl.confwith your favourite editor and search forΒ net.ipv4.ip_forward. Change the value of this to 1 and save the file
#vim /etc/sysctl.conf
net.ipv4.ip_forward =1 #wq! #sysctl -p <============ command to make the changes to take effect.
Masquerade:-
#iptables --table nat --append POSTROUTING --out-interface eth0 -j MASQUERADE
or
#iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
Save the rules:-
#service iptable save
#service iptable restart
#service iptable status
Now You are able to communicate with Network(192.168.1.0/24), and you can access the internet.
Thank You for visiting have a Great Day !!!
Enjoy Linux-Ing π π π
Shahil Just Love Linux π π
