<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="/default.xsl"?>
<fr:tree xmlns:fr="http://www.forester-notes.org" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:xml="http://www.w3.org/XML/1998/namespace" root="false" base-url="/">
  <fr:frontmatter>
    <fr:authors>
      <fr:author>
        <fr:link href="/aram/" title="Aram Hăvărneanu" uri="https://xw.is/aram/" display-uri="aram" type="local">Aram Hăvărneanu</fr:link>
      </fr:author>
    </fr:authors>
    <fr:date>
      <fr:year>2019</fr:year>
      <fr:month>7</fr:month>
      <fr:day>29</fr:day>
    </fr:date>
    <fr:uri>https://xw.is/0006/</fr:uri>
    <fr:display-uri>0006</fr:display-uri>
    <fr:route>/0006/</fr:route>
    <fr:title text="OpenSSH › Connect to laptop (behind NAT) using intermediary server"><fr:link href="/ssh-index/" title="OpenSSH" uri="https://xw.is/ssh-index/" display-uri="ssh-index" type="local">OpenSSH</fr:link> › Connect to laptop (behind NAT) using intermediary server</fr:title>
  </fr:frontmatter>
  <fr:mainmatter>
    <html:p>We'll use a combination of <fr:link href="/openssh/" title="OpenSSH" uri="https://xw.is/openssh/" display-uri="openssh" type="local">ssh</fr:link> <fr:link href="https://www.openssh.com/features.html" type="external">remote and local port forwarding</fr:link> in order to expose the laptop's ssh port outside the NAT. The laptop must initiate the forwarding.</html:p>
    <fr:tree show-metadata="false">
      <fr:frontmatter>
        <fr:authors>
          <fr:author>
            <fr:link href="/aram/" title="Aram Hăvărneanu" uri="https://xw.is/aram/" display-uri="aram" type="local">Aram Hăvărneanu</fr:link>
          </fr:author>
        </fr:authors>
        <fr:date>
          <fr:year>2019</fr:year>
          <fr:month>7</fr:month>
          <fr:day>29</fr:day>
        </fr:date>
        <fr:title text="On the server">On the server</fr:title>
      </fr:frontmatter>
      <fr:mainmatter>
        <html:p>Make sure you have an account that the laptop can connect to through <fr:link href="/openssh/" title="OpenSSH" uri="https://xw.is/openssh/" display-uri="openssh" type="local">ssh</fr:link>.</html:p>
      </fr:mainmatter>
    </fr:tree>
    <fr:tree show-metadata="false">
      <fr:frontmatter>
        <fr:authors>
          <fr:author>
            <fr:link href="/aram/" title="Aram Hăvărneanu" uri="https://xw.is/aram/" display-uri="aram" type="local">Aram Hăvărneanu</fr:link>
          </fr:author>
        </fr:authors>
        <fr:date>
          <fr:year>2019</fr:year>
          <fr:month>7</fr:month>
          <fr:day>29</fr:day>
        </fr:date>
        <fr:title text="On the laptop">On the laptop</fr:title>
      </fr:frontmatter>
      <fr:mainmatter>
        <html:p>This will initiate a connection to the server (from the laptop), and it will set-up a remote port forward such that dialing <html:code>localhost:12345</html:code> <html:em>on the server</html:em> will forward to <html:code>localhost:22</html:code> on the laptop.</html:p>
        <html:pre>ssh -N -R 12345:localhost:22 harieta@freedom.mgk.ro</html:pre>
      </fr:mainmatter>
    </fr:tree>
    <fr:tree show-metadata="false">
      <fr:frontmatter>
        <fr:authors>
          <fr:author>
            <fr:link href="/aram/" title="Aram Hăvărneanu" uri="https://xw.is/aram/" display-uri="aram" type="local">Aram Hăvărneanu</fr:link>
          </fr:author>
        </fr:authors>
        <fr:date>
          <fr:year>2019</fr:year>
          <fr:month>7</fr:month>
          <fr:day>29</fr:day>
        </fr:date>
        <fr:title text="On the other client">On the other client</fr:title>
      </fr:frontmatter>
      <fr:mainmatter>
        <html:p>This will connect to the server, and then set-up a local port forward (from the <html:em>other client</html:em> to the server) such that dialing <html:code>localhost:12345</html:code> <html:em>on the client</html:em> will connect to <html:code>localhost:12345</html:code> <html:em>on the server</html:em>. Of course, <html:code>localhost:12345</html:code> on the server just forwards to <html:code>localhost:22</html:code> on the laptop.</html:p>
        <html:pre>ssh -N -L 12345:localhost:12345 freedom.mgk.ro</html:pre>
        <html:p>Then from another terminal (still on the <html:em>other client</html:em>) you can:</html:p>
        <html:pre>ssh -p 12345 ubuntu@localhost</html:pre>
        <html:p>And should reach localhost:22 <html:em>on the laptop</html:em>.</html:p>
      </fr:mainmatter>
    </fr:tree>
    <fr:tree show-metadata="false">
      <fr:frontmatter>
        <fr:authors>
          <fr:author>
            <fr:link href="/aram/" title="Aram Hăvărneanu" uri="https://xw.is/aram/" display-uri="aram" type="local">Aram Hăvărneanu</fr:link>
          </fr:author>
        </fr:authors>
        <fr:date>
          <fr:year>2019</fr:year>
          <fr:month>7</fr:month>
          <fr:day>29</fr:day>
        </fr:date>
        <fr:title text="Alternatives">Alternatives</fr:title>
      </fr:frontmatter>
      <fr:mainmatter>
        <html:p>Alternativelly, you can use <fr:link href="/tailscale/" title="Tailscale" uri="https://xw.is/tailscale/" display-uri="tailscale" type="local">Tailscale</fr:link>.</html:p>
      </fr:mainmatter>
    </fr:tree>
  </fr:mainmatter>
  <fr:backmatter>
    <fr:tree show-metadata="false" hidden-when-empty="true">
      <fr:frontmatter>
        <fr:authors />
        <fr:title text="References">References</fr:title>
      </fr:frontmatter>
      <fr:mainmatter />
    </fr:tree>
    <fr:tree show-metadata="false" hidden-when-empty="true">
      <fr:frontmatter>
        <fr:authors />
        <fr:title text="Context">Context</fr:title>
      </fr:frontmatter>
      <fr:mainmatter />
    </fr:tree>
    <fr:tree show-metadata="false" hidden-when-empty="true">
      <fr:frontmatter>
        <fr:authors />
        <fr:title text="Backlinks">Backlinks</fr:title>
      </fr:frontmatter>
      <fr:mainmatter />
    </fr:tree>
    <fr:tree show-metadata="false" hidden-when-empty="true">
      <fr:frontmatter>
        <fr:authors />
        <fr:title text="Related">Related</fr:title>
      </fr:frontmatter>
      <fr:mainmatter>
        <fr:tree show-metadata="true" expanded="false" toc="false" numbered="false">
          <fr:frontmatter>
            <fr:authors />
            <fr:uri>https://xw.is/openssh/</fr:uri>
            <fr:display-uri>openssh</fr:display-uri>
            <fr:route>/openssh/</fr:route>
            <fr:title text="OpenSSH">OpenSSH</fr:title>
            <fr:taxon>Software</fr:taxon>
            <fr:meta name="external">https://www.openssh.com</fr:meta>
          </fr:frontmatter>
          <fr:mainmatter>
            <html:p>Premier connectivity tool for remote login with the <fr:link href="https://www.openssh.com/specs.html" type="external">SSH protocol</fr:link>.</html:p>
          </fr:mainmatter>
        </fr:tree>
        <fr:tree show-metadata="true" expanded="false" toc="false" numbered="false">
          <fr:frontmatter>
            <fr:authors />
            <fr:uri>https://xw.is/tailscale/</fr:uri>
            <fr:display-uri>tailscale</fr:display-uri>
            <fr:route>/tailscale/</fr:route>
            <fr:title text="Tailscale">Tailscale</fr:title>
            <fr:taxon>Software</fr:taxon>
            <fr:meta name="external">https://tailscale.com</fr:meta>
          </fr:frontmatter>
          <fr:mainmatter>
            <html:p>Zero-configuration mesh network using <fr:link href="/wireguard/" title="WireGuard" uri="https://xw.is/wireguard/" display-uri="wireguard" type="local">Wireguard</fr:link>.</html:p>
          </fr:mainmatter>
        </fr:tree>
      </fr:mainmatter>
    </fr:tree>
    <fr:tree show-metadata="false" hidden-when-empty="true">
      <fr:frontmatter>
        <fr:authors />
        <fr:title text="Contributions">Contributions</fr:title>
      </fr:frontmatter>
      <fr:mainmatter />
    </fr:tree>
  </fr:backmatter>
</fr:tree>
