Skip to content

Instantly share code, notes, and snippets.

@glimpsed
Last active April 27, 2023 09:22
Show Gist options
  • Save glimpsed/dcbad6c8924faba6a9b058fec3c24303 to your computer and use it in GitHub Desktop.
Save glimpsed/dcbad6c8924faba6a9b058fec3c24303 to your computer and use it in GitHub Desktop.
How to route network traffic through a VPN (OpenVPN/TunnelBlick) ONLY for specific websites/IPs only on macOS / OS X (static routing)
Add the following line at the top of your .ovpnfile to prevent it from routing all network traffic on your Mac through
the VPN:
route-nopull
Next add the following line to allow the VPN to reroute traffic ONLY for a given IP address / domain (if you need to enable it
for a domain you can use its IP address):
route 1.2.3.4
This can also be used to enable selective traffic re-routing for IP subnets. By adding "route 62.42.34.0", you will enable the
VPN for all IP addresses between 62.42.34.1-255.
Multiple rules can also be added by duplicating the "route 1.2.3.4" line and changing the IP / subnet.
@ShadowofZeus
Copy link

Hi Team, my config is as below:

route-nopull
route 10.0.0.0 255.0.0.0
client
nobind
dev tun
proto udp
sndbuf 0
rcvbuf 0
remote Y.Y.X.C
resolv-retry infinite
nobind
explicit-exit-notify 3
persist-key
persist-tun
remote-cert-tls server

But I am failing to ping the Internet whilst I am connected to my VPN...can you kindly point out where I am wrong? i.e
└─$ ping 4.2.2.2
PING 4.2.2.2 (4.2.2.2) 56(84) bytes of data.

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