title: How to connect to Tor control port (9051) from a remote host?
body: <p>I'm trying to connect to control port (9051) of tor from a remote machine using stem python library.</p>
  
  <p><em>dum.py</em></p>
  
  <pre><code>from stem import Signal
  from stem.control import Controller
  
  
  def set_new_ip():
      """Change IP using TOR"""
      with Controller.from_port(address = '10.130.8.169', port=9051) as controller:
          controller.authenticate(password='password')
              controller.signal(Signal.NEWNYM)
  set_new_ip()
  </code></pre>
  
  <p>I'm getting the following error</p>
  
  <pre><code>Traceback (most recent call last):
    File "/home/jkl/anaconda3/lib/python3.5/site-packages/stem/socket.py", line 398, in _make_socket
      control_socket.connect((self._control_addr, self._control_port))
  ConnectionRefusedError: [Errno 111] Connection refused
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File "dum.py", line 28, in &lt;module&gt;
      set_new_ip();
    File "dum.py", line 7, in set_new_ip
      with Controller.from_port(address = '10.130.4.162', port=9051) as controller:
    File "/home/jkl/anaconda3/lib/python3.5/site-packages/stem/control.py", line 998, in from_port
      control_port = stem.socket.ControlPort(address, port)
    File "/home/jkl/anaconda3/lib/python3.5/site-packages/stem/socket.py", line 372, in __init__
      self.connect()
    File "/home/jkl/anaconda3/lib/python3.5/site-packages/stem/socket.py", line 243, in connect
      self._socket = self._make_socket()
    File "/home/jkl/anaconda3/lib/python3.5/site-packages/stem/socket.py", line 401, in _make_socket
      raise stem.SocketError(exc)
  stem.SocketError: [Errno 111] Connection refused
  </code></pre>
  
  <p>Then I went through /etc/tor/torrc config file. 
  It says</p>
  
  <blockquote>
    <p>The port on which Tor will listen for <strong>local connections</strong> from Tor
    controller applications, as documented in control-spec.txt.</p>
  </blockquote>
  
  <pre><code>   ControlPort 9051
      ## If you enable the controlport, be sure to enable one of these
      ## authentication methods, to prevent attackers from accessing it.
      HashedControlPassword 16:E5364A963AF943CB607CFDAE3A49767F2F8031328D220CDDD1AE30A471
      SocksListenAddress 0.0.0.0:9050
      CookieAuthentication 1
  </code></pre>
  
  <p>My question is , 
  How do I connect to control port of Tor from a remote host? <br>
  Is there is any work around or config parameter that I need to set?</p>
  
  <p><em>a possible duplicate of</em> <a href="https://stackoverflow.com/questions/35699833/stem-is-giving-the-unable-to-connect-to-port-9051-error">Stem is giving the &quot;Unable to connect to port 9051&quot; error</a> which has no answers</p>