Sep 072015
 

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

change directory network script

ifcfg-eth0 is the necessary script file for Ethernet 0. Copy this file to the same folder to create new virtual LAN cards.

cp eth0 eth0.1

Now on this newly created virtual LAN card. It could be done by service network restart

service network restart

Run setup command and select network configuration sub window from list

setup

You have two LAN card here, select eth0 from list to assign IP

select eh0

This Ethernet card will be the default gateway of first network set its IP to 192.168.1.254 and click on ok

assign ip

Now select eth0.1 ( This our virtual LAN card which we create in our last sections)

select eth1

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

assign ip eth1

IP forwarding can be enabled by editing in /etc/sysctl.conf file. open this file

vi /etc/sysctl.conf

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.

change value sysctl.conf

If don’t want to restart the system you can tell running kernel directly by echo command and kernel will enable the IP forwarding

echo command

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

setup commands

assign its IP address to 192.168.0.1 with a default gateway of 192.168.0.254

assign IP address

now restart the network service and check connectivity form its default gateway ( Server IP)

ping

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

ip configurations

now open command prompt and test connectivity with default gateway

ping commands

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

ping replay

Test from Linux system

ping the Window host located on other network

ping replay