الجمعة، 28 مايو 2010

Linux Networking Confiuring Two gateways

Confiuring 2 gateways


Some networks may have multiple router/firewalls providing connectivity. Here's a typical scenario:

* You have one router providing access to the Internet that you'd like to have as your default gateway (see the default gateway example earlier)

* You also have another router providing access to your corporate network using addresses in the range 10.0.0.0 to 10.255.255.255. Let's assume that this router has an IP address of 192.168.1.254

Here we are going to discuss the following methods to configure Gateways.

1) Adding Temporary Static Routes
2) Adding Permanent Static Routes


- Adding Temporary Static Routes


The route add command can be used to add new routes to your server that will last till the next reboot. It has the advantage of being univeral to all versions of Linux and is well documented in the man pages. In our example the reference to the 10.0.0.0 network has to be preceded with a -net switch and the subnet mask and gateway values also have to be preceded by the netmask and gw switches respectively.

-------------
[root@Basil15099/~# route add -net 10.0.0.0 netmask 255.0.0.0 gw 192.168.1.254 wlan0
-------------

If you wanted to add a route to an individual server, then the "-host" switch would be used with no netmask value. (The route command automatically knows the mask should be 255.255.255.255). Here is an example for a route to host 10.0.0.1.

-------------
[root@Basil15099/~# route add -host 10.0.0.1 gw 192.168.1.254 wlan0
-------------

A universal way of making this change persistent after a reboot would be to place this route add command in the file /etc/rc.d/rc.local, which is always run at the end of the booting process.


- Adding Permanent Static Routes



In Fedora Linux, permanent static routes are added on a per interface basis in files located in the /etc/sysconfig/network-scripts directory. The filename format is route-interface-name so the filename for interface wlan0 would be route-wlan0.
The format of the file is quite intuitive with the target network coming in the first column followed by the word via and then the gateway's IP address. In our routing example, to set up a route to network 10.0.0.0 with a subnet mask of 255.0.0.0 (a mask with the first 8 bits set to 1) via the 192.168.1.254 gateway, we would have to configure file /etc/sysconfig/network-scripts/route-wlan0 to look like this:

-------------
#
# File /etc/sysconfig/network-scripts/route-wlan0
#
10.0.0.0/8 via 192.168.1.254

 -------------

-------------

ليست هناك تعليقات:

إرسال تعليق