Bypassing NAT for Remote Access of Services

Bypassing NAT for Remote Access of Services

When you want to set up a server, you have to set up port forwarding so that you can access your computer outside the network. But what if you aren’t actually allowed to modify your router settings (or forgot your router password lol)? Or maybe you are just too lazy to learn like me? Are there other ways to make network services accessible outside of the LAN? Well, it turns out there are, and I’m going to share some of them

Solutions

Tor

Tor is basically a service to allow people to anonymously access services over the net. Instead of looking at the Dark Net Stuff and whatever privacy concerns, we could just use it to connect to our private network.

To set this up

  1. Install tor through your package manager
  2. Set up the configuration file in /etc/tor/torrc or in ~/.tor/torrc
  3. chmod 700 <HiddenServiceDir>
  4. Run tor

The configuration file should be something like this. You can adjust the service port

## Enable TOR SOCKS proxy
SOCKSPort 127.0.0.1:9050

## Hidden Service: SSH
HiddenServiceDir /home/.tor/hidden_ssh
HiddenServicePort 22 127.0.0.1:8022

To connect to it, install proxychains-ng through your package manager, and run proxychains4 <command> . Another way is to download the Tor app/Tor Browser and connect to the Tor network first, then access the service.

The best part of this solution is that you can forward multiple ports. However, there are also problems like

  1. It is slow to access your network
  2. Connecting to the Tor network is complicated. You have to download the Tor app. When you activate it, all connections are also passed through it and slowed down drastically

Tunnelling

Tunnelling is basically allowing a port on a machine to be accessible through the wider internet, usually by connecting to an intermediate server. There are many such programs available, but here are the more common ones.

ngrok is a popular service that allows you to tunnel HTTP/HTTPS/TCP connections. To use it, you need to go to its website, sign up for an account and download the binary. It works quite well. Just take note that there are limits on the number of ports you can tunnel. However, when forwarding TCP ports, you cant control the output port the service is forwarded to.

localtunnel is similar to ngrok, except that it is totally free, and only supports HTTP/HTTPS services. To use it, you can run this command

npx localtunnel --port 8000 or npx localtunnel-https --port 8000

If you want to install the program to use, you can run

npm install localtunnel
lt --port

Localtunnel is relatively good, just take note that if you first open the given link in the web browser, it’ll give a message to the user before letting them proceed (just some phishing concerns)

Other Remote Controlled Services

Tmate is a service that allows for instant terminal sharing over the network, bypassing any form of NAT. To use it, firstly install tmate through your package manager, and run tmate .

It is easy to set up and use. However, there are some annoying things

  1. All you can kind of do is SSH
  2. Scrolling up and down is an issue. When I SSH from my phone, I cannot scroll to the commands above and this is annoying

Services like Chrome Remote Desktop and Teamviewer also allow remote access to a computer without the need for setting up port forwarding.

Overall

In short, some of the better ones are ngrok (for forwarding TCP connections like SSH), localtunnel (for HTTP) and tmate (for quick remote access). Tor is a good alternative if you need to forward specific ports and control the specific port to forward out of.

Resources