How to use Linux as router
In this article I will show you that how can you use
Linux as a router. Routers are the devices those are used to connect two
different networks. Routers are very costly devices. Linux could be a cost
effective solution of routing in a small company.
Your system is going use as a router for 192.168.0.0/24 and 192.168.1.0/24. Enable the IP forwarding.
Linux as a Router
In this practical we are using three computers. One
Linux system will be use for routing and reset two will remain in two different
networks. First we will configure the system which is going to play the role of
router.
How to create virtual LAN card
Configure server system
You need two LAN card for routing between two networks
or you can create virtual LAN card instead of deploying them physically.
To create virtual Ethernet card change directory to /etc/sysconfig/network-scripts
ifcfg-eth0 is the necessary script file for
Ethernet 0. Copy this file to the same folder to create new virtual LAN cards.
Now on this newly created virtual LAN card. It could
be done by service
network restart
Run setup command and select network configuration sub window
from list
This Ethernet card will be the default gateway of
first network set its IP to 192.168.1.254 and click on ok
Now select eth0.1 ( This our virtual LAN card which we create in our
last sections)
Set its IP to 192.168.0.254 This will be the default gateway of
other network. Click on OK then quit and quit to come back on command prompt
IP forwarding can be enabled by editing in /etc/sysctl.conf file. open this file
Locate the net.ipv4. ip_forward = 0 tag. and replace the value 0 to 1. This will enable IP forwarding to
permanently . But this require a system reboot.
If don't want to restart the system you can tell
running kernel directly by echo command and kernel will enable the IP forwarding
now configure our client system. we are using two
system one from each network to test the connectivity .
Our first system is a Linux machine run setup command on it
assign its IP address to 192.168.0.1 with a default gateway of 192.168.0.254
now restart the network service and check connectivity
form its default gateway ( Server IP)
Now go on our other host which we are using a window
machine ( You can also use Linux host ) and set IP address to 192.168.1.1 with a default gateway to 192.168.1.254
now open command prompt and test connectivity with
default gateway
At this point you have completed all necessary step's
to enable routing its time to verify this
Test from windows system
ping the Linux host located on other network
Test from Linux system
ping the Window host located on other
network
No comments:
Post a Comment