Community/Bildung/FF@home/12 Debian 10 mit Tinc und Bird

Software

  • Debian 11 (bullseye), Debian 12 (bookworm) und auf dem Laptop Ubuntu 18.04, inzwischen 22.04
  • Tinc 1.0.36 oder tinc 1.1pre18
  • Bird 2.07

    ***** Bitte beachten, dass Bird2 installiert wird. Bei Installation von Bird1 erfolgt nur eine kryptische Fehlermeldung und Bird startet nicht.*****

Installation

  • Installation des Betriebssystems wird hier nicht beschrieben.
  • Hier werden die Schritte nach der Installation von Debian 11 (bullseye) zum Aufbau eines VPN mit Tinc und Bird beschrieben.
  • Für einige Befehle sind root Rechte erforderlich.
  • Tinc 1.0.36 und bird 2 können aus dem Debian Repository installiert werden mit

    sudo apt install tinc bird2

  • Tinc 1.1pre18 ist mit erweiterter control Schnittstelle tinc1.0.36 vorzuziehen und kann aus den Sourcen kompiliert werden:
    Dafür sind Pakete der Entwicklungsumgebung für Debian erforderlich
    sudo apt install build-essential libncurses-dev libreadline-dev liblzo2-dev libssl-dev zlib1g-dev texinfo

    Dann die tinc sourcen runterladen und entpacken
    wget http://tinc-vpn.org/packages/tinc-1.1pre18.tar.gz
    tar zxvf tinc-1.1pre18.tar.gz

    In das von dem vorigen Befehl angelegte Verzeichnis wechseln:
    cd tinc-1.1pre18 und configure / make / make install aufrufen

    ./configure --prefix=/usr --sysconfdir=/etc --runstatedir=/run --localstatedir=/var --with-systemd

    Falls Fehler auftreten, fehlende Pakete in der xxx-dev Version nachinstallieren, dann
    make

    sudo make install
    Damit alles richtig angelegt wird, auch die systemctl systemd Steuerung, muss tinc 1.1pre18 mit den Parametern oben konfiguriert werden:

Allgemein

  • Informationen auf dieser Seite sind teilweise von anderen Wiki-Seiten übernommen.

Es werden für alle Interfaces statische IPV4 Adressen verwendet, auf dem Laptop ist auch DHCP aktiv. Die hier verwendeten Adressen sind dem Wiki IP-Adressen für berghofen entnommen.

Hardware

  • APU mit Debian 11 (Bullseye) ohne grafische Oberfläche
  • Laptop mit Ubuntu 22.04

Berghofen, wie auch die anderen Standorte, besteht jeweils mindestens aus der APU und einem Laptop sowie einem Internetrouter (F!Box).
An jedem Standort gibt es mehrere Tincverbindungen:
- lan: zwischen APU und Laptop
- wan: zwischen APU und den anderen Standorten
- wan: zwischen Laptop und den anderen Standorten

Dateien der APU

/etc/network/interfaces

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback
    	up ip addr add 193.43.220.130/32 dev lo
	
# The primary network interface
allow-hotplug enp1s0
iface enp1s0 inet static
	address 192.168.178.51/24
	
	#default gateway wird von bird erledigt
        # gateway 192.168.178.254 
	broadcast 192.168.178.255
	# dns-* options are implemented by the resolvconf package, if installed
	dns-nameservers 192.168.178.254
	dns-search fritz.box
	up ip rule add from all iif enp1s0 lookup 1 prio 1000 || true
        up ip rule add from 192.168.178.0/24 lookup 1 prio 1010 || true

allow-hotplug wan
iface wan inet static
	address 193.43.220.162/27
	broadcast 193.43.220.191
	mtu 1504

allow-hotplug lan
iface lan inet static
	address 192.168.34.1/24
	broadcast 192.168.34.255
	mtu 1504

#allow-hotplug wlp5s0 # wlan z.Zt. nicht verwendet
#iface wlp5s0 inet dhcp

Die Schnittstellen der Interfacesdatei sind:
- lo Standardloopback
- enp1s0 ethernet
- wan virtuelle Tinc Schnittstelle
- lan virtuelle Tinc Schnittstelle
- wlp5s0 nicht verwendet, auskommentierte WLAN Schnittstelle

Für die Datenweitergabe zwischen den Netzen ist der folgende Eintrag nötig.

/etc/sysctl.conf

# Uncomment the next line to enable packet forwarding for IPv4
net.ipv4.ip_forward=1

Tinc Verzeichnistruktur Tinc APU und Laptop Einstellungen

etc/tinc/
|-- lan
|   |-- hosts
|   |   |-- berghofen
|   |   `-- berglap
|   |-- rsa_key.priv
|   |-- ed25519_key.priv  ## nur bei tinc 1.1
|   `-- tinc.conf
`-- wan   
    |-- hosts
    |   |-- berghofen 
    |   |-- berglap
    |   |-- hoerde
    |   `-- nordstadt
    |-- rsa_key.priv
    |-- ed25519_key.priv  ## nur bei tinc 1.1
    `-- tinc.conf

/etc/tinc/lan/tinc.conf der APU berghofen

## APU lan tinc.conf
Name = berghofen
Device = /dev/net/tun
Mode = switch
AddressFamily = ipv4
BindToAddress = 192.168.178.51
Port = 10001
MaxTimeout = 30
GraphDumpFile = /var/run/tinc.lan.dot
ConnectTo = berglap

/etc/tinc/wan/tinc.conf der APU berghofen

## APU wan tinc.conf
Name = berghofen
Device = /dev/net/tun
Mode = switch
AddressFamily = ipv4
BindToaddress = 192.168.178.51
Port = 661
MaxTimeout = 30
GraphDumpFile = /var/run/tinc.wan.dot
ConnectTo = hoerde
ConnectTo = nordstadt

/etc/tinc/lan/tinc.conf des Laptop berglap

## Laptop lan tinc.conf
Name = berglap
Device = /dev/net/tun
Mode = switch
AddressFamily = ipv4
BindToAddress = 192.168.178.52
Port = 10001
MaxTimeout = 30
GraphDumpFile = /var/run/tinc.lan.dot
ConnectTo = berghofen

/etc/tinc/wan/tinc.conf des Laptop berglap

## Laptop wan tinc.conf
Name = berglap
Device = /dev/net/tun
Mode = switch
AddressFamily = ipv4
BindToaddress = 192.168.178.52
Port = 661
MaxTimeout = 30
GraphDumpFile = /var/run/tinc.wan.dot
ConnectTo = hoerde
ConnectTo = nordstadt

Da auf jedem Rechner 2 Tincinstanzen an demselben Interface laufen, werden sie durch unterschiedliche Ports getrennt: WAN mit port 661, LAN mit Port 10001.

Inhalt der hosts Dateien

Die Public und private Keys werden von Tinc erzeugt:

bei tinc 1.0.36:

tincd -n wan -K 4096
tincd -n lan -K 4096 

bei tinc 1.1:

tinc -n wan generate-keys 4096
tinc -n lan generate-keys 4096

Die ED25519PublicKey Zeile wird nur bei tinc 1.1 erzeugt/verwendet.

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.

/etc/tinc/lan/hosts/berghofen auf APU und laptop

Address = 192.168.178.51
Port = 10001

-----BEGIN RSA PUBLIC KEY-----
 Schlüsseldaten 
-----END RSA PUBLIC KEY-----
Ed25519PublicKey = WmAmMY95+B/A9FDQz7ZiV6WQcG2qAUUclRP52dwXSdD

/etc/tinc/lan/hosts/berglap auf APU und laptop

Address = 192.168.178.52
Port = 10001

-----BEGIN RSA PUBLIC KEY-----
 Schlüsseldaten 
-----END RSA PUBLIC KEY-----
Ed25519PublicKey = WCkEAe/gohI7JAGLiHPKdE+ayxYrG1wuTfQQijAROuD

/etc/tinc/wan/hosts/berghofen auf APU

-----BEGIN RSA PUBLIC KEY-----
 Schlüsseldaten 
-----END RSA PUBLIC KEY-----
Ed25519PublicKey = Tkhp7t+MsmQKsWIkO5qimTKoWdkvRigKwctxtfOu2MF

/etc/tinc/wan/hosts/hoerde auf APU und berglap

Address = 130.180.53.22
Port = 661

-----BEGIN RSA PUBLIC KEY-----
 Schlüsseldaten
-----END RSA PUBLIC KEY-----
Ed25519PublicKey = MjaltxtfPP1SdHgNH/dUuHmbYDXFdZMEUUbl0Qi/YCA

/etc/tinc/wan/hosts/nordstadt auf APU und berglap

Address = 91.204.4.53
Port = 661

-----BEGIN RSA PUBLIC KEY-----
 Schlüsseldaten
-----END RSA PUBLIC KEY-----
Ed25519PublicKey = 4znU87BKnctOFb+/JQhIltGtYN3h3czOVInolRPWgvA

/etc/tinc/wan/hosts/berglap auf berglap

-----BEGIN RSA PUBLIC KEY-----
 Schlüsseldaten
-----END RSA PUBLIC KEY-----
Ed25519PublicKey = 4znU87BKnctOFb+/JQhIltGtYN3h3czOVInolRPWgvA

Die Tinc Instanzen können auf APU und berglap gestartet werden mit:

systemctl start tinc
systemctl start tinc@lan
systemctl start tinc@wan

Beispielhaft tinc@lan abfragen:

systemctl status tinc@lan

tinc@lan.service - Tinc net lan
 Loaded: loaded (/lib/systemd/system/tinc@.service; enabled; vendor preset: enabled)
 Active: active (running) since Tue 2022-03-29 21:26:01 CEST; 1 months 0 days ago
   Docs: info:tinc
         man:tinc(8)
         man:tinc.conf(5)
         http://tinc-vpn.org/docs/
Main PID: 472 (tincd)
  Tasks: 1 (limit: 4657)
 Memory: 4.1M
    CPU: 22min 34.347s
 CGroup: /system.slice/system-tinc.slice/tinc@lan.service
         └─472 /usr/sbin/tincd -n lan -D

… Dabei ist das enabled in der Loaded Zeile wichtig.

Falls die Statusabfrage eine Fehlermeldung “Bogus data …” bringt, alle Schlüssel,
also auch die privaten, löschen und wie oben beschrieben neu erzeugen und verteilen.

Um die Programme automatisch nach einem reboot zu starten, eventuell falls nicht durch die Installation schon eingerichtet:

systemctl enable tinc
systemctl enable tinc@lan
systemctl enable tinc@wan

Bird auf der APU berghofen und Laptop berglap

/etc/iproute2/rt_tables identisch auf APU / laptop

#
# reserved values
#
255	    local
254	    main
253	    default
0	    unspec
#
# local
#
1       tinc
  • Die bird.conf des laptops ist bis auf andere IP Adressen identisch

/etc/bird/bird.conf

# bird.conf Alle Anpassungen als defines
# damit keine übersehen wird

define publicIP = 193.43.220.130;
define publicIP_32 = 193.43.220.130/32;
define isprouter = 192.168.178.254;

# ab hier passt alles für unsere lan/wan Netze

router id publicIP;

# log syslog { debug, info, trace, remote }; /* optional */

define AS35675_all = [
        193.43.220.0/23
        ];

define AS35675_any = [
        193.43.220.0/23+
        ];

protocol device device0 {
        scan time 10;
}


/* wg. BSD: */
protocol direct direct0 {
        ipv4;
}

protocol kernel kernel0 {
        learn on;
        scan time 120;
        ipv4 {
                import all;
                export where source != RTS_DEVICE;
        };
}

# erstellt neue routing tabelle 
ipv4 table fib1table;

#RTS route source
#import / export
protocol kernel kernel1 {
        kernel table 1;
        learn on;
        scan time 120;
        ipv4 {
                table fib1table;
                import all;
                export where source != RTS_DEVICE;
        };
}

protocol static static1 {
        ipv4 {
                table fib1table;
        };
        route 0.0.0.0/0 via isprouter; /* zur F!Box */
}

protocol ospf ospfwan {
        ipv4 {
                import all;
                export where net ~ AS35675_any;
        };
        area 0.0.0.0 {
                stubnet publicIP_32 { cost 1; };
                interface "wan" {    
                        type broadcast;
                        cost 100;
                };
                interface "lan" {
                        type broadcast;
                        cost 10;
                };
        };
}

Den bird starten und eventuell rebootfest machen:

systemctl start bird
systemctl enable bird