How to share WiFi/hotspot over SSH tunnel

I have created a SSH tunnel on my laptop connected to LAN. I want to share the internet via WiFi/hotspot, but over the SSH tunnel. I mean any computer using this wireless should connect to the internet via the SSH tunnel (automatically without setting proxy).

In other words, I want to set the proxy setting only on my laptop (e.g.,, and any computer using the WiFi/hotspot from my laptop should be able to use internet without any proxy setting.

Asked By: Googlebot


What you want is not possible with pure SSH (i.e. the -D proxy option to create the poor-mans VPN).

Here’s two options that do work, though:

  1. use sshuttle (available in the repositories) and tell it to forward all traffic from the subnet of your hotspot through the “VPN”. See the manpage for more info.
  2. set up OpenVPN on the remote system and your local system. The traffic of the connected hotspot users should go through the VPN by default. You might also want to look at this serverfault question.
Answered By: mniess

It is possible using pure ssh -D if one adds redsocks and iptables to the mix. This is much simpler than configuring an OpenVPN especially if you don’t have privileges on the remote machine.

For creating the hotspot on Ubuntu I recommend which uses the built-in default network-manager.

With redsocks installed and configured one can use iptables to redirect all traffic from the wifi hotspot to redsocks which then passes it through the socks proxy.

For instance if your wifi hotspot is on the subnet and the incoming redsocks port is 12345 issue:

sudo iptables -F
sudo iptables -t nat -F
sudo iptables -t nat -A PREROUTING -s -p tcp -j REDIRECT --to-ports 12345

For a detailed set of instructions visit

Answered By: Abid H. Mujtaba
Categories: Answers Tags: , , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.