GitHub CI: update list of container images
[tinc] / QUICKSTART.md
1 # Creating a new VPN
2
3 If you are just starting to create a VPN, first consider what IP addresses you
4 want to use on the VPN. There are several blocks of IP addresses reserved for
5 [private networks](https://en.wikipedia.org/wiki/Private_network):
6
7 - 192.168.0.0/16
8 - 172.16.0.0/12
9 - 10.0.0.0/8
10 - fd00::/8
11
12 Make sure the [IP range](https://en.wikipedia.org/wiki/CIDR) you are choosing is
13 large enough for all the nodes you want to add to the VPN, and also consider
14 that some of these private address ranges might also be used on local area
15 networks, so check in advance that you won't conflict with any range that is
16 already in use by any of the participants. When in doubt, just pick one and try
17 it out. For this quickstart guide, we will use 172.16.0.0/16 as the range of the
18 VPN.
19
20 Also think of a name for your whole VPN. This will be used as the "netname"
21 parameter for tinc, and on Linux this will then also automatically be used as
22 the name for the virtual network interface. We will use "myvpn" as the name in
23 the examples below.
24
25 # Create your first node
26
27 Think of a name for your first node. We will call it "first" in the examples
28 below. The name must be unique for each node in the same VPN, and may only
29 contain letters, numbers and underscores. Apart from that you can choose
30 whatever you want. Now we can create the first node:
31
32 ```sh
33 sudo tinc -n myvpn init first
34 ```
35
36 This creates the initial configuration for the node, but has not started tinc
37 yet. Before we do that, two things have to be done first. We have to tell tinc
38 which part of the IP range of the VPN belongs to *this* particular node. We will
39 use 172.168.1.0/24 for this example. We then have to give this command:
40
41 ```sh
42 sudo tinc -n myvpn add Subnet 172.168.1.0/24
43 ```
44
45 However, tinc itself will not actually configure the virtual network interface
46 for you. You have to create a script named `tinc-up` that does this. To do this,
47 run the command:
48
49 ```sh
50 sudo tinc -n myvpn edit tinc-up
51 ```
52
53 This should start an editor. When you ran the `init` command, a dummy script was
54 already created. Edit it to make sure it looks like this:
55
56 ```sh
57 #!/bin/sh
58 ifconfig $INTERFACE 172.168.1.1/16
59 ```
60
61 Note that the literal text `$INTERFACE` should be in the script, tinc will make
62 sure that environment variable is set correctly when the script is run. The
63 address should be that of the node itself, but the netmask or prefix length (the
64 `/16` in this case) you provide must be that of the *whole* VPN. This tells the
65 kernel that everything for the VPN's IP range should go to tinc's virtual
66 network interface, from then on tinc will handle it and route it to the right
67 node based on the `Subnet`s that you configured.
68
69 To start tinc run:
70
71 ```sh
72 sudo tinc -n myvpn start
73 ```
74
75 This will start running tinc in the background. You can also run it in the
76 foreground with debugging enabled using this command:
77
78 ```sh
79 sudo tinc -n myvpn start -d5 -D
80 ```
81
82 This might be helpful in the beginning to debug any issues you have setting up
83 the VPN.
84
85 # Create your second node
86
87 There are two ways to add new nodes to the VPN.
88
89 ## Using import/export of host config files
90
91 One way to do it is to create a second node just like you created the first
92 node. Just make sure it has a different name (let's call it "second"), and that
93 it gets a different IP range for itself (let's use 172.168.2.0/24). So on the
94 second node run:
95
96 ```sh
97 sudo tinc -n myvpn init second
98 sudo tinc -n myvpn add Subnet 172.168.2.0/24
99 sudo tinc -n myvpn edit tinc-up
100 ```
101
102 And make sure the second node's tinc up contains:
103
104 ```sh
105 #!/bin/sh
106 ifconfig $INTERFACE 172.168.2.1/16
107 ```
108
109 And `start` the second node. After you have done that, you have to make sure
110 that the two nodes can find each other. To do this, at least one node should
111 have a public IP address. Let's assume the first node has public IP address
112 93.184.216.34. You would then give this command on the first node:
113
114 ```sh
115 sudo tinc -n myvpn add Address 93.184.216.34
116 ```
117
118 Note that if you have a public domain name, you can also use that domain name
119 instead of a numeric IP address. Now run the following on the first node:
120
121 ```sh
122 sudo tinc -n myvpn export
123 ```
124
125 This outputs a small amount of text that contains the node's public keys and the
126 public address. On the second node, run this:
127
128 ```sh
129 sudo tinc -n myvpn import
130 ```
131
132 And copy&paste the output from the first node, then press ctrl-D on a new line.
133 If done correctly it should tell you that it has imported the host configuration
134 file. Now you have to do the same but in the other direction: use the `export`
135 command on the second node, and then use `import` on the first node. Now that
136 both nodes know each other, they should be able to connect. This should happen
137 automatically after a while.
138
139 Note that instead of copy&pasting the text manually, you could also redirect it
140 to a text file, send it via email, pipe it through an SSH connection, or use any
141 other way to exchange the host config files. For more information, see the
142 [manual](https://www.tinc-vpn.org/documentation-1.1/How-to-configure.html).
143
144 ## Using invitations
145
146 Another way to add more nodes is to have an existing node generate an
147 [invitation](https://www.tinc-vpn.org/documentation-1.1/Invitations.html) for
148 another node. A prerequisite is that the node generating the invitation should
149 have a public IP address to the invitee will be able to connect to it. Again,
150 let's assume the first node has public IP address 93.184.216.34:
151
152 ```sh
153 sudo tinc -n myvpn add Address 93.184.216.34
154 ```
155
156 Then on the first node, generate in invitation for the second node:
157
158 ```sh
159 sudo tinc -n myvpn invite second
160 ```
161
162 This should generate one line of text that looks like an URL, like for example:
163
164 ```
165 93.184.216.34:655/R4BU9VMzdY4S_EIuAhW1-B0XV50HqooyEv6EUfl4k6Z9_zrq
166 ```
167
168 On the second node, don't using `init` to create the initial configuration.
169 Instead, run the following command:
170
171 ```sh
172 sudo tinc -n myvpn join 93.184.216.34:655/R4BU9VMzdY4S_EIuAhW1-B0XV50HqooyEv6EUfl4k6Z9_zrq
173 ```
174
175 It will then initialize itself and make a connection to the first node and
176 exchange configuration files automatically. You still have to add the `Subnet`
177 and edit `tinc-up` afterwards on the second node (as described in the section
178 above), and use the `start` command to start tinc.
179
180 Invitations are easier to use, and relatively secure. Once used, the invitation
181 is no longer valid. However, be aware that anyone holding an unused invitation
182 can use it to join a VPN, so make sure you do not make invitation URLs public.
183
184 # Checking that things are working
185
186 After you have set up two nodes, you should be able to ping `172.16.1.1`. If it
187 doesn't work, there can be multiple reasons. Make sure you don't have any
188 firewall rules blocking tinc's port, and that at least one node has a public IP
189 address that is accepting incoming connections. You can further investigate by
190 asking tinc the status of a given node. So for example, on the first node, you
191 can run:
192
193 ```sh
194 sudo tinc -n myvpn info second
195 ```
196
197 You can also dump a list of connections:
198
199 ```sh
200 sudo tinc -n myvpn dump connections
201 ```
202
203 Or `dump nodes` to get a list of known nodes, `dump subnets` to see all subnets.
204 If you ran tinc in the background, you can get still get log output like so:
205
206 ```sh
207 sudo tinc -n myvpn log 5
208 ```
209
210 Finally, if the problem is not with tinc, using `tcpdump` to look at the traffic
211 on your real and virtual interfaces might help determine what the problem is.