I just bought a Raspberry Pi and I am wanting to route an ad hoc wireless network interface fully through an SSH tunnel that was created using another wireless interface. I want to do this so that I can have a secured and private connection to the internet at places with public WiFi. I know this would be easier to do all on one computer, but I would like to have it on the RPi too since I use it for other network related things when I am using the internet, and then just simply connect to the ad hoc network from my laptop/phone. This will really help me with my iPhone because it does not support an SSH tunnel locally. How should I go about doing this? Thanks in advance for all of your help.

  • ssh has a tunneling feature built into it, ssh -w .... I've personally never used it though, but it's supposed to use a TUN device, in which case you can just create routing rules to route traffic through the tunnel. (requires server-side support as well)
    – phemmer
    Commented Aug 23, 2012 at 3:13
  • can you rephrase perhaps? Commented Aug 31, 2012 at 20:17

2 Answers 2


You need a remote machine running ssh that you can connect to from the Pi. Enable AllowTCPForwarding on the remote machine then connect from the Pi and create a SOCKS proxy using the ssh connection. Then configure your iphone to use the Pi as a proxy and there you go.

But there's 2 problems I see, 1, you'll have to make the SOCKS proxy accessible to other hosts on the local network. So you may want to configure MAC address filtering within iptables to allow your phone but block anyone else on the public wifi from finding and using the proxy. 2, last time I checked, iOS devices don't support SOCKS proxies, however a workaround has already been posted here.

Remember though, this will encrypt the traffic from your phone to the Internet but the traffic will still be vulnerable to being sniffed by anyone on the same wireless network because the proxy is on the Pi.

On remote-host in /etc/ssh/sshd_config:

AllowTCPForwarding yes

To initiate the proxy from the Pi:

ssh -g -D 8080 user@remote-host

optionally you may want to use -v to troubleshoot the connection and -N to prevent from opening a shell once you connect.

source: man ssh & man sshd_config


What he's saying is that SSH "now" (the past several years) supports a poor-man's VPN. That being said, may I strongly recommend a different solution? Either way, the learning curve is relatively steep, but if you want secured communications with a solid community, oodles of documentation, and clients that run on just about everything (Windows, Linux, Mac, iPhone, Android... you get the idea), you should check out OpenVPN. See http://openvpn.net/index.php/open-source/documentation/howto.html for lots of good getting-started info, and feel free to subscribe to the (very helpful) mailing list. Unsurprisingly, there's also an OpenVPN-on-Raspberry-Pi tutorial: http://raspberrypihelp.net/tutorials/1-openvpn-server-tutorial .

Lastly, one quick plug: OpenVPN is also crazy robust; unlike, say, my company's Cisco IPSec implementation (or SSH), OpenVPN is very good at seamlessly re-establishing a connection, which is handy for things like phones that wander in and out of connectivity.

I realize this doesn't technically answer your question, but as a long-time IT guy, sometimes it's more important to figure out what the person is trying to accomplish than take a literalist approach to a question.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .