2019-02-08 16:06:34 +01:00
# Setting up TOR with c-lightning
2018-05-10 01:18:19 +02:00
2019-03-23 21:23:10 +01:00
To use any Tor features with c-lightning you must have Tor installed and running.
2018-05-10 01:18:19 +02:00
2019-02-08 16:06:34 +01:00
```bash
2018-07-31 19:31:37 +02:00
sudo apt install tor
```
2019-12-13 21:47:28 +01:00
then `/etc/init.d/tor start` or `sudo systemctl start tor` depending
2018-07-31 19:31:37 +02:00
on your system configuration.
2018-05-10 01:18:19 +02:00
2019-03-23 21:23:10 +01:00
Most default setting should be sufficient.
2018-05-10 01:18:19 +02:00
2019-03-23 21:23:10 +01:00
To keep a safe configuration for minimal harassment (See [Tor FAQ])
just check that this line is present in the Tor config file `/etc/tor/torrc` :
2018-05-10 01:18:19 +02:00
2018-07-31 19:31:37 +02:00
`ExitPolicy reject *:* # no exits allowed`
2018-05-10 01:18:19 +02:00
2019-03-23 21:23:10 +01:00
This does not affect c-lightning connect, listen, etc..
It will only prevent your node from becoming a Tor exit node.
2018-07-31 19:31:37 +02:00
Only enable this if you are sure about the implications.
2018-05-10 01:18:19 +02:00
2019-03-23 21:23:10 +01:00
If you don't want to create .onion addresses this should be enough.
2018-05-10 01:18:19 +02:00
2019-03-23 21:23:10 +01:00
There are several ways by which a c-lightning node can accept or make connections over Tor.
2018-05-10 01:18:19 +02:00
2018-08-01 17:32:34 +02:00
The node can be reached over Tor by connecting to its .onion address.
2018-05-10 01:18:19 +02:00
2019-03-23 21:23:10 +01:00
To provide the node with a .onion address you can:
2018-05-10 01:18:19 +02:00
2018-08-01 17:32:34 +02:00
* create a **non-persistent** address with an auto service or
2018-05-10 01:18:19 +02:00
2019-03-23 21:23:10 +01:00
* create a **persistent** address with a hidden service.
2018-05-10 01:18:19 +02:00
2018-08-01 17:32:34 +02:00
#### Creation of an auto service for non-persistent .onion addresses
2018-05-10 01:18:19 +02:00
2019-03-23 21:23:10 +01:00
To provide the node a non-persistent .onion address it
2019-12-13 21:47:28 +01:00
is necessary to access the Tor auto service. These types of addresses change
2018-08-01 17:32:34 +02:00
each time the Tor service is restarted.
2018-07-31 19:31:37 +02:00
2019-12-13 21:47:28 +01:00
*NOTE:If the node is required to be reachable only by **persistent** .onion addresses, this
part can be skipped and it is necessary to set up a hidden service with the steps
2018-07-31 19:31:37 +02:00
outlined in the next section.*
2019-03-23 21:23:10 +01:00
To create and use the auto service follow these steps:
2018-05-10 01:18:19 +02:00
2018-08-01 17:32:34 +02:00
Edit the Tor config file `/etc/tor/torrc`
2018-05-10 01:18:19 +02:00
2018-07-31 19:31:37 +02:00
You can configure the service authenticated by cookie or by password:
2018-05-10 01:18:19 +02:00
2019-12-13 21:47:28 +01:00
##### Service authenticated by cookie
2019-03-23 21:23:10 +01:00
Add the following lines in the `/etc/tor/torrc` file:
2018-07-31 19:31:37 +02:00
````
2018-05-10 01:18:19 +02:00
ControlPort 9051
CookieAuthentication 1
CookieAuthFileGroupReadable 1
2018-07-31 19:31:37 +02:00
````
2018-05-10 01:18:19 +02:00
2019-12-13 21:47:28 +01:00
##### Service authenticated by password
2018-05-10 01:18:19 +02:00
2019-12-13 21:47:28 +01:00
Alternatively, you can set the authentication
2019-03-23 21:23:10 +01:00
to the service with a password by following these steps:
2018-05-10 01:18:19 +02:00
2019-12-13 21:47:28 +01:00
1. Create a hash of your password with
2018-08-02 19:38:02 +02:00
```
tor --hash-password yourpassword
```
2019-03-23 21:23:10 +01:00
2018-07-31 19:31:37 +02:00
This returns a line like
2018-05-10 01:18:19 +02:00
2018-07-31 19:31:37 +02:00
`16:533E3963988E038560A8C4EE6BBEE8DB106B38F9C8A7F81FE38D2A3B1F`
2018-05-10 01:18:19 +02:00
2018-07-31 19:31:37 +02:00
2. put these lines in the `/etc/tor/torrc` file:
```
ControlPort 9051
2018-05-10 01:18:19 +02:00
HashedControlPassword 16:533E3963988E038560A8C4EE6BBEE8DB106B38F9C8A7F81FE38D2A3B1F
2018-07-31 19:31:37 +02:00
````
2018-05-10 01:18:19 +02:00
2019-03-23 21:23:10 +01:00
Save the file and restart the Tor service. In linux:
2018-05-10 01:18:19 +02:00
2019-12-13 21:47:28 +01:00
`/etc/init.d/tor restart` or `sudo systemctl start tor` depending
2019-03-23 21:23:10 +01:00
on the configuration of your system.
2018-05-10 01:18:19 +02:00
2019-12-13 21:47:28 +01:00
The auto service is used by adding `--addr=autotor:127.0.0.1:9051` if you
want the address to be public or `--bind-addr=autotor:127.0.0.1:9051` if you
2018-08-02 19:38:02 +02:00
don't want to publish it.
2018-05-10 01:18:19 +02:00
2019-12-13 21:47:28 +01:00
In the case where the auto service is authenticated through a password, it will
2018-07-31 19:31:37 +02:00
be necessary to add the option `--tor-service-password=yourpassword` (not the hash).
2018-05-10 01:18:19 +02:00
2019-12-13 21:47:28 +01:00
The created non-persistent .onion address wil be shown by the `lightning-cli getinfo` command.
The others nodes will be able to `connect` to this .onion address through the
2018-07-31 19:31:37 +02:00
9735 port.
2018-05-10 01:18:19 +02:00
2019-03-23 21:23:10 +01:00
#### Creation of a hidden service for a persistent .onion address
2018-05-10 01:18:19 +02:00
2019-12-13 21:47:28 +01:00
To have a persistent .onion address other nodes can connect to, it
2018-08-01 17:32:34 +02:00
is necessary to set up a [Tor Hidden Service].
2018-05-10 01:18:19 +02:00
2019-12-13 21:47:28 +01:00
*NOTE: In the case where only non-persistent addresses are required,
2018-07-31 19:31:37 +02:00
you don't have to create the hidden service and you can skip this part.*
2018-05-10 01:18:19 +02:00
2019-03-23 21:23:10 +01:00
Add these lines in the `/etc/tor/torrc` file:
2018-05-10 01:18:19 +02:00
2018-07-31 19:31:37 +02:00
````
HiddenServiceDir /var/lib/tor/lightningd-service_v2/
2018-05-10 12:05:32 +02:00
HiddenServicePort 1234 127.0.0.1:9735
2018-07-31 19:31:37 +02:00
````
2018-08-01 17:32:34 +02:00
2019-03-23 21:23:10 +01:00
If you want to create a version 3 address, you must also add `HiddenServiceVersion 3` so
2018-07-31 19:31:37 +02:00
the whole section will be:
2018-08-01 17:32:34 +02:00
2018-07-31 19:31:37 +02:00
````
HiddenServiceDir /var/lib/tor/lightningd-service_v3/
2018-05-10 01:18:19 +02:00
HiddenServiceVersion 3
2018-05-10 12:05:32 +02:00
HiddenServicePort 1234 127.0.0.1:9735
2018-07-31 19:31:37 +02:00
````
2018-05-10 01:18:19 +02:00
2018-07-31 19:31:37 +02:00
The hidden lightning service will be reachable at port 1234 (global port)
2019-12-13 21:47:28 +01:00
of the .onion address, which will be created at the restart of the
2018-08-01 17:32:34 +02:00
Tor service. Both types of addresses can coexist on the same node.
2018-05-10 01:18:19 +02:00
2018-08-01 17:32:34 +02:00
Save the file and restart the Tor service. In linux:
2018-05-10 01:18:19 +02:00
2019-12-13 21:47:28 +01:00
`/etc/init.d/tor restart` or `sudo systemctl start tor` depending
2018-07-31 19:31:37 +02:00
on the configuration of your system.
You will find the newly created address with:
2018-08-02 19:38:02 +02:00
```
2019-12-13 21:47:28 +01:00
sudo cat /var/lib/tor/lightningd-service_v2/hostname
2018-08-02 19:38:02 +02:00
```
or
```
2019-12-13 21:47:28 +01:00
sudo cat /var/lib/tor/lightningd-service_v3/hostname
2018-08-02 19:38:02 +02:00
```
2019-12-13 21:47:28 +01:00
in the
2018-08-01 17:32:34 +02:00
case of a version 3 Tor address.
2018-07-31 19:31:37 +02:00
2019-03-23 21:23:10 +01:00
Now you are able to create:
2018-07-31 19:31:37 +02:00
2018-08-01 17:32:34 +02:00
* Non-persistent version 2 .onion address via auto service (temp-v2)
2018-07-31 19:31:37 +02:00
2019-12-13 21:47:28 +01:00
* Persistent version 2 and version 3 .onion addresseses (v2 and v3).
2018-07-31 19:31:37 +02:00
Let's see how to use them.
### What do we support
2018-08-01 17:32:34 +02:00
| Case # | IP Number | Tor address |Incoming / Outgoing Tor |
| ------- | ------------- | ------------------------- |-------------------------
| 1 | Public | NO | Outgoing |
| 2 | Public | v2 [1] | Incoming [4] |
| 3 | Public | temp-v2 [2] | Incoming |
| 4 | Not Announced | v2 | Incoming |
| 5 | Not Announced | temp-v2 | Incoming |
| 6 | Public | v3 [3] + temp-v2 | Incoming |
| 7 | Not Announced | v3 + v2 + temp-v2 | Incoming |
| 8 | Public | NO | Outcoing socks5 . |
2018-07-31 19:31:37 +02:00
NOTE:
2019-12-13 21:47:28 +01:00
1. v2: The Version 2 onion address is persistent across Tor service restarts.
2018-08-01 21:01:30 +02:00
It is created when you create the [Tor Hidden Service ](#Creation-of-an-hidden-service-for-a-persistent-onion-address ).
2018-07-31 19:31:37 +02:00
2019-12-13 21:47:28 +01:00
2. temp-v2: The Version 2 onion address changes at each restart of the Tor service.
2018-08-01 21:01:30 +02:00
A non-persistent .onion address is generated by accessing an [auto service ](#creation-of-an-auto-service-for-non-persistent-onion-addresses ).
2018-07-31 19:31:37 +02:00
2018-08-01 17:32:34 +02:00
3. All the v3 addresses referes to [.onion addresses version 3].
2018-07-31 19:31:37 +02:00
2019-12-13 21:47:28 +01:00
4. In all the "Incoming" use case, the node can also make "Outgoing" Tor
connections (connect to a .onion address) by adding the
2019-07-15 01:36:18 +02:00
`--proxy=127.0.0.1:9050` option.
2018-07-31 19:31:37 +02:00
2019-12-13 21:47:28 +01:00
#### Case 1 c-lightning has a public IP address and no Tor hidden service address, but can connect to an onion address via a Tor socks 5 proxy.
2018-07-31 19:31:37 +02:00
2019-12-13 21:47:28 +01:00
Without a .onion address, the node won't be reachable through Tor by other
nodes but it will always be able to `connect` to a Tor enabled node
(outbound connections), passing the `connect` request through the Tor
service socks5 proxy. When the Tor service starts it creates a socks5
proxy which is by default at the address 127.0.0.1:9050.
2018-07-31 19:31:37 +02:00
2019-12-13 21:47:28 +01:00
If the node is started with the option `--proxy=127.0.0.1:9050` the node
will be always able to connect to nodes with .onion address through the socks5
proxy.
2018-08-01 17:32:34 +02:00
2019-12-13 21:47:28 +01:00
**You can always add this option, also in the other use cases, to add outgoing
2018-08-01 17:32:34 +02:00
Tor capabilities.**
2019-12-13 21:47:28 +01:00
If you want to `connect` to nodes ONLY via the Tor proxy, you have to add the
2019-07-15 01:36:18 +02:00
`--always-use-proxy=true` option.
2018-07-31 19:31:37 +02:00
You can announce your public IP address through the usual method:
2018-08-02 19:38:02 +02:00
```
--bind-addr=internalIPAddress:port --announce-addr=externalIpAddress
```
if the node is into an internal network
```
--addr=externalIpAddress
```
if the node is not inside an internal network.
2018-07-31 19:31:37 +02:00
2019-12-13 21:47:28 +01:00
TIP: If you are unsure which of the two is suitable for you, find your internal
2018-07-31 19:31:37 +02:00
and external address and see if they match.
In linux:
Discover your external IP address with: `curl ipinfo.io/ip`
2018-08-01 17:32:34 +02:00
and your internal IP Address with: `ip route get 1 | awk '{print $NF;exit}'`
2018-07-31 19:31:37 +02:00
2019-12-13 21:47:28 +01:00
If they match you can use the `--addr` command line option.
2018-07-31 19:31:37 +02:00
2018-08-01 17:32:34 +02:00
#### Case #2 c-lightning has a public IP address and a fixed Tor hidden service address that is persistent, so that external users can connect to this node.
2018-07-31 19:31:37 +02:00
To have your external IP address and your .onion address announced, you use the
2018-08-02 19:38:02 +02:00
```
2019-12-13 21:47:28 +01:00
--bind-addr=yourInternalIPAddress:port --announce-addr=yourexternalIPAddress:port --announce-addr=your.onionAddress:port`
2018-08-02 19:38:02 +02:00
```
option.
2018-07-31 19:31:37 +02:00
2019-12-13 21:47:28 +01:00
If you are not inside an internal network you can use
2018-08-02 19:38:02 +02:00
```
--addr=yourIPAddress:port --announce-addr=your.onionAddress:port
```
2019-12-13 21:47:28 +01:00
your.onionAddress is the one created with the Tor hidden service ([see above](#creation-of-an-hidden-service-for-a-persistent-onion-address)).
The port is the one indicated as the hidden service port. If the hidden service creation
line is `HiddenServicePort 1234 127.0.0.1:9735` the .onion address will be reachable at
2018-07-31 19:31:37 +02:00
the 1234 port (the global port).
It will be possible to connect to this node with:
2018-08-02 19:38:02 +02:00
```
2019-12-13 21:47:28 +01:00
lightning-cli connect nodeID .onionAddress globalPort
2018-08-02 19:38:02 +02:00
```
through Tor where .onion address is in the form `xxxxxxxxxxxxxxxxxxxxxxxxxx.onion` , Or
```
lightning-cli connect nodeID yourexternalIPAddress Port
```
through Clearnet.
2018-07-31 19:31:37 +02:00
2018-08-01 17:32:34 +02:00
#### Case #3 c-lightning has a public IP address and a non-persisten Tor service address
2018-07-31 19:31:37 +02:00
2018-08-01 17:32:34 +02:00
In this case other nodes can connect to you via Clearnet or Tor.
2018-07-31 19:31:37 +02:00
To announce your IP address to the network, you add:
2018-08-02 19:38:02 +02:00
```
--bind-addr=internalAddress:port --announce-addr=yourExternalIPAddress
```
2018-07-31 19:31:37 +02:00
or `--addr=yourExternalIPAddress` if you are NOT on an internal network.
2019-12-13 21:47:28 +01:00
To get your non-persistent Tor address, add
`--addr=autotor:127.0.0.1:9051` if you want to announce it or
2018-08-01 17:32:34 +02:00
`--bind-addr=autotor:127.0.0.1:9051` if you don't want to announce it.
2018-07-31 19:31:37 +02:00
2019-12-13 21:47:28 +01:00
If the auto service is protected by password ([see above](#service-authenticated-by-password)) it is necessary to
specify it with the option `--tor-service-password=yourpassword` (not the hash).
2018-07-31 19:31:37 +02:00
2019-12-13 21:47:28 +01:00
You will obtain the generated non persisten .onion address by reading the results of the
`lightning-cli getinfo` command. Other nodes will be able to connect to the
2018-07-31 19:31:37 +02:00
.onion address through the 9735 port.
2018-08-01 17:32:34 +02:00
#### Case #4 c-lightning has no public IP address, but has a fixed Tor hidden service address that is persistent
2018-07-31 19:31:37 +02:00
2019-12-13 21:47:28 +01:00
Other nodes can connect to the announced .onion address created with the
2018-08-01 21:01:30 +02:00
hidden service ([see above](#creation-of-an-hidden-service-for-a-persistent-onion-address)).
2018-07-31 19:31:37 +02:00
In this case In the `lightningd` command line you will specify:
2018-08-02 19:38:02 +02:00
```
--bind-addr=yourInternalIPAddress:port --announce-addr=your.onionAddress:port
```
2018-07-31 19:31:37 +02:00
or `--addr=your.onionAddress:port` if you are NOT on an internal network.
2018-08-01 17:32:34 +02:00
#### Case #5 c-lightning has no public IP address, and has no fixed Tor hidden service address
2018-07-31 19:31:37 +02:00
In this case it is difficult to track the node.
You specify just:
2018-08-02 19:38:02 +02:00
```
2019-03-29 23:19:32 +01:00
--bind-addr=yourInternalIPAddress:port --addr=autotor:127.0.0.1:9051
2018-08-02 19:38:02 +02:00
```
2018-07-31 19:31:37 +02:00
In the `lightningd` command line.
Other nodes will not be able to `connect` to you unless you communicate them how to reach you.
2019-12-13 21:47:28 +01:00
You will find your .onion address with the command `lightning-cli getinfo` and the other nodes will
2018-07-31 19:31:37 +02:00
be able to connect to it through the 9735 port.
2018-08-01 17:32:34 +02:00
#### Case #6 c-lightning has a public IP address and a fixed Tor V3 service address and a Tor V2 service address
2018-07-31 19:31:37 +02:00
2019-12-13 21:47:28 +01:00
You will be reachable via Clearnet, via Tor to the .onion V3 address and the
.onion V2 address if this last is communicated to the node that wants to
2018-08-01 17:32:34 +02:00
connect with our node.
2018-07-31 19:31:37 +02:00
2019-12-13 21:47:28 +01:00
to make your external IP address public you add:
2018-08-02 19:38:02 +02:00
```
2019-12-13 21:47:28 +01:00
--bind-addr=yourInternalAddress:port --announce-addr=yourexternalIPAddress:port`.
2018-08-02 19:38:02 +02:00
```
2018-08-01 17:32:34 +02:00
If the node is not on an internal network the option will be:
`--addr=yourexternalIPAddress:port` .
2018-07-31 19:31:37 +02:00
2019-12-13 21:47:28 +01:00
Once the .onion addresses have been created with the procedures [oulined above ](#creation-of-an-hidden-service-for-a-persistent-onion-address ),
2018-08-01 17:32:34 +02:00
the node is already reachable at the .onion address.
2018-07-31 19:31:37 +02:00
2019-12-13 21:47:28 +01:00
To make your external .onion addresses public you add:
2018-08-02 19:38:02 +02:00
```
2019-12-13 21:47:28 +01:00
--announce-addr=.onionAddressV2:port --announce-addr=.onionAddressV3:port
2018-08-02 19:38:02 +02:00
```
to the options to publish your IP number.
2018-07-31 19:31:37 +02:00
2018-08-02 19:38:02 +02:00
#### Case #7 c-lightning has no public IP address, a fixed Tor V3 service address, a fixed Tor V2 service address and also a 3rd non persisten V2 address
2018-07-31 19:31:37 +02:00
2018-08-01 17:32:34 +02:00
External users can connect to this node by Tor V2 and V3 and a random V2 until next tor release, then also (V3 randomly).
2018-07-31 19:31:37 +02:00
2018-08-01 21:01:30 +02:00
The Persistent addresses can be created with the steps [outlined above ](#creation-of-an-hidden-service-for-a-persistent-onion-address ).
2018-05-10 01:18:19 +02:00
2019-12-13 21:47:28 +01:00
To create your non-persistent Tor address, add
`--addr=autotor:127.0.0.1:9051` if you want to announce it or
2018-08-01 17:32:34 +02:00
`--bind-addr=autotor:127.0.0.1:9051` if you don't want to announce it.
2018-05-10 01:18:19 +02:00
2019-12-13 21:47:28 +01:00
Also you must specify `--tor-service-password=yourpassword` (not the hash) to access the
2018-08-01 17:32:34 +02:00
Tor service at 9051 If you have protected them with the password (no additional options if
2018-08-01 21:01:30 +02:00
they are protected with a cookie file. [See above ](#creation-of-an-auto-service-for-non-persistent-onion-addresses )).
2018-05-10 12:05:32 +02:00
2019-12-13 21:47:28 +01:00
To make your external .onion address (V2 and V3) public you add:
2018-08-02 19:38:02 +02:00
```
--bind-addr=yourInternalIPAddress:port --announce-addr=your.onionAddressV2:port --announce-addr=your.onionAddressV3:port
```
2018-08-01 17:32:34 +02:00
#### Case #8 c-lightning has a public IP address and no Tor addresses
2018-05-10 12:05:32 +02:00
2019-12-13 21:47:28 +01:00
The external address is communicated by the
2018-08-02 19:38:02 +02:00
```
--bind-addr=internalIPAddress:port --announce-addr=yourexternalIPAddress:port`
```
2018-08-01 17:32:34 +02:00
or `--addr=yourexternalIPAddress:port` if the node is not inside an internal network.
2018-05-10 12:05:32 +02:00
2019-12-13 21:47:28 +01:00
The node can connect to any V4/6 ip address via a IPV4/6 socks 5 proxy by specifing
2018-08-02 19:38:02 +02:00
```
2019-07-15 01:36:18 +02:00
--proxy=127.0.0.1:9050 --always-use-proxy=true
2018-08-02 19:38:02 +02:00
```
2018-05-10 01:18:19 +02:00
2018-08-02 19:38:02 +02:00
## References
2018-08-01 17:32:34 +02:00
2018-08-02 19:38:02 +02:00
[The Tor project ](https://www.torproject.org/ )
2018-05-10 01:18:19 +02:00
2018-07-31 19:31:37 +02:00
[tor FAQ]: https://www.torproject.org/docs/faq.html.en#WhatIsTor
2018-05-10 01:18:19 +02:00
2018-08-01 17:32:34 +02:00
[Tor Hidden Service]: https://www.torproject.org/docs/onion-services.html.en
2018-05-10 01:18:19 +02:00
2019-12-13 21:47:28 +01:00
[.onion addresses version 3]: https://blog.torproject.org/we-want-you-test-next-gen-onion-services