Ubuntu – How to check command line requests routed thru Tor

command linetorvirtualbox

I think I have Virtualbox set up so that all traffic originating from the guest OS is routed through Tor. Tor is only installed on the host OS and the web browsers on the guest OS all report Tor IP's in Europe when I test with seemyip.com. The host OS shows my real IP when going to the same sites.

But I initiate a lot of requests from the Linux command line and I haven't been able to confirm to my satisfaction that these are routing through Tor, though I have no reason to think they do not.

When I use this command I get no output from the guest OS, but my real IP from the host OS:

dig myip.opendns.com @resolver1.opendns.com +short

This bash file gives no output from either OS:

#!/bin/bash

echo Your external IP Address is:
wget http://Www.whatismyip.com -O - -o /dev/null | grep '<TITLE>' |\
  sed -r 's/<TITLE>WhatIsMyIP\.com \- //g' | sed -r 's/<\/TITLE>//g'

exit 0

Suggestions?

Best Answer

Usually software which is called from your shell doesn't know about about Tor or any other proxy. So you have to tell it. The bad thing is that many software has specific ways to set a proxy up. Below you find some ways to get Tor working on commandline. I assume that you run a combination of Tor and Privoxy at the IP address 127.0.0.1 and port 8118. This might not true in your case. So you should enter the correct values.

Proxy environment variable

There is a special environment variable which is respected by some shell software. Open your .bashrc (or other shell rc file) and enter the following lines.

export http_proxy="http://127.0.0.1:8118"
export https_proxy=${http_proxy}
export HTTP_PROXY=${http_proxy}
export HTTPS_PROXY=${http_proxy}

Applications like wget, GnuPG and curl are known to respect those values.

torsocks

Torsocks is a helper software with re-routes all requests through Tor. Just prepend the software to any command line call.

torsocks your-shellscript
torsocks wget http://example.org

Furthermore you can also use tor-resolve to get an IP address through Tor.

tor-resolve example.org
torsocks ssh $(tor-resolve my.server.example.org)

SSH

If you're using SSH, you can edit your $HOME/.ssh/config.

Host *
     ProxyCommand socat STDIO SOCKS4A:127.0.0.1:%h:%p,socksport=9050

This setting sends every SSH connection through Tor. However the keyword Host in ssh_config allows you to set it up for special hosts. Please have a look at the manpage of ssh_config.

Further ressources

The TorifyHOWTO at Torproject.org has advice for setting up different services. The toraliases might also give some hints and has a setup for IPtables.