-1

As the title says, after deleting a rule from the main routing able I am not able to add any route till I do

service network restart 

or

ifup eth0

To reproduce the problem:

ip route list table main
192.168.2.0/24 dev eth0  proto kernel  scope link  src 192.168.2.47 
default via 192.168.2.1 dev eth0 

I can delete and add the default route

#ip route del default
#ip route list
192.168.2.0/24 dev eth0  proto kernel  scope link  src 192.168.2.47 
#ip route add default via 192.168.2.1

#ip route list
192.168.2.0/24 dev eth0  proto kernel  scope link  src 192.168.2.47 
default via 192.168.2.1 dev eth0 

However, if I delete the 192.168.2.0/24 route I can't add any route anymore.

# ip route del 192.168.2.0/24

# ip route list
default via 192.168.2.1 dev eth0 
# ip route add 192.168.2.0/24
RTNETLINK answers: No such device

# ip route add 192.168.2.0/24 via 0.0.0.0
RTNETLINK answers: No such device
# ip route add 192.168.2.0/24 src 192.168.2.47
RTNETLINK answers: No such device
# ip route list
default via 192.168.2.1 dev eth0 
2
  • Why on earth would you want to do that? Is there a business need for this, or are you just asking a question that boils down to "when I break the routing table, routing stops working"?
    – MadHatter
    Aug 4, 2014 at 14:14
  • basically we ship centos on a small pc based device to our customers. Occasionally they do break the routing table by doing something like this. I was wondering if there any way to fix it without rebooting the box.
    – chandank
    Aug 4, 2014 at 15:31

2 Answers 2

2

The reason for this is that you actually have two routing table entries. First there is the default, which points at the gateway 192.168.2.1 in 192.168.2.0/24 network, and then there is the network route for network for interface eth0 (ie. 192.168.2.0/24) as well.

If you delete the network route of an active, it effectively shuts it down. In this particular case deleting the route 192.168.2.0/24 means you have no usable interfaces for routes and thus adding routes will fail.

Summa summarum: You are simply doing it wrong or at lest in wrong order. Don't delete the 192.168.2.0/24 network, if you have an active interface in that network.

5
  • 1
    I question your use of "happens to be"; next-hop-route generally has to be in the local broadcast network, or you can't use it.
    – MadHatter
    Aug 4, 2014 at 14:20
  • After reading what I wrote, I agree.
    – user192911
    Aug 4, 2014 at 14:24
  • Fair enough; +1 from me.
    – MadHatter
    Aug 4, 2014 at 14:28
  • Thanks for answering the question, however, I can't accept the fact that in Linux you can't fix something without reboot.
    – chandank
    Aug 4, 2014 at 21:14
  • That is not at all what is written above. There is no reboot required. Only that whatever you're trying to do is simply not going to work, reboot or not.
    – user192911
    Aug 5, 2014 at 11:50
0

Finally I got myself the problem.

Basically while adding a route we also need to define the scope and proto as well.

In my case the reason I was not able to add it back because I was not specifying the scope. Scope defined visibility of the IP in the network. It could be host, link [limited to LAN], gloabal etc.

So the correct syntax to add it would be

ip route add 192.168.2.0/24 via 0.0.0.0 dev eth0 scope link

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .