Unable to add more than 1 static route
I'm trying to add multiple persistent static routes using the networksetup command. I've used this method in the past and am now running into a strange issue, where I only seem to be able to add 1 route. For instance, if I go to add another route the previous route will be overwritten with the new.
I've only recently started using this method of adding routes to OSX. Is this normal behaviour?
Here are the commands I'm using:
# networksetup -setadditionalroutes "Ethernet 1" 10.0.0.0 255.0.0.0 69.69.69.69
Then when I run getadditionalroutes, it will only display the last entered route. For example…
# networksetup -getadditionalroutes "Ethernet 1"
10.0.0.0 255.0.0.0 69.69.69.69
# networksetup -setadditionalroutes "Ethernet 1" 20.0.0.0 255.0.0.0 69.69.69.69
# networksetup -getadditionalroutes "Ethernet 1"
20.0.0.0 255.0.0.0 69.69.69.69
What is the best way for me to achieve my goal?
If you want to set additional routes either add all routes:
networksetup -setadditionalroutes "Ethernet 1" 10.0.0.0 255.0.0.0 69.69.69.69 20.0.0.0 255.0.0.0 69.69.69.70
or set a variable with the existing additional routes:
ADDITIONALROUTES=$(networksetup -getadditionalroutes "Ethernet 1")
which yields e.g.
echo $ADDITIONALROUTES
10.0.0.0 255.0.0.0 69.69.69.69
and then use
networksetup -setadditionalroutes "Ethernet 1" $ADDITIONALROUTES 20.0.0.0 255.0.0.0 69.69.69.70
to add other routes without loosing the old routes.