{"id":195,"date":"2025-02-17T12:08:13","date_gmt":"2025-02-17T15:08:13","guid":{"rendered":"https:\/\/vargolino.com\/wp\/?p=195"},"modified":"2026-02-20T10:55:52","modified_gmt":"2026-02-20T13:55:52","slug":"proxy-internet-access-trough-ssh","status":"publish","type":"post","link":"https:\/\/vargolino.com\/wp\/?p=195","title":{"rendered":"Proxy internet access trough SSH"},"content":{"rendered":"\n<p>In a scenario where one machine has access to the internet, and a remote machine does not (due to firewall restrictions), but is accessible via a VPN or something. There is a way to provide internet access for this remote machine.<\/p>\n\n\n\n<p>One way this can be achieved with dynamic port forwarding in SSH, at least for HTTP requests.<\/p>\n\n\n\n<p>Suppose <code>hostA <\/code>is the local machine, which can access the internet; and <code>hostB <\/code>is the machine that is accessible from <code>hostA <\/code>but its access do the internet is blocked by a firewall.<\/p>\n\n\n\n<p>From <code>hostA<\/code>, connect to <code>hostB<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>ssh -R localhost:1080 user@hostB<\/code><\/code><\/pre>\n\n\n\n<p>If already connected, try the escape code <code>~C<\/code> (after an <code>&lt;ENTER&gt;<\/code>) and enter the command and <code>&lt;ENTER&gt;<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>-R localhost:1080<\/code><\/code><\/pre>\n\n\n\n<p>This will open a socks proxy in <code>hostB <\/code>in port 9000, that will forward connections through the SSH connection to be coming out of <code>hostA<\/code>.<\/p>\n\n\n\n<p>Next step is to setup this proxy to be used by <code>hostB<\/code>. For several terminal applications its possible to set this up by exporting a few environment variables.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>export http_proxy=\"socks5h:\/\/localhost:1080\"\nexport https_proxy=\"socks5h:\/\/localhost:1080\"<\/code><\/code><\/pre>\n\n\n\n<p>This way, the HTTP (and HTTPS) requests should be redirected via our new proxy. Using <code>\"socks5h\"<\/code> will also resolve the DNS for these requests via proxy, <code>\"socks5\"<\/code> will try to resolve DNS locally and then make the request to the proxy. This should work for most applications that uses HTTP requests through cURL (older wget versions do no support socks proxies).<\/p>\n\n\n\n<p>Git will use the environment variables (as it uses libcurl for HTTP requests) but you can configure so that only git uses the proxy, or maybe only some repositories:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># configure for this repository only\n<code>git config http.proxy socks5h:\/\/localhost:1080<\/code>\n# configure for all repositories\n<code>git config --global http.proxy socks5h:\/\/localhost:1080<\/code><\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>Of course circumventing firewall restrictions with this can be a security hazard and can be against company security rules.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In a scenario where one machine has access to the internet, and a remote machine does not (due to firewall restrictions), but is accessible via a VPN or something. There is a way to provide internet access for this remote machine. One way this can be achieved with dynamic port forwarding in SSH, at least &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/vargolino.com\/wp\/?p=195\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Proxy internet access trough SSH&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21,3],"tags":[7,9,30,29],"class_list":["post-195","post","type-post","status-publish","format-standard","hentry","category-linux","category-solution","tag-howto","tag-linux","tag-proxy","tag-ssh","entry"],"_links":{"self":[{"href":"https:\/\/vargolino.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/195","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vargolino.com\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vargolino.com\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vargolino.com\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vargolino.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=195"}],"version-history":[{"count":7,"href":"https:\/\/vargolino.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/195\/revisions"}],"predecessor-version":[{"id":229,"href":"https:\/\/vargolino.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/195\/revisions\/229"}],"wp:attachment":[{"href":"https:\/\/vargolino.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=195"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vargolino.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=195"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vargolino.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=195"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}