Skip to content

Instantly share code, notes, and snippets.

@GabLeRoux
Last active March 27, 2024 11:23
Show Gist options
  • Save GabLeRoux/c7d4c9046d9b5ec7bce822426613912a to your computer and use it in GitHub Desktop.
Save GabLeRoux/c7d4c9046d9b5ec7bce822426613912a to your computer and use it in GitHub Desktop.

Attempt to manage vpn routing table with /etc/ppp/ip-up

Related Stackoverflow Question:
https://superuser.com/a/206826/55267

Related answer:
https://superuser.com/a/206826/55267

# setup
sudo touch /etc/ppp/ip-up
sudo vim /etc/ppp/ip-up # fill the script
sudo chmod +x /etc/ppp/ip-up
# tail the logs
sudo tail -f /var/log/ip-up.log

Tested on MacOS 10.13 and didn't work for me. Script doesn't get called.
This works, shebang was wrong. Thanks to athairus and Mark Gaensicke in the comments. 🙌

References

Edits

  • 2022-11-02: I've updated the script to reflect suggested changes in comments and I've added logging of the command
#!/bin/sh
now=`date +%Y-%m-%d_%Hh%Mm%Ss`
logfile=/var/log/ip-up.log
echo "$0 called at $now with following params:" >> $logfile
echo "The VPN interface (e.g. ppp0): $1" >> $logfile
echo "Unknown, was 0, in my case: $2" >> $logfile
echo "IP of the VPN server: $3" >> $logfile
echo "VPN gateway address: $4" >> $logfile
echo "Regular (non-vpn) gateway for your lan connections: $5" >> $logfile
# Add 192.168.0.0 to 192.168.0.255 range to routing table on VPN interface
/sbin/route add -net 192.168.0.0/16 -interface $1 >> $logfile 2>&1
@cptfixit
Copy link

cptfixit commented Nov 2, 2022

The script still isn't right :)

You wrote:
#/sbin/route add 192.168.0.0/16 -interface $1

The actual call to route should be:
/sbin/route add -net 192.168.0.0/16 -interface $1

Note that:

  • Your original made it a comment (by starting with #)
  • Without -net it becomes a route for a single address, not for a network.

@GabLeRoux
Copy link
Author

Thanks I've updated the gist accordingly 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment