12 Debian 10 mit Tinc und Bird.page 11 KB

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