<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="FeedCreator 1.8" -->
<?xml-stylesheet href="https://baszerr.eu/lib/exe/css.php?s=feed" type="text/css"?>
<rss version="2.0">
    <channel xmlns:g="http://base.google.com/ns/1.0">
        <title>BaSzErr - blog:2014:09:02</title>
        <description></description>
        <link>https://baszerr.eu/</link>
        <lastBuildDate>Tue, 28 Apr 2026 12:14:33 +0000</lastBuildDate>
        <generator>FeedCreator 1.8</generator>
        <image>
            <url>https://baszerr.eu/lib/exe/fetch.php?media=wiki:dokuwiki.svg</url>
            <title>BaSzErr</title>
            <link>https://baszerr.eu/</link>
        </image>
        <item>
            <title>connection_tunneling_with_ssh</title>
            <link>https://baszerr.eu/doku.php?id=blog:2014:09:02:connection_tunneling_with_ssh</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;connection_tunneling_with_ssh&quot;&gt;2014-09-02 - connection tunneling with SSH&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
&lt;a href=&quot;https://baszerr.eu/lib/exe/detail.php?id=blog%3A2014%3A09%3A02%3Aconnection_tunneling_with_ssh&amp;amp;media=blog:2014:09:02:openssh_logo.png&quot; class=&quot;media&quot; title=&quot;blog:2014:09:02:openssh_logo.png&quot;&gt;&lt;img src=&quot;https://baszerr.eu/lib/exe/fetch.php?media=blog:2014:09:02:openssh_logo.png&quot; class=&quot;mediaright&quot; align=&quot;right&quot; loading=&quot;lazy&quot; title=&quot;OpenSSH logo&quot; alt=&quot;OpenSSH logo&quot; /&gt;&lt;/a&gt;
everyone knows that &lt;a href=&quot;https://en.wikipedia.org/wiki/OpenSSH&quot; class=&quot;interwiki iw_wp&quot; title=&quot;https://en.wikipedia.org/wiki/OpenSSH&quot;&gt;OpenSSH&lt;/a&gt; can do port forwarding. not everyone knows, that it can (nearly) as easily do connection tunneling, using &lt;a href=&quot;https://en.wikipedia.org/wiki/TUN/TAP&quot; class=&quot;interwiki iw_wp&quot; title=&quot;https://en.wikipedia.org/wiki/TUN/TAP&quot;&gt;tun&lt;/a&gt;. the spell is &lt;em&gt;ssh -w 0:0 hostname&lt;/em&gt;. now you have tun0 interfaces on both ends of communication channel (note: “0:0” means tun0 on both ends). the simple script to setup whole communication and do masquerade to enable tunneled network connection for a remote end can be easily created, using following steps.
&lt;/p&gt;

&lt;p&gt;
first TUN interfaces need to be created on both sides – this is done by ssh. assume some-remote-host is a host tunnel needs to be established with. before you start add a following line to the /etc/ssh/sshd_config:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;PermitTunnel yes&lt;/pre&gt;

&lt;p&gt;
this enables tunnels creation. this option is disabled by default, and most likely it is not present even in a commented-out for in the config. add it manually, if needed and restart ssh daemon. having this done establish tunel interfaces on both sides:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;ssh -f -w 0:0 some-remote-host true&lt;/pre&gt;

&lt;p&gt;
next configure tunnel on the remote end. network will consist of two hosts: 192.168.66.6 (local machine) and 192.168.66.7 (on some-remote-host).
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;ssh root@some-remote-host ifconfig tun0 192.168.66.7 netmask 255.255.255.0 up
ssh root@some-remote-host route add -net 192.168.66.0/24 dev tun0&lt;/pre&gt;

&lt;p&gt;
now configure tunnel locally.
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;ifconfig tun0 192.168.66.6 netmask 255.255.255.0 up
sleep 0.3 # needed for tun0 to become ready... dunno why - race?
route add -net 192.168.66.0/24 dev tun0&lt;/pre&gt;

&lt;p&gt;
at this stage both machines are able to ping each other (assuming firewalls are not blocking the traffic).
&lt;/p&gt;

&lt;p&gt;
to enable network, tunneled via newly setup tun0 interfaces, local machine needs to be added as a default gateway on the remote end:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;ssh root@some-remote-host route add default gw 192.168.66.6 dev tun0&lt;/pre&gt;

&lt;p&gt;
…and masquerade needs to be enabled, along with forwarding:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;echo 1 &amp;gt; /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables -P FORWARD ACCEPT&lt;/pre&gt;

&lt;p&gt;
technically that&amp;#039;s all folks! :) if you do this often, this can be scripted easily. if you have via-key authorization configured, this will be fully automated.
&lt;/p&gt;

&lt;/div&gt;
</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Tue, 15 Jun 2021 20:08:55 +0000</pubDate>
        </item>
    </channel>
</rss>
