3

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?

  • First, what version of OSX are you using? Second would you accept other methods/tools to add your route besides networksetup? Finally, what does netstat -r output? – MERM Jan 12 '17 at 16:04
2

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.

  • Aha! Thank you very much, I've done what you suggested in your second line - add all the routes in one command. Cheers – Huckleberry Finn Jan 12 '17 at 17:03

You must log in to answer this question.

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