Friday 12 April 2013

ROUTING and GATEWAY Configuration (Red Hat, Ubuntu and Windows)


ROUTING and GATEWAY

Gateway:  Gateway is a network point that acts as an entrance to another network. A gateway is required to convert Data packets from one protocol format to another Protocol format, as it connects two dissimilar networks.

Router: A router is connected to two different networks and passes packets between them. Router and Gateway both are sometimes used interchangeably but the difference is that Gateway operates on 7th layer of the OSI Model and the Router works on the 3rd layer of the OSI model.

Here we will describe some routing configuration on different platforms.

Linux Red Hat
1.    To view the current routing table run “route -n
[root@cdacqmail ~]# route -n
Kernel IP routing table
Destination       Gateway                       Genmask           Flags   Metric   Ref    Use Iface
169.254.95.0      0.0.0.0                         255.255.255.0   U          1           0        0 usb0
220.156.188.0     0.0.0.0                         255.255.254.0   U          0           0        0 eth1
169.254.0.0        0.0.0.0                         255.255.0.0        U          1002      0        0 eth0
169.254.0.0        0.0.0.0                         255.255.0.0        U          1003      0        0 eth1
10.0.0.0             0.0.0.0                         255.0.0.0           U          0            0        0 eth0
0.0.0.0               220.156.188.145           0.0.0.0              UG       0           0        0 eth1

2. Adding a Default Gateway

route add default   gw  220.156.188.145
3.    To add a route refers to the command below.

route add -net 10.226.16.0 netmask 255.255.240.0 gw 10.226.0.201

4.    To delete a route refer to the command below.
route del -net 10.226.16.0 netmask 255.255.240.0 gw 10.226.0.201
The routing information above is not persistent across reboots. After a reboot, the routing information will be lost and you need to add them in again.
5.    To make the routing information persistent, add the “route add” line as seen above into the /etc/rc.local file.
Sample /etc/rc.local file.
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.


touch /var/lock/subsys/local
route add -net 10.226.16.0 netmask 255.255.240.0 gw 10.226.0.201


6.    Reject Routing to a Particular Host or Network

route add -host 192.168.1.51 reject

7.    If you want to reject an entire network (192.168.1.1 – 192.168.1.255), then add the following entry.
 route add -net 192.168.1.0 netmask 255.255.255.0 reject



UBUNTU

1.    Adding Route

route add -net $NET netmask $MASK gw $GATEWAY
route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.254


You need to add above syntax to post-up command as follows:
post-up command
post-up route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.254

Given command will run after bringing the interface up.

Example


Edit /etc/network/interfaces, enter:
$ sudo vi /etc/network/interfaces

 
#---------------------------------------#
# Feel free to change IP and gateway    #
# as per your local setup and routing   #
# policy                                #
# Last edited by root @ 23/Oct/2012     #
#---------------------------------------#
 
#--------------------------------------------#
# Setup the loopback network interface (lo0) #
#--------------------------------------------#
auto lo
iface lo inet loopback
 
#--------------------------------------------#
# Setup eth0 - connected to private LAN/VLAN #
#--------------------------------------------#
auto eth0
allow-hotplug eth0
iface eth0 inet static
        address 10.70.201.5
        netmask 255.255.255.192
        ### Ubuntu Linux add persistent route command ###
        post-up route add -net 10.0.0.0 netmask 255.0.0.0 gw 10.70.201.6
 
#----------------------------------------#
# Setup eth1 - connected to the Internet #
#----------------------------------------#
auto eth1
allow-hotplug eth1
iface eth1 inet static
        address 205.153.203.98
        netmask 255.255.255.248
        ### Ubuntu Linux - This is your default gateway ###
        gateway 205.153.203.97
 
Save and close the file.
2.    You need to restart the networking as follows:



$ sudo service networking restart



OR  as root user:


# service networking restart

WINDOWS Server

1.    You can check routing in windows by following step:

C:\Documents and Settings\jitendrakumar>route print

IPv4 Route Table
===========================================================================
Interface List
0x1 ........................... MS TCP Loopback interface
0x20003 ...00 23 ae 77 ee 57 ...... Broadcom NetLink (TM) Gigabit Ethernet
===========================================================================
===========================================================================
Active Routes:
Network Destination        Netmask          Gateway       Interface  Metric
          0.0.0.0          0.0.0.0     10.226.0.201     10.226.1.206     10
         10.0.0.0    255.255.240.0       10.0.0.206     10.226.1.206     10
       10.0.0.206  255.255.255.255        127.0.0.1        127.0.0.1     10
       10.226.0.0    255.255.240.0     10.226.1.206     10.226.1.206     10
     10.226.1.206  255.255.255.255        127.0.0.1        127.0.0.1     10
   10.255.255.255  255.255.255.255     10.226.1.206     10.226.1.206     10
        127.0.0.0        255.0.0.0        127.0.0.1        127.0.0.1      1
       172.20.0.0    255.255.254.0     172.20.0.206     10.226.1.206     10
       172.20.0.0      255.255.0.0       172.20.0.1     10.226.1.206      1
     172.20.0.206  255.255.255.255        127.0.0.1        127.0.0.1     10
   172.20.255.255  255.255.255.255     10.226.1.206     10.226.1.206     10
        224.0.0.0        240.0.0.0     10.226.1.206     10.226.1.206     10
  255.255.255.255  255.255.255.255     10.226.1.206     10.226.1.206      1
Default Gateway:      10.226.0.201
===========================================================================
Persistent Routes:
  Network Address          Netmask  Gateway Address  Metric
172.20.0.0         255.255.0.0       172.20.0.1       1


2.    Adding Route in Window server

route  add <destination> mask <subnet mask> <gateway> metric <lowest number wins> if <interface>
Ex-
route ADD 157.0.0.0 MASK 155.0.0.0 157.55.80.1 METRIC 2 IF 2



3.    Deleting route in windows server

route delete 157.0.0.0 MASK 155.0.0.0 157.55.80.1 METRIC 2 IF 2           

4.    Adding Persistent Route.

Routes added by using the -p option are stored in the Windows registry under the following key:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip \Parameters\PersistentRoutes

route \[-p\] add <destination> mask <subnet mask> <gateway> metric <lowest number wins> if <interface>


metric Metric : Specifies an integer cost metric (ranging from 1 to 9999) for the route, which is used when choosing among multiple routes in the routing table that most closely match the destination address of a packet being forwarded. The route with the lowest metric is chosen. The metric can reflect the number of hops, the speed of the path, path reliability, path throughput, or administrative properties.
if Interface : Specifies the interface index for the interface over which the destination is reachable. For a list of interfaces and their corresponding interface indexes, use the display of the route print command. You can use either decimal or hexadecimal values for the interface index. For hexadecimal values, precede the hexadecimal number with0x. When the if parameter is omitted, the interface is determined from the gateway address.



No comments:

Post a Comment