Skip to content

Instantly share code, notes, and snippets.

@Eradash
Last active August 10, 2018 01:24
Show Gist options
  • Save Eradash/fed087e8653d4a3a67c5d0247495f55e to your computer and use it in GitHub Desktop.
Save Eradash/fed087e8653d4a3a67c5d0247495f55e to your computer and use it in GitHub Desktop.
Route local adresses when using VPN on MacOS

Route local addresses when using VPN on MacOS

Edit ip-up file

The ip-up file is responsible of adding routes to the routing table when a network connection is established. By modifying it, you can add your own routes. A great use case is when you want to access the TLM's Gitlab while on the VPN of a client.

First, you need to know wich interface to use for the new route.

ifconfig will show all interfaces available.

Open /etc/ppp/ip-up and add those lines (replace enX by your interface of choice)

#!/bin/sh
/sbin/route add 10.0.0.5 -interface enX

You can also only add the route with the command route (with sudo)

Make the file executable:

sudo chmod 0755 /etc/ppp/ip-up

Reset your network connection and it should be up.

Yout can check it with sudo route get 10.0.0.5 or with netstat -rn -f inet

Edit the host file

In order to resolve the URL, you will need to add a host in your host file. MacOS will check there first before checking it on the DNS of the VPN.

Add this line to: /private/etc/hosts

10.0.0.5 gitlab.eradash.info

Note

Be sure that the route you want to add is not conflicting with one in the VPN. If so, you wont be able to access the one on your VPN, since it will be redirected to the interface specified in the routing table.

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