RHEL6-(10)-ROUTES
& DEFAULT GATEWAY -P2
Under Routes & Default Gateway:
In UNIX systems routing table consists the information about packet
forwarding.
Route add
Route delete
Making route persistent
Default route configuration
[root@rhel6-server ~]# ip route show
192.168.234.0/24
dev eth1 proto kernel scope link
src 192.168.234.146 metric 1
192.168.234.0/24
dev eth2 proto kernel scope link
src 192.168.234.147 metric 1
192.168.110.0/24
dev eth0 proto kernel scope link
src 192.168.110.137 metric 1
192.168.110.0/24
dev eth3 proto kernel scope link
src 192.168.110.135 metric 1
default
via 192.168.110.1 dev eth0 proto static
[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 eth1
192.168.234.0 0.0.0.0 255.255.255.0 U
0 0 0 eth2
192.168.110.0 0.0.0.0 255.255.255.0 U
0 0 0 eth0
192.168.110.0 0.0.0.0 255.255.255.0 U
0 0 0 eth3
0.0.0.0 192.168.110.1 0.0.0.0 UG 0 0 0 eth0
Now what I want is, the traffic from 192.168.234.0 should follow its
own default gateway 192.168.234.2 via eth1.
[root@rhel6-server ~]# ip route add 192.168.234.0/24 via
192.168.234.2 dev eth1
[root@rhel6-server /]# ip route show
192.168.234.0/24
via 192.168.234.2 dev eth1
192.168.234.0/24
dev eth2 proto kernel scope link
src 192.168.234.147 metric 1
192.168.234.0/24
dev eth1 proto kernel scope link
src 192.168.234.146 metric 1
192.168.110.0/24
dev eth3 proto kernel scope link
src 192.168.110.135 metric 1
192.168.110.0/24
dev eth0 proto kernel scope link
src 192.168.110.137 metric 1
default
via 192.168.110.1 dev eth0 proto static
[root@rhel6-server /]# netstat -nr
Kernel
IP routing table
Destination Gateway Genmask Flags
MSS Window irtt Iface
192.168.234.0 192.168.234.2 255.255.255.0 UG
0 0 0 eth1
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
Changes are effective, but are they persistent…??
NO……
Just,
[root@rhel6-server /]# service network restart
All gone.
As recommended I created a file,
[root@rhel6-server /]# vi
/etc/sysconfig/network-scripts/route-eth1
GATEWAY0=192.168.234.2
NETMASK0=255.255.255.0
ADDRESS0=192.168.234.0
And restart network, but no luck. Then I did,
[root@rhel6-server /]# cat
/etc/sysconfig/network-scripts/route-eth1
#GATEWAY0=192.168.234.2
#NETMASK0=255.255.255.0
#ADDRESS0=192.168.234.0
192.168.234.0/24 via 192.168.234.2 dev eth1 çç
And restart network, but again no luck. Then I did,
[root@rhel6-server /]# vi /etc/sysconfig/static-routes
any net 192.168.234.0 netmask 255.255.255.0 gw 192.168.234.2 eth1
[root@rhel6-server /]# service network restart
And,
[root@rhel6-server /]# netstat -nr
Kernel
IP routing table
Destination Gateway Genmask Flags
MSS Window irtt Iface
192.168.234.0 192.168.234.2 255.255.255.0 UG
0 0 0 eth1
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
Now it is permanent.
Next What…??
Let’s do it again,
ROUTE CONFIGURATION:
ip route [ add | del | change | append | replace ]
destination-address
ROUTE ADD:
Single IP
[root@rhel6-server /]# ip route add 192.168.234.146 via
192.168.234.2 dev eth1
Whole subnet
[root@rhel6-server /]# ip route add 192.168.234.0/24 via
192.168.234.2 dev eth2
We can make it persistent by,
[root@rhel6-server /]# vi /etc/sysconfig/static-routes
any net 192.168.234.0 netmask 255.255.255.0 gw 192.168.234.2 eth1
any net 192.168.110.0 netmask 255.255.255.0 gw 192.168.110.1 eth3
[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 192.168.234.2 255.255.255.0 UG
0 0 0 eth1
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 192.168.110.1 255.255.255.0 UG
0 0 0 eth3
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
We can also do,
Either,
[root@rhel6-server /]# vi
/etc/sysconfig/network-scripts/route-eth1
GATEWAY0=192.168.234.2
NETMASK0=255.255.255.0
ADDRESS0=192.168.234.0
Or,
[root@rhel6-server /]# vi
/etc/sysconfig/network-scripts/route-eth1
192.168.234.0/24 via 192.168.234.2 dev eth1
This method (route-dev_name) did not work for me.
ROUTE DELETE:
Referring o/p from above “netstat –nr”
[root@rhel6-server /]# ip route delete 192.168.234.0/24 via
192.168.234.2 dev eth1
[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 192.168.110.1 255.255.255.0 UG
0 0 0 eth3
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
Delete any corresponding entry if any from “route-eth1” or “static-routes”
file to make it persistent.
[root@rhel6-server /]# ip route delete 192.168.234.0/24
[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 eth1
192.168.110.0 192.168.110.1 255.255.255.0 UG
0 0 0 eth3
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
[root@rhel6-server /]# ip route delete 192.168.234.0/24 dev
eth1
DEFAULT ROUTE REPLACE:
[root@rhel6-server /]# ip route replace default via
192.168.234.2 dev eth1
[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 192.168.110.1 255.255.255.0 UG
0 0 0 eth3
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 eth1
[root@rhel6-server /]# ip route replace via 192.168.110.1
dev eth0
[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
192.168.110.1 255.255.255.0 UG
0 0 0 eth3
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
DEFAULT GATEWAY CONFIGURATION:
[root@rhel6-server /]# route del default gw 192.168.110.1
“OR”
[root@rhel6-server /]# ip route del default via
192.168.110.1
[root@rhel6-server /]# netstat -nr
Kernel
IP routing table
Destination Gateway Genmask Flags
MSS Window irtt Iface
192.168.110.0 192.168.110.1 255.255.255.0 UG
0 0 0 eth3
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 -Cn
Kernel
IP routing cache
Source Destination Gateway Flags Metric Ref Use Iface
192.168.110.1 192.168.110.137 192.168.110.137 l 0
0 549 lo
192.168.110.137
192.168.110.1 192.168.110.1 0
1 0 eth3
“-C” lists the kernel’s routing cache information.
[root@rhel6-server /]# route add default gw 192.168.110.1
“OR”
[root@rhel6-server /]# ip route add default via
192.168.110.1
[root@rhel6-server /]# netstat -nr
Kernel
IP routing table
Destination Gateway Genmask Flags
MSS Window irtt Iface
192.168.110.0 192.168.110.1 255.255.255.0 UG
0 0 0 eth3
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 eth3
[root@rhel6-server /]# route -Cn
Kernel
IP routing cache
Source Destination Gateway Flags Metric Ref Use Iface
192.168.110.137
192.168.110.1 192.168.110.1 0
1 0 eth3
192.168.110.1 192.168.110.137 192.168.110.137 l 0
0 30 lo
192.168.110.1 192.168.110.255 192.168.110.255 bl 0
0 1 lo
CONTINUE………..
No comments:
Post a Comment