How to add a persistent route in Sierra

Hi,


I need to add a persistent static route on my iMac running macOS Sierra but everything I tried failed so far:


What I want to do is to make sure all traffic to a specific subnet like 172.31.0.0/16 goes through the Ethernet connection when the default is the WiFi. And of course the configuration needs to remain after a machine reboot...


Any clue on how to do that on Sierra?


Cedric

iMac, macOS Sierra (10.12.3)

Posted on Mar 15, 2017 9:03 AM

Reply
6 replies

Oct 19, 2017 9:05 AM in response to zepom69

I would recommend you accomplish this with the networksetup utility from the command line. You can set it to add persistent static routes for individual network profiles. I used it to successfully accomplish exactly what you're talking about for both my "Home - Docked" network location, and my "Home - Wifi" location. Be careful that you do not have hyphens in the network service name that you're adding the routes into - it doesn't seem to "like" that (the network locations name doesn't seem to matter much, however).



Hope that helps!


Best,

Pete

Mar 16, 2017 8:29 AM in response to zepom69

Hello again zepom69,

You have to be clear about exactly what is or is not happening. In your first post, you said it "failed". One of the links you tried has been obsolete for over ten years. The other one was correct, but the specific routing being performed was not applicable to what you are right attempting. So I can't tell what the problem is.


Can you explain exactly what system modifications you have made and exactly what the behaviour is?

Mar 16, 2017 9:40 AM in response to etresoft

Sorry for not being clear. I have the following configuration :

- en0 : 172.31.108.187 defaut gw 172.31.108.2

- en1 : 192.168.0.145 default gw 192.168.0.1


What I need to do is to make all the traffic to 172.31.0.0/16 go through en0. To do that, I use the following command and that works fine:


sudo route add -net 172.31.0.0/16 172.31.108.2


But as soon as I restart the computer, this route is lost. I can see the line disappeared when I ran the netstat -rn command.


I tried to set up a LaunchAgent as explained in the first link I posted, but the route was still not there after a reboot. If I look down in the comments, someone else is complaining that it does not work on El Capitan either.


Thank you for the time you take for helping me! I hope I was more clear this time...

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How to add a persistent route in Sierra

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.