Create Permanent Static Route with Two Lan Card

I want to create routing for my two Lan Card. First Lan Card (eth0) for Internet access, and second Lan Card (eth1) for my Intranet. So when i access internet, it will route to my eth0 by default. otherwise, with eth1 for intranet access.

Public (eth0):
IP: 201.102.21.201
Netmask: 255.255.255.241
Gateway: 201.102.21.1

Intranet (eth1):
IP: 10.1.10.24
Netmask: 255.255.255.0
Gateway: 10.1.10.1

Basic command for adding route on Linux:

route add [-net|-host] <IP/Net> netmask <Mask> gw <Gateway IP> dev <Int>X

And this is what we do:

route add -net 10.0.0.0 netmask 255.0.0.0 gw 10.1.10.1 dev eth1
route add -net default netmask 0.0.0.0 gw 201.102.21.1 dev eth0

To check the route, simply type “route” with no arguments

route

The output will seen like this:

Kernel IP routing table
Destination    Gateway        Genmask           Flags Metric Ref   Use Iface
201.102.21.201Â *Â Â Â Â Â Â Â Â Â Â Â Â Â Â 255.255.255.241Â Â Â Â UÂ Â Â Â 1Â Â Â Â Â Â Â Â Â 0Â Â Â Â Â Â Â 0 eth0
10.1.10.24Â Â Â Â Â Â Â Â Â Â *Â Â Â Â Â Â Â Â Â Â Â Â Â Â 255.255.255.0Â Â Â Â Â Â Â Â Â UÂ Â Â Â Â 1Â Â Â Â Â Â Â Â Â 0Â Â Â Â Â Â Â 0 eth1
link-local        *              255.255.0.0             U   1000    0       0 eth0
10.0.0.0Â Â Â Â Â Â Â Â 10.1.10.1Â Â Â Â Â Â 255.0.0.0Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â UGÂ Â Â 0Â Â Â Â Â Â Â Â Â 0Â Â Â Â Â Â Â 0 eth1
default          201.102.21.1   0.0.0.0                  UG   0         0       0 eth0

Now, to keep this route persistent, add this lines to file /etc/networking/interfaces

up route add -net 10.0.0.0 netmask 255.0.0.0 gw 10.1.10.1 dev eth1
up route add -net default netmask 0.0.0.0 gw 201.102.21.1 dev eth0

Restart networking to confirm the changes

sudo /etc/init.d/networking restart

Other method, Create a file called defaultroute in /etc/init.d and make it executable (chmod +x /etc/init.d/defaultroute).
Add the route commands there and do this:

update-rc.d defaultroute defaults 99

.

Published by Miaz Akemapa

Book minded!!!

Leave a Reply

Your email address will not be published. Required fields are marked *