Routing

From CLONWiki
Jump to navigation Jump to search

RHEL9

Use nmtui. Select connection you want to configure routing for, and select 'Routing'. Click <Edit...>. For example to route traffic from clonfarm21sro/129.57.69.11 to anything on subnet 129.57.177.0/25 through gateway 129.57.69.1, choose clonfarm21sro and set following:

Destination/Prefix: 129.57.177.0/25
Next hop: 129.57.69.1

Select following options:

[X] Never use this network for default route
[X] Ignore automatically obtained routes
[X] Ignore automatically obtained DNS parameters


After saving and exiting 'nmtui', restart connection:

nmcli connection down <connection>
nmcli connection up <connection>

Check routing table with command ip route.

To check actual route to the machines on 177, use traceroute command, for example:

clonfarm21> traceroute ejfat-fs-daq
traceroute to ejfat-fs-daq (129.57.177.7), 30 hops max, 60 byte packets
1  gw-69.jlab.org (129.57.69.1)  0.451 ms  0.438 ms  0.431 ms
2  * * *
3  * ejfat-fs-daq.jlab.org (129.57.177.7)  0.135 ms  0.129 ms




Solaris

Routing can be checked by command:

netstat -nr

To check traffic for example on 'e1000g1' interface type following command, it will show every 2 seconds:

netstat -I e1000g1 -i 2

For example on clondaq2 it shows following:

Routing Table: IPv4
  Destination           Gateway           Flags  Ref   Use   Interface
-------------------- -------------------- ----- ----- ------ ---------
129.57.68.0          129.57.68.24         U         1      6  e1000g1
129.57.69.0          129.57.69.202        U         1      3  e1000g2
129.57.167.0         129.57.167.109       U         1    546  e1000g0
129.57.16.0          129.57.68.100        UG        1      4  
224.0.0.0            129.57.167.109       U         1      0  e1000g0
default              129.57.167.99        UG        1    356  
127.0.0.1            127.0.0.1            UH        5    180  lo0

In that example traffic was routed to subnet 16 to serve SILO. It was achieved by script /etc/rc3.d/S99manualroute with following contents:

#!/sbin/sh
#
# This script adds a manual route to force traffic to the 16 net
# out the NIC that is on the 129.57.68.x lan. 
#   - P. Letta 04/06/2006
case "$1" in
start)
        /usr/sbin/route add -net 129.57.16.0 -netmask 255.255.252.0 129.57.68.100
        /usr/sbin/route add -net 129.57.166.0 -netmask 255.255.255.0 129.57.68.100
        ;;
stop)
        ;;
*)
        echo "Usage: $0 { start }"
        exit 1
        ;;
esac
exit 0

NOTE: to delete routing setting for example do following:

       /usr/sbin/route delete -net 129.57.166.0 -netmask 255.255.255.0 129.57.68.100


Linux:

clondb1

Add 2 files to /etc/sysconfig/network-scripts/ directory:

route-eth0:

GATEWAY0=129.57.167.99
NETMASK0=0.0.0.0
ADDRESS0=0.0.0.0

route-eth1:

GATEWAY1=129.57.68.100
NETMASK1=255.255.255.0
ADDRESS1=129.67.68.0

Restart network by service network restart. Command route must show following:

[root@clondb1 ~]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
129.57.68.0     *               255.255.255.0   U     0      0        0 eth1
129.57.167.0    *               255.255.255.0   U     0      0        0 eth0
169.254.0.0     *               255.255.0.0     U     0      0        0 eth1
default         hallb-gp.jlab.o 0.0.0.0         UG    0      0        0 eth0
[root@clondb1 ~]# 


from web

If you know there is always going to be a permanent route for a destination then a static route can be a viable option.To add a persistent static route in Redhat Enterprise Linux create a file called route-<int>X in the directory

/etc/sysconfig/network-scripts/

where <int> is the interface number and X is the interface number. As you would expect, these are specified in seperate file for each of the available interface. Example:

/etc/sysconfig/network-scripts/route-eth0
/etc/sysconfig/network-scripts/route-eth1

Every entry or a route has three entities as follows:

GATEWAY<N>=xxx.xxx.xxx.xxx
NETMASK<N>=yyy.yyy.yyy.yyy
ADDRESS<N>=zzz.zzz.zzz.zzz

As the names implies, they are the gateway IP, Netmask and the IP/Network Address. Note the <N> next to each of the three entities. This number defines the route entry number and should be the same on all the entities. Example:

GATEWAY0=192.168.1.1
NETMASK0=255.255.255.0
ADDRESS0=10.10.10.0
GATEWAY1=192.168.1.1
NETMASK1=255.255.255.0
ADDRESS1=20.20.20.2

A sample file /etc/sysconfig/static-routes is available for your reference.

Once the file is created, restart the network service as follows:

# service network restart

To view the routes type

# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0     *               255.255.255.0   U     0      0        0 eth0
192.168.2.0     *               255.255.255.0   U     0      0        0 eth1
10.10.10.0      *               255.255.255.0   U     0      0        0 eth0
20.20.20.2      *               255.255.255.0   U     0      0        0 eth0
169.254.0.0     *               255.255.0.0     U     0      0        0 eth1
default         192.168.1.1     0.0.0.0         UG    0      0        0 eth0

or

# ip route show
192.168.1.0/24 dev eth0  proto kernel  scope link  src 192.168.1.1
192.168.2.0/24 dev eth1  proto kernel  scope link  src 192.168.2.1
10.10.10.0/24 via 192.168.1.1 dev eth0
20.20.20.2/24 via 192.168.1.1 dev eth0
default via 192.168.1.1 dev eth0

To dynamically add a route, try the folowing:

Syntax:
   # ip route add <Net/IP>/<Mask> via <Gateway> dev <Int>X
Example:
   # ip route add 10.10.10.0/24 via 192.168.1.1 dev eth0

or

Syntax:
   # route add [-net|-host] <IP/Net> netmask <Mask> gw <Gateway IP> dev <Int>X
Example:
   # route add -net 10.10.10.0 netmask 255.255.255.0 gw 192.168.1.1 dev eth0

advise

Specify two gateways for two network destinations: (i.e. one external, one internal private network. Two routers/gateways will be specified.)

Add internet gateway as before: route add default gw 201.51.31.1 eth0
Add second private network: route add -net 10.0.0.0 netmask 255.0.0.0 gw 192.168.10.254 eth0

See more here.