Pages

Wednesday 16 November 2011

How to Add Persistent Route in Linux (Centos)

Ever met any situation that when you have two machines in 2 different Private Virtual LANs (VLAN), and you wish to allow them to communicate to each other?

We know we can always make these 2 machines communicate using Public IP Address, but we are not encourage to do so because it is not secure.

Instead of going through public connection, we would prefer them to communicate privately via Private network. Machines in different VLAN are usually not allow to communicate for security purposes. For example:



Therefore, there are some extra little works to let these 2 machines able to communicate.

Route Add. We add another route in 2 machines manually by using route add command in linux. (For route adding in Windows, please refer to How to Add Persistent Route in Windows )

Here is the scenario and steps:

Machine X in VLAN A with netmask 255.255.255.240, gateway 192.168.8.209
Machine Y in VLAN B with netmask 255.255.255.224, gateway 192.168.9.1

Machine X:
1) Open terminal and go to /etc/sysconfig/network-scripts
cd /etc/sysconfig/network-scripts
2) Edit file route-eth1 ( In this scenario, private vlan are using 2nd network card ), or create a new file name route-eth1 if the file is not exists.
nano route-eth1
3)  Type in your command with the following format:
Destination-Network/cidr via Source-Gateway dev Network-Card
     To calculate cidr value, refer to this online calculator:  http://www.subnet-calculator.com/cidr.php
   
      In this scenario it will be:
192.168.9.0/27 via 192.168.8.209 dev eth1
4) Save and exit the editor. Restart the network service by typing the following command:
service network restart
5) Type in route and you can see the route is already there!



6) Repeat same step in Machine Y but change the command to:
192.168.7.208/28 via 192.168.9.1 dev eth1
 7) Now Machine X can ping to Machine Y~


Guide written by Eddy@CRs

How to Add Persistent Route in Windows

Many people would wants their machines in differnt VLAN to communicate. To do that, machines in 2 different VLAN must manually configure a persistent route.

Why persistent route? The answer is very simple, a non-persistent route will disappear after a machine's reboot.

Non persistent route add command:
route add “Destination-Network-IP” mask 255.255.255.255 “Source-gateway”
Persistent route add command , simple add another parameter:
route add “Destination-Network-IP” mask 255.255.255.255 “Source-gateway” -p

 Example:
A machine X (Gateway 192.168.8.209) wants to add a persistent route to destination host at VLAN X with netmask 255.255.255.240 gateway 192.168.2.177.

Command:


route add 192.168.8.176 mask 255.255.255.255 192.168.8.209


Result:


Route added!

Guide Written by Eddy@CRs

A very First Post - Cyborg Repairs

Good day, Cyborg Repairs was launched in November 2011.

Welcome! Currently there are limited resources and information that we able to shares with folks who visits our blog, but please do not worry, more are coming right on the way. Stay tune.

Cyborg Repairs Team
Eddy