How to check command line requests routed thru Tor?

6,752

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.

Share:
6,752

Related videos on Youtube

Chris
Author by

Chris

Updated on September 18, 2022

Comments

  • Chris
    Chris over 1 year

    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?

    • adempewolff
      adempewolff almost 12 years
      Are you sure the global proxy settings are set to route through TOR? Or are the browsers using their individual proxy support?
    • Chris
      Chris almost 12 years
      Sorry for the delay in responding the ISP was down here for a couple of days.I'm sure the proxy settings are global. TOR is not installed on the guest OS and there are no proxy settings configured on the browsers. I used a tutorial from How-to-Forge to route all virtualbox traffic through TOR, now I'm just looking for a way to check that is doing that from the command line.