RHEL6-(9)-ROUTES
& DEFAULT GATEWAY -P1
Under Routes & Default Gateway:
We had already seen about Routes &
Gateway before, let’s take in little brief.
Default gateway: A default gateway is a remote host or router that
our Linux host forwards traffic to, when the destination IP address of outgoing
traffic does not match any route in our local routing table
Static route: Static routes are for traffic that must not, or should
not, go through the default gateway.
Default route: If the IP that is to be communicated, does not fall
into any of the other routes than send the packets to the default route.
Network Files:
/etc/sysconfig/network
The "/etc/sysconfig/network" file
holds top-level networking configuration, including the hostname and gateway
settings.
/etc/sysconfig/network-scripts/ifcfg-eth0
The
"/etc/sysconfig/network-scripts/ifcfg-eth0" file holds the network
configuration for the "eth0" adapter.
/etc/hosts
The main purpose of this file is to resolve
hostnames that cannot be resolved any other way. It can also be used to resolve
hostnames on small networks with no DNS server.
/etc/resolv.conf
The "/etc/resolv.conf" file is
used to configure the location of the DNS servers to be used for name
resolution. This file specifies the IP addresses of DNS servers and the search
domain. Unless configured to do otherwise, the network initialization scripts
populate this file.
/etc/nsswitch.conf
The /etc/nsswitch.conf file defines the
order in which to contact different name services.
/etc/sysconfig/network-scripts
DIRECORY
The
"/etc/sysconfig/network-scripts" directory contains a number of
network related scripts and commands.
Default Gateway of system
[root@rhel6-server ~]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.234.0 * 255.255.255.0 U
1 0 0 eth2
192.168.234.0 * 255.255.255.0 U
1 0 0 eth1
192.168.110.0 * 255.255.255.0 U
1 0 0 eth3
192.168.110.0 * 255.255.255.0 U
1 0 0 eth0
default 192.168.110.1 0.0.0.0 UG
0 0 0 eth0
[root@rhel6-server ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.234.0 0.0.0.0 255.255.255.0 U 1
0 0 eth2
192.168.234.0 0.0.0.0 255.255.255.0 U
1 0 0 eth1
192.168.110.0 0.0.0.0 255.255.255.0 U
1 0 0 eth3
192.168.110.0 0.0.0.0 255.255.255.0 U
1 0 0 eth0
0.0.0.0 192.168.110.1 0.0.0.0 UG
0 0 0 eth0
“-n” option to display numerical addresses instead of trying to
determine symbolic host names (via dns or /etc/hosts file).
[root@rhel6-server ~]# netstat -nr
Kernel
IP routing table
Destination Gateway Genmask Flags
MSS Window irtt Iface
192.168.234.0 0.0.0.0 255.255.255.0 U
0 0 0 eth2
192.168.234.0 0.0.0.0 255.255.255.0 U
0 0 0 eth1
192.168.110.0
0.0.0.0 255.255.255.0 U
0 0 0 eth3
192.168.110.0 0.0.0.0 255.255.255.0 U
0 0 0 eth0
0.0.0.0 192.168.110.1 0.0.0.0 UG 0 0 0 eth0
Global system wide default gateway configuration defined by,
[root@rhel6-server ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=rhel6-server
GATEWAY=192.168.234.2
Well, interesting. Global default gateway is different and working
gateway is different.
How…?
From the o/p it is confirmed that we have 2 networks configured.
192.168.234.2
192.168.110.1
Let’s see, which interface is using what.
[root@rhel6-server ~]# ip addr
1:
lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd
00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0:
<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen
1000
link/ether 00:0c:29:80:4e:36 brd ff:ff:ff:ff:ff:ff
inet 192.168.110.137/24 brd 192.168.110.255 scope global
eth0
inet6 fe80::20c:29ff:fe80:4e36/64 scope
link
valid_lft forever preferred_lft forever
3: eth1:
<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen
1000
link/ether 00:0c:29:80:4e:40 brd
ff:ff:ff:ff:ff:ff
inet 192.168.234.146/24 brd 192.168.234.255 scope global
eth1
inet6 fe80::20c:29ff:fe80:4e40/64 scope
link
valid_lft forever preferred_lft forever
4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP>
mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:80:4e:4a brd
ff:ff:ff:ff:ff:ff
inet 192.168.234.147/24 brd 192.168.234.255 scope global
eth2
inet6 fe80::20c:29ff:fe80:4e4a/64 scope
link
valid_lft forever preferred_lft forever
5: eth3:
<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen
1000
link/ether 00:0c:29:80:4e:54 brd
ff:ff:ff:ff:ff:ff
inet 192.168.110.135/24 brd 192.168.110.255 scope global
eth3
inet6 fe80::20c:29ff:fe80:4e54/64 scope
link
valid_lft forever preferred_lft forever
6: pan0:
<BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN
link/ether 4e:9e:c6:34:21:59 brd
ff:ff:ff:ff:ff:ff
Before moving ahead, have you noticed a strange “pan0” interface…?
Personal Area Networking Profile (PAN) allows Bluetooth devices to
form an ad-hoc network, access a remote network through a network access point.
OK, now let’s check their config files.
[root@rhel6-server ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
|grep -i gateway
GATEWAY=192.168.110.1
[root@rhel6-server ~]# cat
/etc/sysconfig/network-scripts/ifcfg-eth1 |grep -i gateway
GATEWAY=192.168.234.2
[root@rhel6-server ~]# cat
/etc/sysconfig/network-scripts/ifcfg-eth2 |grep -i gateway
GATEWAY=192.168.234.2
[root@rhel6-server ~]# cat
/etc/sysconfig/network-scripts/ifcfg-eth3 |grep -i gateway
GATEWAY=192.168.110.1
Now I want to change my default gateway,
[root@rhel6-server ~]# route del default
[root@rhel6-server ~]# netstat -nr
Kernel
IP routing table
Destination Gateway Genmask Flags
MSS Window irtt Iface
192.168.234.0 0.0.0.0 255.255.255.0 U
0 0 0 eth2
192.168.234.0 0.0.0.0 255.255.255.0 U
0 0 0 eth1
192.168.110.0 0.0.0.0 255.255.255.0 U
0 0 0 eth3
192.168.110.0 0.0.0.0 255.255.255.0 U
0 0 0 eth0
[root@rhel6-server ~]# route add default gw 192.168.234.2
[root@rhel6-server ~]# netstat -nr
Kernel
IP routing table
Destination Gateway Genmask Flags
MSS Window irtt Iface
192.168.234.0 0.0.0.0 255.255.255.0 U
0 0 0 eth2
192.168.234.0 0.0.0.0 255.255.255.0 U
0 0 0 eth1
192.168.110.0 0.0.0.0 255.255.255.0 U
0 0 0 eth3
192.168.110.0 0.0.0.0 255.255.255.0 U
0 0 0 eth0
0.0.0.0 192.168.234.2 0.0.0.0 UG 0 0 0 eth2
Is this change temporary or permanent…?
[root@rhel6-server ~]# service network restart
[root@rhel6-server ~]# netstat -nr
Kernel
IP routing table
Destination Gateway Genmask Flags
MSS Window irtt Iface
192.168.234.0 0.0.0.0 255.255.255.0 U
0 0 0 eth2
192.168.234.0 0.0.0.0 255.255.255.0 U
0 0 0 eth1
192.168.110.0 0.0.0.0 255.255.255.0 U
0 0 0 eth3
192.168.110.0 0.0.0.0 255.255.255.0 U
0 0 0 eth0
0.0.0.0 192.168.110.1 0.0.0.0 UG 0 0 0 eth0
Gone, means it was temporary.
But I am eager to make it persistent.
How…??
Let’s do some changes.
[root@rhel6-server ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=rhel6-server
GATEWAY=192.168.234.2
[root@rhel6-server ~]# grep -i gateway /etc/sysconfig/network-scripts/ifcfg-eth0
GATEWAY=192.168.110.1
[root@rhel6-server ~]# service network restart
[root@rhel6-server ~]# netstat -nr
Kernel
IP routing table
Destination Gateway Genmask Flags
MSS Window irtt Iface
192.168.234.0 0.0.0.0 255.255.255.0 U
0 0 0 eth2
192.168.234.0 0.0.0.0 255.255.255.0 U
0 0 0 eth1
192.168.110.0 0.0.0.0 255.255.255.0 U
0 0 0 eth3
192.168.110.0 0.0.0.0 255.255.255.0 U
0 0 0 eth0
0.0.0.0 192.168.110.1 0.0.0.0 UG 0 0 0 eth0
It is still taking 192.168.110.1 via “eth0”
Now,
[root@rhel6-server ~]# grep -i gateway
/etc/sysconfig/network-scripts/ifcfg-eth0
GATEWAY=192.168.234.2
[root@rhel6-server ~]# service network restart
[root@rhel6-server ~]# route
Kernel
IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.234.2 * 255.255.255.255 UH 0
0 0 eth0
192.168.234.0 * 255.255.255.0 U
1 0 0 eth2
192.168.234.0 * 255.255.255.0 U
1 0 0 eth1
192.168.110.0 * 255.255.255.0 U
1 0 0 eth3
192.168.110.0 * 255.255.255.0 U
1 0 0 eth0
default 192.168.234.2 0.0.0.0 UG
0 0 0 eth0
[root@rhel6-server ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=rhel6-server
GATEWAY=192.168.110.2 çç
different gateway
[root@rhel6-server ~]# grep -i gateway
/etc/sysconfig/network-scripts/ifcfg-eth0
GATEWAY=192.168.110.1
[root@rhel6-server ~]# service network restart
[root@rhel6-server ~]# route |grep default
default
192.168.110.1 0.0.0.0 UG
0 0 0 eth0
Well, it means it is taking always “eth0” or the
First Available Interface as reference.
Now disabling the “eth0”
[root@rhel6-server ~]# cd /etc/sysconfig/network-scripts/
[root@rhel6-server network-scripts]# mv ifcfg-eth0
new.ifcfg-eth0.org
[root@rhel6-server ~]# service network restart
[root@rhel6-server network-scripts]# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:0C:29:80:4E:36
inet6 addr:
fe80::20c:29ff:fe80:4e36/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500
Metric:1
RX packets:8 errors:0 dropped:0
overruns:0 frame:0
TX packets:14 errors:0 dropped:0
overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1222 (1.1 KiB) TX bytes:900 (900.0 b)
See, the default route shifted to “eth1”
[root@rhel6-server network-scripts]# route |grep default
default
192.168.234.2 0.0.0.0 UG
0 0 0 eth1
Verify it, by again changing the gateway for “eth1”
[root@rhel6-server ~]# grep -i gateway
/etc/sysconfig/networking/devices/ifcfg-eth3
GATEWAY=192.168.234.2
[root@rhel6-server /]# grep -i gateway
/etc/sysconfig/networking/devices/ifcfg-eth1
GATEWAY=192.168.110.1çç
[root@rhel6-server ~]# service network restart
[root@rhel6-server ~]# route |grep default
default
192.168.110.1 0.0.0.0 UG
0 0 0 eth1
Now, final confirmation,
[root@rhel6-server ~]# vi
/etc/sysconfig/networking/devices/ifcfg-eth1
[root@rhel6-server ~]# grep -i gateway
/etc/sysconfig/networking/devices/ifcfg-eth1
GATEWAY=192.168.200.200çç
[root@rhel6-server ~]# service network restart
[root@rhel6-server ~]# route |grep default
default 192.168.200.200
0.0.0.0 UG 0
0 0 eth1
It seems…
The working default gateway depends upon first available interface.
Good, Now what…
Can I do an interface wise gateway setting…??
Let’s check,
[root@rhel6-server ~]# route add default gw 192.168.234.2
eth1
[root@rhel6-server ~]# route add default gw 192.168.234.2
eth2
[root@rhel6-server ~]# route add default gw 192.168.110.1
eth0
[root@rhel6-server ~]# route add default gw 192.168.110.1
eth3
[root@rhel6-server ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.234.0 0.0.0.0 255.255.255.0 U
1 0 0 eth2
192.168.234.0 0.0.0.0 255.255.255.0 U
1 0 0 eth1
192.168.110.0 0.0.0.0 255.255.255.0 U
1 0 0 eth3
192.168.110.0 0.0.0.0 255.255.255.0 U
1 0 0 eth0
0.0.0.0
192.168.110.1 0.0.0.0 UG
0 0 0 eth3
0.0.0.0
192.168.110.1 0.0.0.0 UG
0 0 0 eth0
0.0.0.0
192.168.234.2 0.0.0.0 UG
0 0 0 eth2
0.0.0.0
192.168.234.2 0.0.0.0 UG
0 0
0 eth1
0.0.0.0
192.168.110.1 0.0.0.0 UG
0 0 0 eth0
But this setting is not permanent.
[root@rhel6-server ~]# service network restart
[root@rhel6-server ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.234.0 0.0.0.0 255.255.255.0 U
1 0 0 eth2
192.168.234.0 0.0.0.0 255.255.255.0 U
1 0 0 eth1
192.168.110.0 0.0.0.0 255.255.255.0 U
1 0 0 eth3
192.168.110.0 0.0.0.0 255.255.255.0 U
1 0 0 eth0
0.0.0.0
192.168.110.1 0.0.0.0 UG
0 0 0 eth0
[root@rhel6-server ~]# ip route add 192.168.110.0/24 via
192.168.110.1
[root@rhel6-server ~]# ip route add 192.168.234.0/24 via
192.168.234.2
[root@rhel6-server ~]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.234.0
192.168.234.2 255.255.255.0 UG 0
0 0 eth2
192.168.234.0 * 255.255.255.0 U
1 0 0 eth2
192.168.234.0 * 255.255.255.0 U
1 0 0 eth1
192.168.110.0
192.168.110.1 255.255.255.0 UG
0 0 0 eth3
192.168.110.0 * 255.255.255.0 U
1 0 0 eth3
192.168.110.0 * 255.255.255.0 U
1 0 0 eth0
default
192.168.110.1 0.0.0.0 UG
0 0 0 eth0
default 192.168.110.1 0.0.0.0 UG
0 0 0 eth0
This setting is also not permanent.
[root@rhel6-server ~]# service network restart
[root@rhel6-server ~]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use
Iface
192.168.234.0 * 255.255.255.0 U
1 0 0 eth2
192.168.234.0 * 255.255.255.0 U
1 0 0 eth1
192.168.110.0 * 255.255.255.0 U
1 0 0 eth3
192.168.110.0 * 255.255.255.0 U
1 0 0 eth0
default
192.168.110.1 0.0.0.0 UG
0 0 0 eth0
Continue…………
No comments:
Post a Comment