12 Debian 10 mit Tinc und Bird.page 11 KB

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