How to bypass blocked ports on a local network and proxy all traffic using EC2

Nino
Nino
Sep 6, 2018 · 2 min read

So here I am, sitting in a restaurant in an Eastern European country and I wanna do some work on Read2Me, a text-to-speech startup of mine, but I can’t connect to the MySQL server or SSH to my instance— hard to work that way.

Let’s fix this — we will start an AWS EC2 instance with SSH listening on port 443 (you can change this, but this port is never closed on local networks) and use sshuttle to proxy all our traffic through the EC2. I will be using an instance in Frankfurt because it’s geographically closest to me (~1000km, 5ms delay each way).

  1. Get an EC2 instance running — choose Ubuntu 18

2. Put this into the user-data field (see screenshot below for example):

#!/bin/bash -ex 
perl -pi -e 's/^#?Port 22$/Port 443/' /etc/ssh/sshd_config
service sshd restart || service ssh restart

Make sure you configure your security policy to allow inbound (ingress) port 443. For the sake of simplicity, I’m just gonna allow all traffic and I’m gonna set the Source to Anywhere.

3. On your local computer, open your terminal (or command prompt if on Windows) and install sshuttle. On Mac it’s like this: brew install sshuttle. Check out the docs for other OSes.

Start the session:

sshuttle --dns -vr ubuntu@YOUR_EC2_HOSTNAME:443  0/0 --ssh-cmd 'ssh -i /PATH/TO/YOUR/KEY.pem'

And that’s it. You don’t need to change any network settings on your computer, this alone will do it.

Using the same port for HTTPS and SSH on EC2

Yes, this is possible — you don’t need to start another server just for the use case discussed in this post, you can use an existing server.

This is done using a multiplexer — check out sshl.

References

How to start an EC2 with SSH running on a custom port: https://stackoverflow.com/a/33612991/1325575

How can I tunnel all of my network traffic through SSH: https://superuser.com/a/757974/375210

Nino

Written by

Nino

Creator of https://read2me.online/

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade