If I add a route with
ip route add 220.127.116.11/24 via 10.0.0.100 dev eth0
and then execute the same command a second time, it fails because the route is already present.
I don't see that behavior documented anywhere. Is it safe to depend on this behavior, or might different / future versions of Linux allow duplicate routes?
I'm writing a bash script that configures the routing table. I want to make it safe to run the script multiple times.
I see two options:
ip route addcommand within an
ifstatement that runs
ip route listand uses regex to check if the route is already in place.
ip route addand ignore if it fails because the route already exists.
The first doesn't seem very robust, as I have to depend on the output format of
ip route list. The second seems to depend on undocumented behavior.