📜 ⬆️ ⬇️

Mac OS Routing with VPN Connection

There was once a task to connect via VPN to a working network in order to have access to internal resources.
You can do this with Mac tools by creating a VPN connection and 2 options:
1. put a tick "Send all traffic through a VPN connection"
2. Statically prescribe statically route add-net 192.168.10.0/24 192.168.44.1, where 192.168.10.0/24 is the network where the computers are located at work, 192.168.44.1 VPN gateway to which I connect.

So after each connection you need to do a second manipulation, since the general access to the Internet is limited and the speed is not great. Or the task is to go to sites (for example, youtube) through a faster VPN channel ...


')
So I solved the problem as follows:
created script: touch /etc/ppp/ip-up
gave him execution rights: chmod +x /etc/ppp/ip-up
created a log file: touch /tmp/ppp.log

Script content:
#!/bin/sh
VPNWORK="192.168.44.1"; # ( VPN )
if [ $IPREMOTE = $VPNWORK ] #,
then
/sbin/route -n add -net 192.168.10.0/24 $IPREMOTE > /tmp/ppp.log 2>&1
fi


Thus, after connecting to the network, the route is added, and there is no need to add it manually, as well as disconnecting from the VPN, it is deleted by itself.

If you need to add a DNS server, you can add text between then and fi:
echo "nameserver 4.2.2.1" > /etc/resolv.conf
Instead of 4.2.2.1, specify your primary DNS and a second entry working.

But at the same time, after disconnecting, we need to return the previous DNS config to the site, for this we create: touch /etc/ppp/ip-down && chmod +x /etc/ppp/ip-down

Before starting work we make backup:
cp /etc/resolv.conf /etc/resolv.conf_original

and add to the script / etc / ppp / ip-down:
#!/bin/sh
cat /etc/resolv.conf_original > /etc/resolv.conf


Actually everything. With each VPN connection, a route is prescribed, you work as long as you need, after a shutdown, it is deleted, and you will not have DNS snags.

Source: https://habr.com/ru/post/88946/


All Articles