12 Debian 10 mit Tinc und Bird.page 12 KB

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