Share one VPN connection

My personal Linux laptop is a real spider in the web. It's got OpenVPN connections to the office, to the datacenter, to serveral family members, etcetera. I love it. But sometimes, there are some tasks that Linux simply can't do, like running a vSphere client.

For those situations, I use the second (Windows) computer on my desk to perform those tasks. However, this computer does not have a VPN connection right to the place I'm connecting to.

So, what do I do?


In the examples, my configuration will be:

  • VPN bridged to the office network.
  • My windows machine is on
  • My office range is
  • My laptop has locally and on the office side
  • IP Forwarding

    First of all, I tell my laptop's Linux kernel to forward tcp (ipv4) packages:
    echo 1 > /proc/sys/net/ipv4/ip_forward
    You may want to put this in some bootup script...

    Source NAT

    Then, I make my laptop perform SNAT (source nat) on outbound packages to make the office/datacenter network believe it's actually the laptop connecting instead of the windows desktop machine:
    iptables -t nat -I POSTROUTING -s [win-ip-here] -d [network here] -j SNAT --to-source [laptop-ip]
    For my situation, the command would be:
    iptables -t nat -I POSTROUTING -s -d -j SNAT --to-source
    You may want to put this in some bootup script as well...
    If your VPN is not bridged, but routed, you may need to enter the ip of your PtP partner instead of the

    Static route

    And finally, I tell my Windows machine that packages for my office network should be sent to the laptop, using the netsh command.
    netsh interface ipv4 add route interface="Local Area Network" nexthop= store=persistent
    netsh interface ipv4 add route interface="Local Area Network" nexthop= store=active (temporary)

    That's all

    Now connect to your office ips from your second pc. In my situation, I use OpenVPN, but any kind of VPN can do this, as long as your operating system is smart enough to route and perform SNAT.

    © GeekLabInfo Share one VPN connection is a post from You are free to copy materials from, but you are required to link back to
    1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5,00 out of 5)

    Geef een antwoord

    Het e-mailadres wordt niet gepubliceerd.