Debian10 mit Tinc und Bird.page 10 KB

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