<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="../assets/xml/rss.xsl" media="all"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Hack It Yourself (Posts about networking)</title><link>https://hiy.netlify.app/</link><description></description><atom:link href="https://hiy.netlify.app/categories/networking.xml" rel="self" type="application/rss+xml"></atom:link><language>en</language><copyright>Contents © 2026 &lt;a href="mailto:non@existent.com"&gt;author&lt;/a&gt; </copyright><lastBuildDate>Mon, 26 Jan 2026 02:50:52 GMT</lastBuildDate><generator>Nikola (getnikola.com)</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>OpenVPN how to route Internet traffic through a client</title><link>https://hiy.netlify.app/posts/openvpn-route-traffic-through-client.html</link><dc:creator>author</dc:creator><description>&lt;p&gt;My use case: I want to route all Internet traffic from &lt;code&gt;machine B&lt;/code&gt; through
&lt;code&gt;machine A&lt;/code&gt;. However, I cannot simply install OpenVPN server on &lt;code&gt;machine A&lt;/code&gt; as
&lt;code&gt;machine A&lt;/code&gt; is behind layers of NATs/firewalls I don't control. My current
solution is to &lt;strong&gt;install OpenVPN server on &lt;code&gt;machine C&lt;/code&gt;&lt;/strong&gt;, and have &lt;strong&gt;both
&lt;code&gt;machines A&lt;/code&gt; and &lt;code&gt;B&lt;/code&gt; connect to &lt;code&gt;C&lt;/code&gt; as clients&lt;/strong&gt;. I'm trying to &lt;strong&gt;set up proper
routes so that all traffic from &lt;code&gt;B&lt;/code&gt; can be routed through &lt;code&gt;A&lt;/code&gt;&lt;/strong&gt;. The setup on
each machine and the steps I have attempted are detailed below and my remaining
problem is in the second to last paragraph.&lt;/p&gt;
&lt;p&gt;Now, &lt;code&gt;machine C&lt;/code&gt; runs Linux and OpenVPN server in a Docker container
(https://github.com/kylemanna/docker-openvpn). With &lt;code&gt;redirect-gateway def1&lt;/code&gt;,
both client machines can connect and route traffic through the server
(https://ipleak.net confirms the server IP). For the following tests though,
&lt;code&gt;redirect-gateway def1&lt;/code&gt; is removed, while &lt;code&gt;topology subnet&lt;/code&gt; and
&lt;code&gt;client-to-client&lt;/code&gt; are added. The server has subnet IP &lt;code&gt;192.168.255.1&lt;/code&gt; and
public IP &lt;code&gt;AAA.BBB.CCC.DDD&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;machine A&lt;/code&gt; runs Windows and has &lt;code&gt;IPEnabledRouter=1&lt;/code&gt; set in
&lt;code&gt;HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\&lt;/code&gt;, Service &lt;code&gt;Routing and
Remote Access&lt;/code&gt; set to &lt;code&gt;Automatic&lt;/code&gt; and running, and the network adapter with
Internet access set to allow sharing from the OpenVPN TAP adapter. It is
assigned &lt;code&gt;192.168.255.2&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;machine B&lt;/code&gt; runs Windows and is behind a router with IP &lt;code&gt;192.168.1.100&lt;/code&gt;. It is
assigned OpenVPN subnet IP &lt;code&gt;192.168.255.3&lt;/code&gt;. The following routes are added in
addition to what OpenVPN sets up automatically:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;Network Destination        Netmask          Gateway       Interface  Metric
          0.0.0.0        128.0.0.0    192.168.255.2    192.168.255.3    259
        128.0.0.0        128.0.0.0    192.168.255.2    192.168.255.3    259
  AAA.BBB.CCC.DDD  255.255.255.255      192.168.1.1    192.168.1.100    291
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;From &lt;code&gt;machine B&lt;/code&gt;, I can ping &lt;code&gt;machine A&lt;/code&gt; at &lt;code&gt;192.168.255.2&lt;/code&gt;, but &lt;strong&gt;Internet
traffic is still routed through the OpenVPN server&lt;/strong&gt; (ipleak shows
&lt;code&gt;AAA.BBB.CCC.DDD&lt;/code&gt;). I tried adding a route: &lt;code&gt;route add default gw 192.168.255.2
tun0&lt;/code&gt;, but this makes the clients unable to access Internet. The server route
table typically looks like:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         172.19.0.1      0.0.0.0         UG    0      0        0 eth0
172.19.0.0      0.0.0.0         255.255.0.0     U     0      0        0 eth0
192.168.254.0   192.168.255.2   255.255.255.0   UG    0      0        0 tun0
192.168.255.0   0.0.0.0         255.255.255.0   U     0      0        0 tun0
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;How can I make this work?&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;[EDIT]&lt;/strong&gt; A little more context on the use case: I need to set up VPN for a
division so that their users' home computers &lt;code&gt;machine B&lt;/code&gt; can access third-party
resources that restrict access based on IP address. The access to &lt;code&gt;machine A&lt;/code&gt; is
not blocked, but there are at least two layers of NAT/firewalls up the
organization, whose admins do not want to change their setup to help with
incoming connections. We therefore want to devise a working solution using
`machine C** that may be a VPS as the VPN server. There is an official VPN
service but since it is open to certain outside members, the third-party vendor
does not wish to allow its IP access.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Network Diagram" src="https://hiy.netlify.app/images/openvpn-route-traffic-through-client/network-diagram.png"&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt; In principle, the setup should be similar to
&lt;a href="https://community.openvpn.net/openvpn/wiki/RoutedLans"&gt;RoutedLans&lt;/a&gt;, except that
we cannot simply set &lt;code&gt;machine A&lt;/code&gt; to handle &lt;code&gt;0.0.0.0&lt;/code&gt;. This SF
&lt;a href="https://serverfault.com/a/624988"&gt;answer&lt;/a&gt; explains why packets cannot be
sent through another client as the gateway using the TUN interface. However,
there is a workaround according to the first comment to this
&lt;a href="https://serverfault.com/a/875765"&gt;answer&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;On &lt;code&gt;machine C&lt;/code&gt;:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Add the following to the server configuration:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;topology subnet
client-to-client

route 1.0.0.0 255.0.0.0
route 2.0.0.0 254.0.0.0
route 4.0.0.0 252.0.0.0
route 8.0.0.0 248.0.0.0
route 16.0.0.0 240.0.0.0
route 32.0.0.0 224.0.0.0
route 64.0.0.0 192.0.0.0
route 128.0.0.0 128.0.0.0

push "route 1.0.0.0 255.0.0.0"
push "route 2.0.0.0 254.0.0.0"
push "route 4.0.0.0 252.0.0.0"
push "route 8.0.0.0 248.0.0.0"
push "route 16.0.0.0 240.0.0.0"
push "route 32.0.0.0 224.0.0.0"
push "route 64.0.0.0 192.0.0.0"
push "route 128.0.0.0 128.0.0.0"
&lt;/pre&gt;&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;Set iroutes and a static IP for &lt;code&gt;machine A&lt;/code&gt; in &lt;code&gt;client-config-dir&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;ifconfig-push 192.168.255.2 255.255.255.0
push "route 192.168.255.0 255.255.255.0 192.168.255.1"

iroute 1.0.0.0 255.0.0.0
iroute 2.0.0.0 254.0.0.0
iroute 4.0.0.0 252.0.0.0
iroute 8.0.0.0 248.0.0.0
iroute 16.0.0.0 240.0.0.0
iroute 32.0.0.0 224.0.0.0
iroute 64.0.0.0 192.0.0.0
iroute 128.0.0.0 128.0.0.0
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;On &lt;code&gt;machine A&lt;/code&gt;:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;In &lt;code&gt;HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\&lt;/code&gt;, set
   &lt;code&gt;IPEnableRouter=1&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Set service &lt;code&gt;Routing and Remote Access&lt;/code&gt; to &lt;code&gt;Automatic&lt;/code&gt; and make sure it is
   running.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Set the network adapter with Internet access to allow sharing from the
   OpenVPN TAP adapter. It appears that sharing has to be disabled and
   re-enabled every time the machine is rebooted.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;On &lt;code&gt;machine B&lt;/code&gt;: make sure &lt;code&gt;redirect-gateway def1&lt;/code&gt; is in the client
configuration.&lt;/p&gt;</description><category>home-lab</category><category>linux</category><category>networking</category><category>windows</category><guid>https://hiy.netlify.app/posts/openvpn-route-traffic-through-client.html</guid><pubDate>Sat, 17 Aug 2019 03:35:55 GMT</pubDate></item></channel></rss>