12 Debian 10 mit Tinc und Bird.page 12 KB

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