PuTTY as SOCKS proxy in Ubuntu

I knew how to set up PuTTY to provide a dynamic SOCKS proxy. But when I tried to use it (e.g. to tunnel web access for Firefox) it just did not work. Firefox showed

Connection Interrupted
The connection to the server was reset while the page was loading.

In short, the problem here was that PuTTY running on my Ubuntu 8.04 Hardy Heron box only opened an IPv6 (tcp6) port whereas Firefox only connected to an IPv4 proxy. netstat revealed this clearly:

tux@ubuntu:~$ netstat -ltnu
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN
tcp6       0      0 ::1:48000               :::*                    LISTEN
udp        0      0 0.0.0.0:5353            0.0.0.0:*
...

I then found that the "Auto" setting of PuTTY's dynamic tunnel did not work as expected. I had to set it to "IPv4" as shown:

With "Auto" PuTTY shows the "forwarded port" as "D48000". If you set it to IPv4 and click [Add] it should show up as "4D48000". After this PuTTY listened on the IPv4 side only

tux@ubuntu:~$ netstat -ltnu
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 127.0.0.1:48000         0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN
udp        0      0 0.0.0.0:5353            0.0.0.0:*
...

and Firefox and friends could use it.

Proxy DNS too

While you are it (and as a reminder for myself) consider to configure Firefox to also proxy DNS requests. Unless you set network.proxy.socks_remote_dns in about:config to true Firefox will not send its DNS lookups through your tunnel. Some VPN like setups might even not work at all without it.