Michael Contento

Softwaredeveloper | Azure-Cloud-Ninja | Beekeeper | Dad

Re-routing a nasty VPN connection

2023-02-03 4 min read Networking Security

Using a VPN is usually a good thing, as it allows a secure connection between you and some secret / sensitive things. Those might be single devices (machines, servers etc.) or directly expose you to a whole (sub)network.

So it’s a quite natural solution to deploy a VPN setup when some of you workforce works from outside your sacred office (where you can physically control things). It might be that you employees are working some days from the home office or they might be sales persons who work, by design, “outside”.

The problem

I once got myself in a situation where I was forced to use a VPN to access some ressources, which is usually not a bad thing, but the VPN was configured in a way, that it routes all traffic through this VPN connection.

No just the IP-Range required to access the protected ressource. All of it. No matter if private or work related traffic. Even my online-banking traffic was routed through the VPN.

Making things worse: The VPN was breaking up the SSL chain and doing deep packet inspection and dediced wether or not I was allowed to access various services.

Idea of a solution

I’m per se not a hardcode network engineer but for our solution we only need to know a few basic things:

  • Your computer has a routing table that defined how / where network is passed to
  • This routing table can contain specific rules that, for example, say “route all traffic to through my VPN connection”
  • But it also contains a default route that is used as fallback
  • DNS servers are used to resolve human readable names (like michaelcontento.de) to machine addressable IP addresses (like

With this knowledge in mind we can go and try to understand how the VPN will change our system. Once we know what the VPN client changes, we can find some counter measures 😎

Analysing the mess

I came up with the following strategy to analyse “the mess” the VPN client was producing in my routing table:

  1. Take a snapshot of the routing table before we estable a VPN connection
  2. Take a snapshot of the routing table after we have a VPN connection established
  3. Compare the two states and see what / who we can do about it

Luckily those three steps are pretty easy under macOS (the system I’m using), but same should be true for Linux and Windows.

  1. Before snapshot netstat -rn > before
  2. After snapshot netstat -rn > after
  3. Comparing both diff before after

Pretty easy and this left me with a diff that looks like this:

 2< default         UGScg             en7
 4> default        UGScg           utun3
 5> default         UGScIg            en7
 7>          UGSc              lo0
 8>       UGSc              en7
 9>       UGSc              en7
10> 13.107.64/18       UGSc              en7
11> 13.107.128/22       UGSc              en7
12> 13.107.136/22       UGSc              en7
13> 23.103.160/20       UGSc              en7
14> 40.96/13        UGSc              en7
15> 40.104/15       UGSc              en7
16> 40.108.128/17       UGSc              en7
17> 52.96/14        UGSc              en7
18> 52.104/14       UGSc              en7
19> 52.112/14       UGSc              en7
20> 52.120/14       UGSc              en7
21> 104.146.128/17       UGSc              en7
23>       UGSc              en7
24> 132.245         UGSc              en7
25> 150.171.32/22       UGSc              en7
26> 150.171.40/22       UGSc              en7
27>       UGHS              en7
29>      UGHS            utun3
30>      UGHS            utun3

Looks bad on the first glimpse, but basically it can be read as this:

  • The old default route via gets inactivated
  • A new default route is created that routes everything through
  • Some IP blocks are actively routed through the old default route (
    • I’ve checked some of the IP ranges and they all belong to Microsoft
    • So I suspect this is some whitelisted traffic for MS Teams and other things

The solution

So to achieve our goal, we just need to somewhat “invert” the routing table. Right now we route EVERYTHING through the VPN (except for the whitelisted stuff) but we actually want to route ONLY SELECTED IP ranges.

So for my case the solutions was as simple as this:

  1. Establish the VPN connection as usual
  2. Remove the VPN based default route
    • sudo route -n delete default
  3. Instanciate our local default route again
    • sudo route -n add default
  4. Whitelist the traffic we want to route through the VPN
    • sudo route -n add
  5. Enjoy your free, private and unwachted internet traffic