I have the Tor service, and I want to use the terminal to change the IP address which Tor gives me. In other words: How do I request a new IP address from Tor on the command line?
-
5an even better way to say it is how to "change identity" from a terminal– mchidJul 19, 2014 at 20:04
-
I added another command that I found for when running the tor daemon on Ubuntu in the background.– mchidJul 19, 2014 at 20:29
-
stackoverflow.com/questions/1969958/…– Ciro Santilli OurBigBook.comNov 15, 2015 at 23:05
5 Answers
For tor daemon running on Ubuntu, first try this:
killall -HUP tor
If that does not work, enable the control port in your torrc file.
Then, set a password for the control port with tor --hash-password password
Open a telnet connection to the control port and issue the NEWNYM command:
printf 'AUTHENTICATE "password"\r\nSIGNAL NEWNYM\r\n' | nc 127.0.0.1 9051
sources:
-
1For the newbs out there, you must first set the hashed password on your torrc like this: askubuntu.com/a/989108/52975 Dec 24, 2017 at 9:06
You can simply type or insert in your bash script:
service tor reload
-
-
To me this is actually a better answer then the one @mchid gave. The reload command will trigger the running tor executable to reload its configuration and setup a new circuit (and thus get new IP). The other answer will kill the running executable and restart it. This might take longer and cause other services depening on tor's proxy to be there to fail.– AlexSep 16, 2016 at 16:48
-
I don't know why others suggested such a complicated solution while this simple line can solve the problem Jun 17, 2017 at 10:31
-
1
-
@Alex If you just use the second method and issue the NEWNYM command, it will stay running and you will get a new IP because it will switch to clean circuits.– mchidJul 1, 2020 at 7:57
Method 1: HUP
Mentioned at Change IP address which is given by Tor using the terminal but here go a few more details:
sudo killall -HUP tor
Then check that your IP has changed with:
curl --socks5 127.0.0.1:9050 http://checkip.amazonaws.com/
Tested in Ubuntu 17.10 with sudo apt-get install tor
version 1.6.0-5.
sudo
is needed since the process is started by root by default.
What an HUP signal does exactly to the Tor daemon is documented at: https://gitweb.torproject.org/torspec.git/tree/control-spec.txt?id=03aaace9bd9459b0d4bf22a75012acf39d07bcec#n394 and is equivalent to sending some command through the command port.
Browser Bundle 5.0.5 is not affected by this, only daemon ports like the default 9050, which is not used by the TBB. For that use case see: https://tor.stackexchange.com/questions/1071/how-can-a-new-circuit-happen-without-closing-all-tabs
If you are deploying an army of Tor IPs as mentioned here you can selectively send:
kill -HUP $PID
Method 2: control port
Mentioned by kat:
(echo authenticate '""'; echo signal newnym; echo quit) | nc localhost 9051
but for that to work on Ubuntu 17.10 you must first:
enable the control port by uncommenting:
ControlPort 9051
from
/etc/tor/torrc
Set the empty password, otherwise it gives
515 Authentication failed: Wrong length on authentication cookie.
. First run:tor --hash-password ''
This outputs something like:
16:D14CC89AD7848B8C60093105E8284A2D3AB2CF3C20D95FECA0848CFAD2
Now on
/etc/tor/torrc
update the line:HashedControlPassword 16:D14CC89AD7848B8C60093105E8284A2D3AB2CF3C20D95FECA0848CFAD2
Restart Tor:
sudo service tor restart
Bonus: how to check that your IP changed
curl --socks5 127.0.0.1:9050 http://checkip.amazonaws.com/
See also:
- https://tor.stackexchange.com/questions/100/can-tor-be-used-with-applications-other-than-web-browsers
- Command for determining my public IP?
Related threads
-
Such complicated solutions for such a simple function (
get new circuit
). I don't trust tor at all anymore. I think it is full of bugs and glitches to make us expose ourselves Dec 17, 2019 at 19:18
You can set up a control port and use the python script
from stem import Signal
from stem.control import Controller
with Controller.from_port(port = 9051) as controller:
controller.authenticate()
controller.signal(Signal.NEWNYM)
-
1
A one-liner that makes tor use a different ip address:
systemctl show -p MainPID tor | cut -d= -f2 | xargs sudo kill -HUP