How to Delete a Route in Red Hat 6.6

Deleting a route from the routing table in Linux should be simple. However, the syntax of the route command can be a little fussy.

I wanted to remove the first entry in the routing table shown below:

Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
172.26.62.25    10.149.57.129   255.255.255.255 UGH       0 0          0 eth4.2251
10.149.55.128   *               255.255.255.240 U         0 0          0 eth3.2261
10.149.57.128   *               255.255.255.240 U         0 0          0 eth4.2251
link-local      *               255.255.0.0     U         0 0          0 eth3.2261
link-local      *               255.255.0.0     U         0 0          0 eth4.2251
default         10.149.55.129   0.0.0.0         UG        0 0          0 eth3.2261

The correct command was:

# route del -host 172.26.62.25 gw 10.149.57.129
# netstat -r
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
10.149.55.128   *               255.255.255.240 U         0 0          0 eth3.2161
10.149.57.128   *               255.255.255.240 U         0 0          0 eth4.2251
link-local      *               255.255.0.0     U         0 0          0 eth3.2261
link-local      *               255.255.0.0     U         0 0          0 eth4.2251
default         10.149.55.129   0.0.0.0         UG        0 0          0 eth3.2261

The following also works, though admittedly this is on Red Hat 6.5:

[root@jim-redhat65 ~]# ip route del 172.26.62.25 via 10.149.57.129

Baffling Error Messages

Attempts to remove the route with the following commands failed, with the cryptic error “SIOCDELRT: No such device“:

# route delete 172.26.62.25/32  10.149.57.129
SIOCDELRT: No such device
# route del 172.26.62.25  10.149.57.129
SIOCDELRT: No such device
# route del 172.26.62.25/32  10.149.57.129
SIOCDELRT: No such device
# route del -host 172.26.62.25   10.149.57.129
SIOCDELRT: No such device

It seems, roughly, that “SIOCDELRT: No such device” happens when the command can’t identify which route you are talking about. A situation where it does know the route but you are trying to do something nonsensical with it seems to result in the equally unhelpful “SIOCADDRT: No such process”. For example…

Adding a Route on Red Hat 6

On Red Hat 6.5 again:

[root@jim-redhat65 ~]# netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
172.27.99.10    192.168.237.150 255.255.255.255 UGH       0 0          0 eth5
172.27.99.9     192.168.237.150 255.255.255.255 UGH       0 0          0 eth5
192.168.2.0     0.0.0.0         255.255.255.0   U         0 0          0 eth4
192.168.237.0   0.0.0.0         255.255.255.0   U         0 0          0 eth5
169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth5
169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth4
0.0.0.0         192.168.237.2   0.0.0.0         UG        0 0          0 eth5
[root@jim-redhat65 ~]# route add 172.27.99.11/32 gw 10.214.49.150
SIOCADDRT: No such process

It happens because the chosen gateway 10.214.49.150 is not not routable from any interface on the local machine (either eth4 or eth5). Try again with a different gateway:

[root@jim-redhat65 ~]# route add 172.27.99.11/32 gw 192.168.237.150

That works, because 192.168.237.150, (it actually doesn’t exist) is routable as an IP address. It can be contacted from eth5, which is on the same vlan. Therefore the desired route makes sense, and the kernel is happy to add it.

Acknowledgements

Thanks to the ever reliable Softpanarama web pages for the route del command. (See under the Typical Operations section). The same page also has a nice introduction to policy based routing.

Leave a Reply

Your email address will not be published. Required fields are marked *