12 Debian 10 mit Tinc und Bird.page 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. # Software
  2. - Debian 11 (bullseye), Debian 12 (bookworm) und auf dem Laptop Ubuntu 18.04, inzwischen 22.04
  3. - Tinc 1.0.36 oder tinc 1.1pre18
  4. - Bird 2.07
  5. ***** Bitte beachten, dass Bird2 installiert wird. Bei Installation von Bird1 erfolgt nur eine kryptische Fehlermeldung und Bird startet nicht.*****
  6. # Installation
  7. - Installation des Betriebssystems wird hier nicht beschrieben.
  8. - Hier werden die Schritte nach der Installation von Debian 11 (bullseye) zum Aufbau eines VPN mit Tinc und Bird beschrieben.
  9. - Für einige Befehle sind root Rechte erforderlich.
  10. - Tinc 1.0.36 und bird 2 können aus dem Debian Repository installiert werden mit
  11. sudo apt install tinc bird2
  12. - Tinc 1.1pre18 kann aus den Sourcen kompiliert werden:
  13. Dafür sind die Pakete der Entwicklungsumgebung für Debian erforderlich
  14. sudo apt install build-essential libncurses-dev libreadline-dev liblzo2-dev libssl-dev
  15. Dann die tinc sourcen runterladen und entpacken
  16. wget http://tinc-vpn.org/packages/tinc-1.1pre18.tar.gz
  17. tar zxvf tinc-1.1pre18.tar.gz
  18. In das von dem vorigen Befehl angelegte Verzeichnis wechseln:
  19. cd tinc-1.1pre18 und configure / make / make install aufrufen
  20. ./configure --prefix=/usr --sysconfdir=/etc --runstatedir=/run --localstatedir=/var --with-systemd
  21. Falls Fehler auftreten, fehlende Pakete (die xxx-dev Version) nachinstallieren, dann
  22. make
  23. sudo make install
  24. Damit alles richtig angelegt wird, insbesondere systemd, muss tinc 1.1pre18 mit den Parametern oben konfiguriert werden:
  25. # Dateien der APU
  26. /etc/network/interfaces
  27. # This file describes the network interfaces available on your system
  28. # and how to activate them. For more information, see interfaces(5).
  29. # Allgemein
  30. - Informationen auf dieser Seite sind teilweise von anderen Wiki-Seiten übernommen.
  31. Es werden für alle Interfaces statische IPV4 Adressen verwendet, auf dem Laptop ist auch DHCP aktiv.
  32. Die hier verwendeten Adressen sind dem Wiki [IP-Adressen](40 IP-Adressen ff@home) für berghofen entnommen.
  33. # Hardware
  34. - APU mit Debian 11 (Bullseye) ohne grafische Oberfläche
  35. - Laptop mit Ubuntu 22.04
  36. Berghofen, wie auch die anderen Standorte, besteht jeweils mindestens aus der APU und einem Laptop sowie einem Internetrouter (F!Box).
  37. An jedem Standort gibt es mehrere Tincverbindungen:
  38. - lan: zwischen APU und Laptop
  39. - wan: zwischen APU und den anderen Standorten
  40. - wan: zwischen Laptop und den anderen Standorten
  41. # Dateien der APU
  42. /etc/network/interfaces
  43. # This file describes the network interfaces available on your system
  44. # and how to activate them. For more information, see interfaces(5).
  45. source /etc/network/interfaces.d/*
  46. # The loopback network interface
  47. auto lo
  48. iface lo inet loopback
  49. up ip addr add 193.43.220.130/32 dev lo
  50. # The primary network interface
  51. allow-hotplug enp1s0
  52. iface enp1s0 inet static
  53. address 192.168.178.51/24
  54. #default gateway wird von bird erledigt
  55. # gateway 192.168.178.254
  56. broadcast 192.168.178.255
  57. # dns-* options are implemented by the resolvconf package, if installed
  58. dns-nameservers 192.168.178.254
  59. dns-search fritz.box
  60. up ip rule add from all iif enp1s0 lookup 1 prio 1000 || true
  61. up ip rule add from 192.168.178.0/24 lookup 1 prio 1010 || true
  62. allow-hotplug wan
  63. iface wan inet static
  64. address 193.43.220.162/27
  65. broadcast 193.43.220.191
  66. mtu 1504
  67. allow-hotplug lan
  68. iface lan inet static
  69. address 192.168.34.1/24
  70. broadcast 192.168.34.255
  71. mtu 1504
  72. #allow-hotplug wlp5s0 # wlan z.Zt. nicht verwendet
  73. #iface wlp5s0 inet dhcp
  74. Die Schnittstellen der Interfacesdatei sind:
  75. - lo Standardloopback
  76. - enp1s0 ethernet
  77. - wan virtuelle Tinc Schnittstelle
  78. - lan virtuelle Tinc Schnittstelle
  79. - wlp5s0 nicht verwendet, auskommentierte WLAN Schnittstelle
  80. ## Für die Datenweitergabe zwischen den Netzen ist der folgende Eintrag nötig.
  81. /etc/sysctl.conf
  82. # Uncomment the next line to enable packet forwarding for IPv4
  83. net.ipv4.ip_forward=1
  84. # Tinc Verzeichnistruktur Tinc APU und Laptop Einstellungen
  85. etc/tinc/
  86. |-- lan
  87. | |-- hosts
  88. | | |-- berghofen
  89. | | `-- berglap
  90. | |-- rsa_key.priv
  91. | |-- ed25519_key.priv ## nur bei tinc 1.1
  92. | `-- tinc.conf
  93. `-- wan
  94. |-- hosts
  95. | |-- berghofen
  96. | |-- berglap
  97. | |-- hoerde
  98. | `-- nordstadt
  99. |-- rsa_key.priv
  100. |-- ed25519_key.priv ## nur bei tinc 1.1
  101. `-- tinc.conf
  102. /etc/tinc/lan/tinc.conf der APU berghofen
  103. ## APU lan tinc.conf
  104. Name = berghofen
  105. Device = /dev/net/tun
  106. Mode = switch
  107. AddressFamily = ipv4
  108. BindToAddress = 192.168.178.51
  109. Port = 10001
  110. MaxTimeout = 30
  111. GraphDumpFile = /var/run/tinc.lan.dot
  112. ConnectTo = berglap
  113. /etc/tinc/wan/tinc.conf der APU berghofen
  114. ## APU wan tinc.conf
  115. Name = berghofen
  116. Device = /dev/net/tun
  117. Mode = switch
  118. AddressFamily = ipv4
  119. BindToaddress = 192.168.178.51
  120. Port = 661
  121. MaxTimeout = 30
  122. GraphDumpFile = /var/run/tinc.wan.dot
  123. ConnectTo = hoerde
  124. ConnectTo = nordstadt
  125. /etc/tinc/lan/tinc.conf des Laptop berglap
  126. ## Laptop lan tinc.conf
  127. Name = berglap
  128. Device = /dev/net/tun
  129. Mode = switch
  130. AddressFamily = ipv4
  131. BindToAddress = 192.168.178.52
  132. Port = 10001
  133. MaxTimeout = 30
  134. GraphDumpFile = /var/run/tinc.lan.dot
  135. ConnectTo = berghofen
  136. /etc/tinc/wan/tinc.conf des Laptop berglap
  137. ## Laptop wan tinc.conf
  138. Name = berglap
  139. Device = /dev/net/tun
  140. Mode = switch
  141. AddressFamily = ipv4
  142. BindToaddress = 192.168.178.52
  143. Port = 661
  144. MaxTimeout = 30
  145. GraphDumpFile = /var/run/tinc.wan.dot
  146. ConnectTo = hoerde
  147. ConnectTo = nordstadt
  148. Da auf jedem Rechner 2 Tincinstanzen an demselben Interface laufen, werden sie durch unterschiedliche Ports getrennt: WAN mit port 661, LAN mit Port 10001.
  149. Inhalt der hosts Dateien
  150. Die Public und private Keys werden von Tinc erzeugt:
  151. bei tinc 1.0.36:
  152. tincd -n wan -K 4096
  153. tincd -n lan -K 4096
  154. bei tinc 1.1:
  155. tinc -n wan generate-keys 4096
  156. tinc -n lan generate-keys 4096
  157. Die ED25519PublicKey Zeile wird nur bei tinc 1.1 erzeugt/verwendet.
  158. Für hosts, die per ConnectTo in der tinc.conf angesprochen werden, ist in der zugehörigen hosts Datei die IPadresse des hosts und der port erforderlich für die aktive Verbindungsaufnahme. Mit anderen Worten: wenn Gerät1 zu Gerät2 verbinden will, müssen im öffentlichen Schlüssel von Gerät2, der von Gerät2 auf Gerät1 kopiert wurde, die Adresse und der Port des Zielrechners, also von Gerät2 eingefügt werden.
  159. /etc/tinc/lan/hosts/berghofen auf APU und laptop
  160. Address = 192.168.178.51
  161. Port = 10001
  162. -----BEGIN RSA PUBLIC KEY-----
  163. Schlüsseldaten
  164. -----END RSA PUBLIC KEY-----
  165. Ed25519PublicKey = WmAmMY95+B/A9FDQz7ZiV6WQcG2qAUUclRP52dwXSdD
  166. /etc/tinc/lan/hosts/berglap auf APU und laptop
  167. Address = 192.168.178.52
  168. Port = 10001
  169. -----BEGIN RSA PUBLIC KEY-----
  170. Schlüsseldaten
  171. -----END RSA PUBLIC KEY-----
  172. Ed25519PublicKey = WCkEAe/gohI7JAGLiHPKdE+ayxYrG1wuTfQQijAROuD
  173. /etc/tinc/wan/hosts/berghofen auf APU
  174. -----BEGIN RSA PUBLIC KEY-----
  175. Schlüsseldaten
  176. -----END RSA PUBLIC KEY-----
  177. Ed25519PublicKey = Tkhp7t+MsmQKsWIkO5qimTKoWdkvRigKwctxtfOu2MF
  178. /etc/tinc/wan/hosts/hoerde auf APU und berglap
  179. Address = 130.180.53.22
  180. Port = 661
  181. -----BEGIN RSA PUBLIC KEY-----
  182. Schlüsseldaten
  183. -----END RSA PUBLIC KEY-----
  184. Ed25519PublicKey = MjaltxtfPP1SdHgNH/dUuHmbYDXFdZMEUUbl0Qi/YCA
  185. /etc/tinc/wan/hosts/nordstadt auf APU und berglap
  186. Address = 91.204.4.53
  187. Port = 661
  188. -----BEGIN RSA PUBLIC KEY-----
  189. Schlüsseldaten
  190. -----END RSA PUBLIC KEY-----
  191. Ed25519PublicKey = 4znU87BKnctOFb+/JQhIltGtYN3h3czOVInolRPWgvA
  192. /etc/tinc/wan/hosts/berglap auf berglap
  193. -----BEGIN RSA PUBLIC KEY-----
  194. Schlüsseldaten
  195. -----END RSA PUBLIC KEY-----
  196. Ed25519PublicKey = 4znU87BKnctOFb+/JQhIltGtYN3h3czOVInolRPWgvA
  197. Die Tinc Instanzen können auf APU und berglap gestartet werden mit:
  198. systemctl start tinc
  199. systemctl start tinc@lan
  200. systemctl start tinc@wan
  201. Beispielhaft tinc@lan abfragen:
  202. systemctl status tinc@lan
  203. tinc@lan.service - Tinc net lan
  204. Loaded: loaded (/lib/systemd/system/tinc@.service; enabled; vendor preset: enabled)
  205. Active: active (running) since Tue 2022-03-29 21:26:01 CEST; 1 months 0 days ago
  206. Docs: info:tinc
  207. man:tinc(8)
  208. man:tinc.conf(5)
  209. http://tinc-vpn.org/docs/
  210. Main PID: 472 (tincd)
  211. Tasks: 1 (limit: 4657)
  212. Memory: 4.1M
  213. CPU: 22min 34.347s
  214. CGroup: /system.slice/system-tinc.slice/tinc@lan.service
  215. └─472 /usr/sbin/tincd -n lan -D
  216. ...
  217. Dabei ist das enabled in der Loaded Zeile wichtig.
  218. Falls die Statusabfrage eine Fehlermeldung "Bogus data ..." bringt, alle Schlüssel,
  219. also auch die privaten, löschen und wie oben beschrieben neu erzeugen und verteilen.
  220. Um die Programme automatisch nach einem reboot zu starten, eventuell
  221. falls nicht durch die Installation schon eingerichtet:
  222. systemctl enable tinc
  223. systemctl enable tinc@lan
  224. systemctl enable tinc@wan
  225. # Bird auf der APU berghofen und Laptop berglap
  226. /etc/iproute2/rt_tables identisch auf APU / laptop
  227. #
  228. # reserved values
  229. #
  230. 255 local
  231. 254 main
  232. 253 default
  233. 0 unspec
  234. #
  235. # local
  236. #
  237. 1 tinc
  238. - Die bird.conf des laptops ist bis auf andere IP Adressen identisch
  239. /etc/bird/bird.conf
  240. # bird.conf Alle Anpassungen als defines
  241. # damit keine übersehen wird
  242. define publicIP = 193.43.220.130;
  243. define publicIP_32 = 193.43.220.130/32;
  244. define isprouter = 192.168.178.254;
  245. # ab hier passt alles für unsere lan/wan Netze
  246. router id publicIP;
  247. # log syslog { debug, info, trace, remote }; /* optional */
  248. define AS35675_all = [
  249. 193.43.220.0/23
  250. ];
  251. define AS35675_any = [
  252. 193.43.220.0/23+
  253. ];
  254. protocol device device0 {
  255. scan time 10;
  256. }
  257. /* wg. BSD: */
  258. protocol direct direct0 {
  259. ipv4;
  260. }
  261. protocol kernel kernel0 {
  262. learn on;
  263. scan time 120;
  264. ipv4 {
  265. import all;
  266. export where source != RTS_DEVICE;
  267. };
  268. }
  269. # erstellt neue routing tabelle
  270. ipv4 table fib1table;
  271. #RTS route source
  272. #import / export
  273. protocol kernel kernel1 {
  274. kernel table 1;
  275. learn on;
  276. scan time 120;
  277. ipv4 {
  278. table fib1table;
  279. import all;
  280. export where source != RTS_DEVICE;
  281. };
  282. }
  283. protocol static static1 {
  284. ipv4 {
  285. table fib1table;
  286. };
  287. route 0.0.0.0/0 via isprouter; /* zur F!Box */
  288. }
  289. protocol ospf ospfwan {
  290. ipv4 {
  291. import all;
  292. export where net ~ AS35675_any;
  293. };
  294. area 0.0.0.0 {
  295. stubnet publicIP_32 { cost 1; };
  296. interface "wan" {
  297. type broadcast;
  298. cost 100;
  299. };
  300. interface "lan" {
  301. type broadcast;
  302. cost 10;
  303. };
  304. };
  305. }
  306. Den bird starten und eventuell rebootfest machen:
  307. systemctl start bird
  308. systemctl enable bird