{"id":219,"date":"2010-07-05T12:56:37","date_gmt":"2010-07-05T17:56:37","guid":{"rendered":"http:\/\/www.rajatswarup.com\/blog\/?p=219"},"modified":"2010-07-05T13:02:17","modified_gmt":"2010-07-05T18:02:17","slug":"reverse-tunnels","status":"publish","type":"post","link":"https:\/\/www.rajatswarup.com\/blog\/2010\/07\/05\/reverse-tunnels\/","title":{"rendered":"Reverse tunnels"},"content":{"rendered":"<p>SSH is an excellent piece of software which can help you do a lot of things such as have encrypted shells etc.  But what makes SSH incredibly flexible is having tunnels.<\/p>\n<p>A typical ssh tunnel works from the client to the ssh server and it forwards a local port on the client to the server seamlessly.<\/p>\n<pre>client ----&gt; ssh_conn ----&gt; ssh_server\r\nclient --&gt; tunneled_port --&gt; ssh_server<\/pre>\n<pre>ssh -L 10000:localhost:10000 username@ssh_server<\/pre>\n<p>This connection creates a tunneled port on client:10000 i.e., anything sent to this port appears as if it&#8217;s automatically sent to ssh_server on port 10000.  The localhost here is confusing, but think of it as&#8230;.&#8221;what is localhost for ssh_server?&#8221;.  It would be the ssh_server itself, right?<br \/>\nIf you do a netstat on the client, you see a listener on the port 10000\/tcp.<\/p>\n<p>Now comes the more interesting reverse tunnel.  The reverse tunnel is different in that, you have a tunnel being initiated by the client that says to the ssh server, &#8220;Hey, I&#8217;m initiating this connection that will allow you to automatically access a port on *me* after *I* initiate the connection?&#8221;  (confused!!?!)<\/p>\n<pre>client ---&gt; ssh_connection ---&gt; server  ---+\r\n                                           |\r\nclient &lt;-- tunneled_port  &lt;----- server ---+<\/pre>\n<pre>ssh -NR 10000:localhost:10000 user@ssh_server<\/pre>\n<p>Here the meaning of localhost is slightly different, though.\u00a0 The &#8220;localhost&#8221; means what is localhost for the client (and not on the server as in the previous case)!\u00a0\u00a0 So what you&#8217;re saying is, &#8220;Hey SSH server, I&#8217;m initiating this connection to you but if you connect to your port 10000 you will get a tunnel to *my* port 10000.&#8221;\u00a0 If you do a netstat on the server you see a listener on port 10000.  Isn&#8217;t it great that you can make the server listen to a port which acts as a tunnel to you&#8230;so anyone on the server can seamlessly connect to you even though technically you were the client!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SSH is an excellent piece of software which can help you do a lot of things such as have encrypted shells etc. But what makes SSH incredibly flexible is having tunnels. A typical ssh tunnel works from the client to the ssh server and it forwards a local port on the client to the server [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[230],"tags":[400,399,398,401],"class_list":["post-219","post","type-post","status-publish","format-standard","hentry","category-howto","tag-networking","tag-reverse_tunnel","tag-ssh","tag-tunnel"],"_links":{"self":[{"href":"https:\/\/www.rajatswarup.com\/blog\/wp-json\/wp\/v2\/posts\/219","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rajatswarup.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rajatswarup.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rajatswarup.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rajatswarup.com\/blog\/wp-json\/wp\/v2\/comments?post=219"}],"version-history":[{"count":4,"href":"https:\/\/www.rajatswarup.com\/blog\/wp-json\/wp\/v2\/posts\/219\/revisions"}],"predecessor-version":[{"id":223,"href":"https:\/\/www.rajatswarup.com\/blog\/wp-json\/wp\/v2\/posts\/219\/revisions\/223"}],"wp:attachment":[{"href":"https:\/\/www.rajatswarup.com\/blog\/wp-json\/wp\/v2\/media?parent=219"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rajatswarup.com\/blog\/wp-json\/wp\/v2\/categories?post=219"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rajatswarup.com\/blog\/wp-json\/wp\/v2\/tags?post=219"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}