Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

wizit

macrumors newbie
Original poster
May 18, 2023
8
0
Hi everybody,

I would like to add persistence route on my MacBook to route certain traffic through VPN. The command I am using at terminal is

sudo route -n add -net 172.16.1.0/24 10.8.0.1

The command is running fine and doing its job. The problem is that, when MacBook is rebooted, the route entry in the route table resets and route entry get lost, and requires everytime to run this command at terminal.

How can I make this route permanent/persistent (until I delete) on my MacBook?

Thanks!
 

DarkPremiumCho

macrumors 6502
Mar 2, 2023
276
177
What's the protocol of your VPN? If it's a PPP connection:

sudo echo "#!/bin/sh" > /etc/ppp/ip-up
sudo echo "/sbin/route -n add -net 172.16.1.0/24 10.8.0.1" >> /etc/ppp/ip-up
sudo chmod +x /etc/ppp/ip-up

Your route will be added automatically when the VPN connection is established.

If you really need it permanently, try launchd or networksetup -setadditionalroutes though I have not personally verified them.
 

gilby101

macrumors 68030
Mar 17, 2010
2,920
1,616
Tasmania
The command networksetup -setadditionalroutes will create permanent routes. Read the man page to get the full syntax.
 

wizit

macrumors newbie
Original poster
May 18, 2023
8
0
Thanks, VPN is seup using OpenVPN on Linux and MacOS is connected using Tunnelblick VPN connect client with client config .ovpn file with generated certificate. When VPN is connected it is creating utun3virtual interface. Route command posted in question, only work correctly when VPN is fully established and it get wiped when system reboot. Need to issue route command everytime, when VPN is fully established.
What's the protocol of your VPN? If it's a PPP connection:

sudo echo "#!/bin/sh" > /etc/ppp/ip-up
sudo echo "/sbin/route -n add -net 172.16.1.0/24 10.8.0.1" >> /etc/ppp/ip-up
sudo chmod +x /etc/ppp/ip-up

Your route will be added automatically when the VPN connection is established.

If you really need it permanently, try launchd or networksetup -setadditionalroutes though I have not personally verified them.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.