Skip to content

Wireguard

Verschoben Wireguard
  • Diese Anleitung ignoriert ein paar Sicherheitseinstellungen. Einige Daten dürfen nicht von anderen einsehbar sein. Dazu bitte die Anleitung von wireguard beachten! Das hier ist ein Test im lokalen Netz, da interessiert mich das nicht so sehr. Im "bösen" Internet bitte unbedingt beachten!

    In letzter Zeit liest man immer von Wireguard und das es bald evt. in den Kernel aufgenommen wird. Das macht doch jemanden wie mich furchtbar neugierig.

    Was kann man mit einem VPN-Tunnel anstellen?

    • Man verbindet zwei unterschiedliche Standorte zu einem Netz
    • Man möchte evt. seine eigene IP-Adresse tarnen
    • Man möchte auf sein Heimnetzwerk von unterwegs aus drauf zugreifen
    • Man möchte zwei Server verbinden, die dann z.B. die Redis-Datenbank in Master/Slave Modus betreiben
      und vieles andere

    Dann geht es mal ans Ausprobieren, wie immer auf einem ROCKPro64 bzw. zwei 😉

    Installation Kernel-Modul

    Dieser Teil ist überflüssig geworden mit dem Release RC12, bitte den nächsten Beitrag von mir lesen.

    Wir brauchen für Wireguard ein Kernelmodul, das aber nicht vorhanden ist. Dann bauen wir das mal selber.

    sudo apt-get install libmnl-dev libelf-dev linux-headers-$(uname -r) build-essential pkg-config
    git clone https://git.zx2c4.com/WireGuard
    cd WireGuard/src
    make
    sudo make install
    

    Konfiguration Tunnel

    Danach ist alles vorhanden, was wir benötigen. In diesem Beispiel wollen wir eine Peer-to-Peer Verbindung aufbauen.

    Peer-to-Peer Tunnel

    RP64 Nr.1

    • LAN Adresse: 192.168.3.208
    • Wireguard IP 192.168.10.1

    RP64 Nr.2

    • LAN Adresse: 192.168.3.14
    • Wireguard IP 192.168.10.2

    Unter /etc/wireguard legt man alle Keys und Konfigdateien ab.

    cd /etc/wireguard
    

    Der Ordner ist standardmäßig leer!

    Keys erzeugen:

    private.key erzeugen

    root@rp64_nextcloud:/etc/wireguard# wg genkey > private.key
    Warning: writing to world accessible file.
    Consider setting the umask to 077 and trying again.
    

    public.key erzeugen

    root@rp64_nextcloud:/etc/wireguard# wg pubkey > public.key < private.key
    

    psk.key erzeugen

    root@rp64_nextcloud:/etc/wireguard# wg genpsk > psk.key
    

    Schnittstelle erzeugen

    sudo ip link add wg0 type wireguard
    sudo ip addr add 192.168.10.1/24 dev wg0
    

    Ausgabe: Nur Schnittstelle angelegt

    root@rp64_nextcloud:/etc/wireguard# wg
    interface: wg0
    

    Key hinzufügen

    cd /etc/wireguard
    wg set wg0 private-key ./private.key 
    

    Ausgabe: Key hinzugefügt!

    root@rp64_nextcloud:/etc/wireguard# wg
    interface: wg0
    public key: gqiCgt5+X3na+wZ1e9gnR1pTujFO3jIudnwDIttDPEo=
    private key: (hidden)
    

    Schnittstelle IP-Adresse löschen

    Falls man sich mal vertan hat, kann man hiermit alle IP-Adressen einer Schnittstelle löschen.

    ip addr flush dev wg0
    

    Schnittstelle aktivieren

    ip link set wg0 up 
    

    Wenn man das vergisst, wird einem beim Befehl wg kein Port angezeigt.

    Nicht richtig

    interface: wg0
      public key: gqiCgt5+X3na+wZ1e9gnR1pTujFO3jIudnwDIttDPEo=
      private key: (hidden)
    

    Korrekt

    interface: wg0
      public key: gqiCgt5+X3na+wZ1e9gnR1pTujFO3jIudnwDIttDPEo=
      private key: (hidden)
      listening port: 35866
    

    Peer bekanntmachen

    wg set wg0 peer zj1ajjcBhgFSe+NUHtnTNQ4+emsVgHDPVOeQHVKK4U4= allowed-ips 192.168.10.2/32 endpoint 192.168.3.14:53751
    
    • wg = Programm wireguard
    • set = Befehl
    • wg0 = Interface
    • peer = Peer to Peer Verbindung
    • PUBLICKEY = Den public.key vom ZIEL
    • allowed-ips IP-Adresse des Ziels, hier 192.168.10.2 gewählt
    • endpoint 192.168.3.14:PORT / LAN IP Schnittstelle und PORT

    Das ganze ist dann auf beiden Rechner auszuführen, nicht besonders viel Arbeit wenn man es einmal verstanden hat. Ich habe hier nur die Schritte auf dem einen Rechner aufgelistet.

    Test

    Ping Test RP Nr. 1

    root@rp64_nextcloud:/etc/wireguard# ping 192.168.10.2
    PING 192.168.10.2 (192.168.10.2) 56(84) bytes of data.
    64 bytes from 192.168.10.2: icmp_seq=1 ttl=64 time=2.50 ms
    64 bytes from 192.168.10.2: icmp_seq=2 ttl=64 time=2.99 ms
    64 bytes from 192.168.10.2: icmp_seq=3 ttl=64 time=2.75 ms
    64 bytes from 192.168.10.2: icmp_seq=4 ttl=64 time=2.59 ms
    64 bytes from 192.168.10.2: icmp_seq=5 ttl=64 time=2.91 ms
    ^C
    --- 192.168.10.2 ping statistics ---
    5 packets transmitted, 5 received, 0% packet loss, time 4007ms
    rtt min/avg/max/mdev = 2.509/2.755/2.998/0.194 ms
    

    Ping Test RP Nr. 2

    root@rockpro64:/etc/wireguard# ping 192.168.10.1
    PING 192.168.10.1 (192.168.10.1) 56(84) bytes of data.
    64 bytes from 192.168.10.1: icmp_seq=1 ttl=64 time=2.95 ms
    64 bytes from 192.168.10.1: icmp_seq=2 ttl=64 time=2.83 ms
    64 bytes from 192.168.10.1: icmp_seq=3 ttl=64 time=2.43 ms
    ^C
    --- 192.168.10.1 ping statistics ---
    3 packets transmitted, 3 received, 0% packet loss, time 2003ms
    rtt min/avg/max/mdev = 2.430/2.740/2.958/0.225 ms
    

    Nach erfolgreichem Pingtest, kann man mit dem Befehl wg sehen, wie viel Daten man transferiert hat.

    root@rp_64_test:/etc/wireguard# wg
    interface: wg0
      public key: zj1ajjcBhgFSe+NUHtnTNQ4+emsVgHDPVOeQHVKK4U4=
      private key: (hidden)
      listening port: 41908
    
    peer: gqiCgt5+X3na+wZ1e9gnR1pTujFO3jIudnwDIttDPEo=
      endpoint: 192.168.3.208:35866
      allowed ips: 192.168.10.1/32
      latest handshake: 52 seconds ago
      transfer: 4.84 KiB received, 4.93 KiB sent
    

    Iperf3

    Iperf3 Test RP Nr. 1 (Server)

    root@rp64_nextcloud:/etc/wireguard# iperf3 -B 192.168.10.1 -s
    -----------------------------------------------------------
    Server listening on 5201
    -----------------------------------------------------------
    Accepted connection from 192.168.10.2, port 32876
    [  5] local 192.168.10.1 port 5201 connected to 192.168.10.2 port 32878
    [ ID] Interval           Transfer     Bandwidth
    [  5]   0.00-1.00   sec  75.5 MBytes   633 Mbits/sec                  
    [  5]   1.00-2.00   sec   106 MBytes   891 Mbits/sec                  
    [  5]   2.00-3.00   sec   107 MBytes   895 Mbits/sec                  
    [  5]   3.00-4.00   sec   107 MBytes   901 Mbits/sec                  
    [  5]   4.00-5.00   sec   107 MBytes   900 Mbits/sec                  
    [  5]   5.00-6.00   sec   107 MBytes   899 Mbits/sec                  
    [  5]   6.00-7.00   sec   107 MBytes   901 Mbits/sec                  
    [  5]   7.00-8.00   sec   107 MBytes   895 Mbits/sec                  
    [  5]   8.00-9.00   sec   107 MBytes   896 Mbits/sec                  
    [  5]   9.00-10.00  sec   107 MBytes   897 Mbits/sec                  
    [  5]  10.00-10.02  sec  1.91 MBytes   893 Mbits/sec                  
    - - - - - - - - - - - - - - - - - - - - - - - - -
    [ ID] Interval           Transfer     Bandwidth
    [  5]   0.00-10.02  sec  0.00 Bytes  0.00 bits/sec                  sender
    [  5]   0.00-10.02  sec  1.02 GBytes   871 Mbits/sec                  receiver
    -----------------------------------------------------------
    Server listening on 5201
    -----------------------------------------------------------
    ^Ciperf3: interrupt - the server has terminated
    

    Iperf3 Test RP Nr. 2 (Client)

    root@rockpro64:/etc/wireguard# iperf3 -c 192.168.10.1
    Connecting to host 192.168.10.1, port 5201
    [  4] local 192.168.10.2 port 32878 connected to 192.168.10.1 port 5201
    [ ID] Interval           Transfer     Bandwidth       Retr  Cwnd
    [  4]   0.00-1.00   sec  80.3 MBytes   673 Mbits/sec    3   1.52 MBytes       
    [  4]   1.00-2.00   sec   106 MBytes   889 Mbits/sec    1    910 KBytes       
    [  4]   2.00-3.00   sec   106 MBytes   891 Mbits/sec    0   1.01 MBytes       
    [  4]   3.00-4.00   sec   108 MBytes   910 Mbits/sec    0   1.11 MBytes       
    [  4]   4.00-5.00   sec   107 MBytes   899 Mbits/sec    0   1.21 MBytes       
    [  4]   5.00-6.00   sec   107 MBytes   900 Mbits/sec    0   1.30 MBytes       
    [  4]   6.00-7.00   sec   107 MBytes   900 Mbits/sec    0   1.39 MBytes       
    [  4]   7.00-8.00   sec   106 MBytes   891 Mbits/sec    1    811 KBytes       
    [  4]   8.00-9.00   sec   107 MBytes   900 Mbits/sec    0    942 KBytes       
    [  4]   9.00-10.00  sec   107 MBytes   896 Mbits/sec    0   1.04 MBytes       
    - - - - - - - - - - - - - - - - - - - - - - - - -
    [ ID] Interval           Transfer     Bandwidth       Retr
    [  4]   0.00-10.00  sec  1.02 GBytes   875 Mbits/sec    5             sender
    [  4]   0.00-10.00  sec  1.02 GBytes   872 Mbits/sec                  receiver
    
    iperf Done.
    

    Iperf3 normales LAN

    root@rp64_nextcloud:/etc/wireguard# iperf3 -s
    -----------------------------------------------------------
    Server listening on 5201
    -----------------------------------------------------------
    Accepted connection from 192.168.3.14, port 39548
    [  5] local 192.168.3.208 port 5201 connected to 192.168.3.14 port 39550
    [ ID] Interval           Transfer     Bandwidth
    [  5]   0.00-1.00   sec   110 MBytes   925 Mbits/sec                  
    [  5]   1.00-2.00   sec   112 MBytes   942 Mbits/sec                  
    [  5]   2.00-3.00   sec   112 MBytes   940 Mbits/sec                  
    [  5]   3.00-4.00   sec   112 MBytes   940 Mbits/sec                  
    [  5]   4.00-5.00   sec   112 MBytes   939 Mbits/sec                  
    [  5]   5.00-6.00   sec   112 MBytes   938 Mbits/sec                  
    [  5]   6.00-7.00   sec   112 MBytes   938 Mbits/sec                  
    [  5]   7.00-8.00   sec   112 MBytes   939 Mbits/sec                  
    [  5]   8.00-9.00   sec   112 MBytes   940 Mbits/sec                  
    [  5]   9.00-10.00  sec   111 MBytes   927 Mbits/sec                  
    [  5]  10.00-10.02  sec  1.97 MBytes   924 Mbits/sec                  
    - - - - - - - - - - - - - - - - - - - - - - - - -
    [ ID] Interval           Transfer     Bandwidth
    [  5]   0.00-10.02  sec  0.00 Bytes  0.00 bits/sec                  sender
    [  5]   0.00-10.02  sec  1.09 GBytes   937 Mbits/sec                  receiver
    -----------------------------------------------------------
    Server listening on 5201
    -----------------------------------------------------------
    Accepted connection from 192.168.3.14, port 39552
    [  5] local 192.168.3.208 port 5201 connected to 192.168.3.14 port 39554
    [ ID] Interval           Transfer     Bandwidth       Retr  Cwnd
    [  5]   0.00-1.00   sec   114 MBytes   958 Mbits/sec    0   1.36 MBytes       
    [  5]   1.00-2.00   sec   112 MBytes   943 Mbits/sec    0   1.36 MBytes       
    [  5]   2.00-3.00   sec   111 MBytes   936 Mbits/sec    0   1.84 MBytes       
    [  5]   3.00-4.00   sec   111 MBytes   933 Mbits/sec    0   1.84 MBytes       
    [  5]   4.00-5.00   sec   108 MBytes   901 Mbits/sec    0   1.84 MBytes       
    [  5]   5.00-6.00   sec   111 MBytes   934 Mbits/sec    0   1.84 MBytes       
    [  5]   6.00-7.00   sec   112 MBytes   944 Mbits/sec    0   1.84 MBytes       
    [  5]   7.00-8.00   sec   112 MBytes   944 Mbits/sec    0   1.84 MBytes       
    [  5]   8.00-9.00   sec   112 MBytes   943 Mbits/sec    0   1.84 MBytes       
    [  5]   9.00-10.00  sec   111 MBytes   934 Mbits/sec    0   1.84 MBytes       
    [  5]  10.00-10.01  sec  1.25 MBytes  1.15 Gbits/sec    0   1.84 MBytes       
    - - - - - - - - - - - - - - - - - - - - - - - - -
    [ ID] Interval           Transfer     Bandwidth       Retr
    [  5]   0.00-10.01  sec  1.09 GBytes   937 Mbits/sec    0             sender
    [  5]   0.00-10.01  sec  0.00 Bytes  0.00 bits/sec                  receiver
    -----------------------------------------------------------
    Server listening on 5201
    -----------------------------------------------------------
    

    Fazit

    Ultra coole Sache 🙂 Ich habe noch nie so schnell einen Tunnel aufgebaut! Meine Erinnerungen an OpenVPN kommen da hoch, was war das ein Gefummel bis da mal eine Verbindung stand. Die Perfomance der Verbindung war ebenfalls überraschend schnell. Bitte beachten, das war ein Test zweier ROCKPro64 in meinem lokalem Netz. Ein Test in der freien Wildbahn folgt aber! 😉

    Und zum Schluss folgender Hinweis der wireguard Webseite!

    WireGuard is not yet complete. You should not rely on this code. It has not undergone proper degrees of security auditing and the protocol is still subject to change. We're working toward a stable 1.0 release, but that time has not yet come. There are experimental snapshots tagged with "0.0.YYYYMMDD", but these should not be considered real releases and they may contain security vulnerabilities (which would not be eligible for CVEs, since this is pre-release snapshot software). If you are packaging WireGuard, you must keep up to date with the snapshots.

  • So, gibt was Neues 🙂 Kamil hat mit dem Release RC12 ein paar Dinge verbessert.

    Software

    root@rockpro64:~# uname -a
    Linux rockpro64 4.4.167-1189-rockchip-ayufan-gea9ef7a80268 #1 SMP Tue May 28 14:37:31 UTC 2019 aarch64 aarch64 aarch64 GNU/Linux
    

    https://github.com/ayufan-rock64/linux-build/releases/download/0.8.0rc12/bionic-minimal-rockpro64-0.8.0rc12-1132-arm64.img.xz

    ## Wireguard
    
    Installing Wireguard is very simple with DKMS and makes Wireguard to be auto-updated
    after kernel change.
    
    Following the documentation from https://www.wireguard.com/install/:
    
    ```bash
    sudo add-apt-repository ppa:wireguard/wireguard
    sudo apt-get install python wireguard
    ```
    

    Ok, DKMS !?

    DKMS 🇬🇧 steht für Dynamic Kernel Module Support. Das von Dell entwickelte Hilfsprogramm überwacht, ob zusätzliche >Kernelmodule manuell installiert wurden und aktualisiert die Module immer dann, wenn ein neuer oder aktualisierter Kernel installiert wird. Dies ist insofern praktisch, dass das Kompilieren des Kernelmoduls nicht immer von Hand durchgeführt werden muss, wenn der Kernel aktualisiert wurde.
    Quelle: https://wiki.ubuntuusers.de/DKMS/

    So für mich als normaler User, ich muss mir Wireguard jetzt nicht mehr bauen, sondern kann es ganz bequem installieren. Die dazu benötigten Befehle stehen weiter oben.

    Repository adden

    rock64@rockpro64:~$ sudo add-apt-repository ppa:wireguard/wireguard
     WireGuard is a novel VPN that runs inside the Linux Kernel. This is the Ubuntu packaging for WireGuard. More info may be found at its website, listed below.
    
    More info: https://www.wireguard.com/
    Packages: wireguard wireguard-tools wireguard-dkms
    
    Install with: $ apt install wireguard
    
    For help, please contact <email address hidden>
     More info: https://launchpad.net/~wireguard/+archive/ubuntu/wireguard
    Press [ENTER] to continue or Ctrl-c to cancel adding it.
    

    Wireguard installieren

    rock64@rockpro64:~$ sudo apt-get install python wireguard
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    The following additional packages will be installed:
      dkms libpython-stdlib libpython2.7-minimal libpython2.7-stdlib python-minimal python2.7 python2.7-minimal wireguard-dkms wireguard-tools
    Suggested packages:
      python3-apport menu python-doc python-tk python2.7-doc binfmt-support
    Recommended packages:
      fakeroot
    The following NEW packages will be installed:
      dkms libpython-stdlib libpython2.7-minimal libpython2.7-stdlib python python-minimal python2.7 python2.7-minimal wireguard wireguard-dkms
      wireguard-tools
    0 upgraded, 11 newly installed, 0 to remove and 0 not upgraded.
    Need to get 4451 kB of archives.
    After this operation, 21.4 MB of additional disk space will be used.
    Do you want to continue? [Y/n] 
    Get:1 http://ppa.launchpad.net/wireguard/wireguard/ubuntu bionic/main arm64 wireguard-dkms all 0.0.20190406-wg1~bionic [553 kB]
    Get:2 http://ports.ubuntu.com/ubuntu-ports bionic-security/main arm64 libpython2.7-minimal arm64 2.7.15~rc1-1ubuntu0.1 [334 kB]
    Get:3 http://ports.ubuntu.com/ubuntu-ports bionic-security/main arm64 python2.7-minimal arm64 2.7.15~rc1-1ubuntu0.1 [1142 kB]
    Get:4 http://ppa.launchpad.net/wireguard/wireguard/ubuntu bionic/main arm64 wireguard-tools arm64 0.0.20190406-wg1~bionic [84.1 kB]
    Get:5 http://ports.ubuntu.com/ubuntu-ports bionic/main arm64 python-minimal arm64 2.7.15~rc1-1 [28.1 kB]
    Get:6 http://ports.ubuntu.com/ubuntu-ports bionic-security/main arm64 libpython2.7-stdlib arm64 2.7.15~rc1-1ubuntu0.1 [1851 kB]
    Get:7 http://ppa.launchpad.net/wireguard/wireguard/ubuntu bionic/main arm64 wireguard all 0.0.20190406-wg1~bionic [4168 B]
    Get:8 http://ports.ubuntu.com/ubuntu-ports bionic-security/main arm64 python2.7 arm64 2.7.15~rc1-1ubuntu0.1 [238 kB]
    Get:9 http://ports.ubuntu.com/ubuntu-ports bionic/main arm64 libpython-stdlib arm64 2.7.15~rc1-1 [7620 B]
    Get:10 http://ports.ubuntu.com/ubuntu-ports bionic/main arm64 python arm64 2.7.15~rc1-1 [140 kB]
    Get:11 http://ports.ubuntu.com/ubuntu-ports bionic-updates/main arm64 dkms all 2.3-3ubuntu9.2 [68.0 kB]
    Fetched 4451 kB in 1s (6651 kB/s)
    Selecting previously unselected package libpython2.7-minimal:arm64.
    (Reading database ... 47070 files and directories currently installed.)
    Preparing to unpack .../0-libpython2.7-minimal_2.7.15~rc1-1ubuntu0.1_arm64.deb ...
    Unpacking libpython2.7-minimal:arm64 (2.7.15~rc1-1ubuntu0.1) ...
    Selecting previously unselected package python2.7-minimal.
    Preparing to unpack .../1-python2.7-minimal_2.7.15~rc1-1ubuntu0.1_arm64.deb ...
    Unpacking python2.7-minimal (2.7.15~rc1-1ubuntu0.1) ...
    Selecting previously unselected package python-minimal.
    Preparing to unpack .../2-python-minimal_2.7.15~rc1-1_arm64.deb ...
    Unpacking python-minimal (2.7.15~rc1-1) ...
    Selecting previously unselected package libpython2.7-stdlib:arm64.
    Preparing to unpack .../3-libpython2.7-stdlib_2.7.15~rc1-1ubuntu0.1_arm64.deb ...
    Unpacking libpython2.7-stdlib:arm64 (2.7.15~rc1-1ubuntu0.1) ...
    Selecting previously unselected package python2.7.
    Preparing to unpack .../4-python2.7_2.7.15~rc1-1ubuntu0.1_arm64.deb ...
    Unpacking python2.7 (2.7.15~rc1-1ubuntu0.1) ...
    Selecting previously unselected package libpython-stdlib:arm64.
    Preparing to unpack .../5-libpython-stdlib_2.7.15~rc1-1_arm64.deb ...
    Unpacking libpython-stdlib:arm64 (2.7.15~rc1-1) ...
    Setting up libpython2.7-minimal:arm64 (2.7.15~rc1-1ubuntu0.1) ...
    Setting up python2.7-minimal (2.7.15~rc1-1ubuntu0.1) ...
    Linking and byte-compiling packages for runtime python2.7...
    Setting up python-minimal (2.7.15~rc1-1) ...
    Selecting previously unselected package python.
    (Reading database ... 47818 files and directories currently installed.)
    Preparing to unpack .../python_2.7.15~rc1-1_arm64.deb ...
    Unpacking python (2.7.15~rc1-1) ...
    Selecting previously unselected package dkms.
    Preparing to unpack .../dkms_2.3-3ubuntu9.2_all.deb ...
    Unpacking dkms (2.3-3ubuntu9.2) ...
    Selecting previously unselected package wireguard-dkms.
    Preparing to unpack .../wireguard-dkms_0.0.20190406-wg1~bionic_all.deb ...
    Unpacking wireguard-dkms (0.0.20190406-wg1~bionic) ...
    Selecting previously unselected package wireguard-tools.
    Preparing to unpack .../wireguard-tools_0.0.20190406-wg1~bionic_arm64.deb ...
    Unpacking wireguard-tools (0.0.20190406-wg1~bionic) ...
    Selecting previously unselected package wireguard.
    Preparing to unpack .../wireguard_0.0.20190406-wg1~bionic_all.deb ...
    Unpacking wireguard (0.0.20190406-wg1~bionic) ...
    Processing triggers for mime-support (3.60ubuntu1) ...
    Setting up wireguard-tools (0.0.20190406-wg1~bionic) ...
    Setting up dkms (2.3-3ubuntu9.2) ...
    Setting up libpython2.7-stdlib:arm64 (2.7.15~rc1-1ubuntu0.1) ...
    Setting up wireguard-dkms (0.0.20190406-wg1~bionic) ...
    Loading new wireguard-0.0.20190406 DKMS files...
    Building for 4.4.167-1189-rockchip-ayufan-gea9ef7a80268
    Building initial module for 4.4.167-1189-rockchip-ayufan-gea9ef7a80268
    Done.
    
    wireguard:
    Running module version sanity check.
     - Original module
       - No original module exists within this kernel
     - Installation
       - Installing to /lib/modules/4.4.167-1189-rockchip-ayufan-gea9ef7a80268/updates/dkms/
    
    depmod...
    
    DKMS: install completed.
    Setting up python2.7 (2.7.15~rc1-1ubuntu0.1) ...
    Setting up libpython-stdlib:arm64 (2.7.15~rc1-1) ...
    Setting up wireguard (0.0.20190406-wg1~bionic) ...
    Setting up python (2.7.15~rc1-1) ...
    

    Danach ein Reboot und wie im ersten Beitrag beschrieben installieren.

    ROCKPro64 Nr.1

    root@rp64_nextcloud:/etc/wireguard# wg
    interface: wg0
      public key: gqiCgt5+X3na+wZ1e9gnR1pTujFO3jIudnwDIttDPEo=
      private key: (hidden)
      listening port: 53984
    
    peer: WU2zYy8EcQvGT2SlqcbY8O8DN1o28TlOT/9yS1+tcAk=
      endpoint: 192.168.3.18:34774
      allowed ips: 192.168.10.2/32
    root@rp64_nextcloud:/etc/wireguard# ping 192.168.10.2
    PING 192.168.10.2 (192.168.10.2) 56(84) bytes of data.
    64 bytes from 192.168.10.2: icmp_seq=1 ttl=64 time=15.2 ms
    64 bytes from 192.168.10.2: icmp_seq=2 ttl=64 time=2.22 ms
    64 bytes from 192.168.10.2: icmp_seq=3 ttl=64 time=2.42 ms
    ^C
    --- 192.168.10.2 ping statistics ---
    3 packets transmitted, 3 received, 0% packet loss, time 2003ms
    rtt min/avg/max/mdev = 2.221/6.629/15.247/6.094 ms
    

    ROCKPro64 Nr.2

    root@rockpro64:~# wg
    interface: wg0
      public key: WU2zYy8EcQvGT2SlqcbY8O8DN1o28TlOT/9yS1+tcAk=
      private key: (hidden)
      listening port: 34774
    
    peer: gqiCgt5+X3na+wZ1e9gnR1pTujFO3jIudnwDIttDPEo=
      endpoint: 192.168.3.208:53984
      allowed ips: 192.168.10.1/32
    root@rockpro64:~# ping 192.168.10.1
    PING 192.168.10.1 (192.168.10.1) 56(84) bytes of data.
    64 bytes from 192.168.10.1: icmp_seq=1 ttl=64 time=3.16 ms
    64 bytes from 192.168.10.1: icmp_seq=2 ttl=64 time=2.54 ms
    64 bytes from 192.168.10.1: icmp_seq=3 ttl=64 time=2.51 ms
    ^C
    --- 192.168.10.1 ping statistics ---
    3 packets transmitted, 3 received, 0% packet loss, time 2003ms
    rtt min/avg/max/mdev = 2.514/2.740/3.163/0.299 ms
    

    Fazit

    Tunnel steht, Ping Test erfolgreich.

  • Was machen, damit Wireguard auch einen Neustart übersteht?

    Das Image von Kamil basiert auf einem Ubuntu Minimal und nutzt systemd.

    Wir brauchen zwei Dateien, das Beispiel bezieht sich auf den Rechner Nr.2

    /etc/systemd/network/wg0.network

    [Match]
    Name=wg0
    
    [Network]
    Address=192.168.10.2
    #Address=2001:db8:1234:5678::1
    

    /etc/systemd/network/wg0.netdev

    [NetDev]
    Name=wg0
    Kind=wireguard
    Description=Wireguard tunnel
    
    [WireGuard]
    PrivateKey=<PrivateKey Rechner Nr.2>
    ListenPort=34774
    
    [WireGuardPeer]
    PublicKey=<PublicKey Rechner Nr.1>
    AllowedIPs=192.168.10.1/32
    #AllowedIPs=
    Endpoint=192.168.3.208:53984
    

    Danach

    systemctl daemon-reload
    systemctl start systemd-networkd
    

    Einmal durchstarten

    reboot
    

    Danach müßte der Tunnel wg0 automatisch gestartet sein. Kontrollieren mit

    sudo wg
    

    Ausgabe:

    root@rockpro64:~# wg
    interface: wg0
      public key: WU2zYy8EcQvGT2SlqcbY8O8DN1o28TlOT/9yS1+tcAk=
      private key: (hidden)
      listening port: 34774
    
    peer: gqiCgt5+X3na+wZ1e9gnR1pTujFO3jIudnwDIttDPEo=
      endpoint: 192.168.3.208:53984
      allowed ips: 192.168.10.1/32
      latest handshake: 9 minutes, 49 seconds ago
      transfer: 1.28 KiB received, 1.30 KiB sent
    

    Tunnel testen mit

    root@rockpro64:~# ping 192.168.10.1
    PING 192.168.10.1 (192.168.10.1) 56(84) bytes of data.
    64 bytes from 192.168.10.1: icmp_seq=1 ttl=64 time=14.4 ms
    64 bytes from 192.168.10.1: icmp_seq=2 ttl=64 time=2.82 ms
    
    --- 192.168.10.1 ping statistics ---
    2 packets transmitted, 2 received, 0% packet loss, time 1002ms
    rtt min/avg/max/mdev = 2.828/8.662/14.497/5.835 ms
    

    Den Daemon von systemd kontrollieren

    root@rockpro64:~# networkctl status wg0
    ● 4: wg0
           Link File: /lib/systemd/network/99-default.link
        Network File: /etc/systemd/network/wg0.network
                Type: none
               State: routable (configured)
             Address: 192.168.10.2
    
  • Etwas schnellerer Weg den Tunnel aufzubauen, Voraussetzung

    • wireguard modul installiert
    • Keys erzeugt

    Danach dann einfach

    ip link add wg0 type wireguard
    wg setconf wg0 /etc/wireguard/wg0.conf
    

    Datei /etc/wireguard/wg0.conf

    [Interface]
    PrivateKey = <Private Key>
    ListenPort = 60563
    
    [Peer]
    PublicKey = <Public Key Ziel>
    Endpoint = <IPv4 Adresse Zielrechner>:58380
    AllowedIPs = 10.10.0.1/32
    

    Die Rechte der Dateien von wireguard müssen eingeschränkt werden.

    sudo chmod 0600 /etc/wireguard/wg0.conf
    

    Das ganze per rc.local beim Booten laden. Datei /root/wireguard_start.sh

    ###############################################################################################
    #       Autor: Frank Mankel
    #       Startup-Script
    #       Wireguard
    #       Kontakt: frank.mankel@gmail.com
    #
    ###############################################################################################
    
    ip link add wg0 type wireguard
    ip address add dev wg0 10.10.0.1/8
    wg setconf wg0 /etc/wireguard/wg0.conf
    ip link set up dev wg0
    

    Danach Datei ausführbar machen

    chmod +x /root/wireguard_start.sh
    

    In rc.local

    /root/wireguard_start.sh
    

    eintragen - Fertig!

  • 0 Stimmen
    9 Beiträge
    362 Aufrufe
    FrankMF

    Ergänzt um eine automatische Übernahme der Tags aus dem Forum. Man muss den Beiträgen in Mastodon ja auch Reichweite geben 🙂

  • Debian 12 Bookworm released

    Linux
    5
    0 Stimmen
    5 Beiträge
    227 Aufrufe
    FrankMF

    Mein persönliches Fazit, alles läuft rund mit Debian Bookworm 12 🙂

    Alle meine Hetzner VMs sind jetzt auf Bookworm 🤓 Ok, was schwer und zeitaufwendig war, war die Nextcloud Installation bzw. der ganze PHP-Server. Das ist echt jedes mal eine Herausforderung, aber auch dabei werde ich die letzten Jahre sicherer. Hier die Story zum Nextcloud Server

    Link Preview Image Nextcloud - Upgrade auf Bookworm 12

    Mein Debian Server mit einer Nextcloud-Installation läuft noch auf Debian 11. Das möchte ich gerne ändern, wie ich aber letzte Woche lernen musste, ist das g...

    favicon

    linux-nerds.org (linux-nerds.org)

    Richtig rund lief das Upgrade des NodeBB-Servers, war einfach und direkt auf Node18 hochgezogen.

    Link Preview Image NodeBB - Upgrade auf Debian Bookworm 12

    Heute mal den Server für meine NodeBB-Foren auf Debian Bookworm 12 upgegraded. Ehrlich gesagt, das war langweilig........ Erster Schritt, kontrolliert ob De...

    favicon

    linux-nerds.org (linux-nerds.org)

    Damit ist jetzt alles hier auf Debian Bookworm 12

    Haupt-PC VMs bei Hetzner VMs in der Proxmox

    Oh, da fällt mir gerade ein, der Proxmox ist noch fällig. Aber, dazu habe ich mir was einfallen lassen, da ist noch ein neues Mainboard unterwegs und dann gibt es dazu einen etwas größeren Beitrag.

    Danke Debian-Team, Debian Bookworm 12 ist eine runde Sache!

    Spannend wird jetzt, wie lange ich auf meinem Haupt-PC (Bookworm, KDE, Wayland) bleibe. Ich habe da so eine unangenehme Eigenschaft, wenn es um veraltete Pakete geht. Diesmal werde ich dann wahrscheinlich auf den Debian Unstable Zweig (sid) wechseln. Aber das dürfte noch was dauern, da ja aktuell erst mal alles passt.

  • Wireguard - wg-quick

    Wireguard
    1
    0 Stimmen
    1 Beiträge
    954 Aufrufe
    Niemand hat geantwortet
  • Restic - forget --keep-last 3 --prune

    Restic
    2
    0 Stimmen
    2 Beiträge
    578 Aufrufe
    FrankMF

    Ich habe mich damit noch ein wenig beschäftigt, die letzten drei zu behalten, ist nicht so optimal. Da es viele Optionen bei dem Befehl gibt, hier ein Ausschnitt

    Flags: -l, --keep-last n keep the last n snapshots -H, --keep-hourly n keep the last n hourly snapshots -d, --keep-daily n keep the last n daily snapshots -w, --keep-weekly n keep the last n weekly snapshots -m, --keep-monthly n keep the last n monthly snapshots -y, --keep-yearly n keep the last n yearly snapshots

    habe ich das ein wenig so angepasst, das ich denke es passt für mich.

    restic --password-file /root/passwd -r /media/NAS_neu/Restic/Home/ forget --keep-last 3 --keep-monthly 3 --prune

    Damit behalte ich auch die jeweils eines pro Monat. Und die letzten drei. Das sieht dann so aus.

    root@debian:~# ./backup2.sh repository 2f3f6147 opened successfully, password is correct Files: 38 new, 100 changed, 13268 unmodified Dirs: 0 new, 1 changed, 0 unmodified Added to the repo: 10.166 GiB processed 13406 files, 50.324 GiB in 3:24 snapshot 849f614c saved repository 2f3f6147 opened successfully, password is correct Applying Policy: keep the last 3 snapshots, 3 monthly snapshots snapshots for (host [debian], paths [/home/frank]): keep 5 snapshots: ID Time Host Tags Reasons Paths ------------------------------------------------------------------------------------ a7251cfd 2019-11-28 17:00:01 debian monthly snapshot /home/frank 283d4027 2019-12-31 17:00:01 debian monthly snapshot /home/frank ae2b96ec 2020-01-01 21:47:46 debian last snapshot /home/frank 079e00a6 2020-01-02 17:00:01 debian last snapshot /home/frank 849f614c 2020-01-03 21:08:45 debian last snapshot /home/frank monthly snapshot ------------------------------------------------------------------------------------ 5 snapshots remove 26 snapshots: ID Time Host Tags Paths ------------------------------------------------------------------ 896f16c2 2019-11-07 22:23:40 debian /home/frank b21bcf6d 2019-11-11 17:00:01 debian /home/frank f89248fb 2019-11-12 17:00:01 debian /home/frank 123ab546 2019-11-13 17:00:01 debian /home/frank b82d87d0 2019-11-18 17:00:01 debian /home/frank 040b0ab7 2019-11-19 17:00:01 debian /home/frank 7221d8ef 2019-11-20 17:00:01 debian /home/frank 84132a25 2019-11-21 17:00:01 debian /home/frank b558a52c 2019-11-25 17:00:01 debian /home/frank e5cc0c3e 2019-12-02 17:00:01 debian /home/frank 22423fa5 2019-12-03 17:00:01 debian /home/frank 39df1ab9 2019-12-04 17:00:01 debian /home/frank 98843457 2019-12-05 17:00:01 debian /home/frank b0cdd4b6 2019-12-09 17:00:01 debian /home/frank 828414f9 2019-12-10 17:00:01 debian /home/frank e34a27c3 2019-12-11 17:00:01 debian /home/frank 6e488c3b 2019-12-12 17:00:01 debian /home/frank 17898403 2019-12-16 17:00:01 debian /home/frank 1973305a 2019-12-17 17:00:01 debian /home/frank 9553bedd 2019-12-18 17:00:01 debian /home/frank fedf749d 2019-12-19 17:00:01 debian /home/frank 8e7cb876 2019-12-23 17:00:01 debian /home/frank 0bd0d102 2019-12-25 17:00:01 debian /home/frank 13d348b0 2019-12-26 17:00:01 debian /home/frank c7d960aa 2019-12-30 17:00:01 debian /home/frank f6ea9118 2020-01-01 17:00:01 debian /home/frank ------------------------------------------------------------------ 26 snapshots 26 snapshots have been removed, running prune counting files in repo building new index for repo [0:35] 100.00% 7806 / 7806 packs repository contains 7806 packs (46537 blobs) with 41.110 GiB processed 46537 blobs: 0 duplicate blobs, 0 B duplicate load all snapshots find data that is still in use for 5 snapshots [0:01] 100.00% 5 / 5 snapshots found 32654 of 46537 data blobs still in use, removing 13883 blobs will remove 0 invalid files will delete 715 packs and rewrite 752 packs, this frees 5.027 GiB [2:28] 100.00% 752 / 752 packs rewritten counting files in repo [0:01] 100.00% 6571 / 6571 packs finding old index files saved new indexes as [d137b425 f7caee99 a6e9711a] remove 35 old index files [1:13] 100.00% 1467 / 1467 packs deleted done using temporary cache in /tmp/restic-check-cache-916655151 repository 2f3f6147 opened successfully, password is correct created new cache in /tmp/restic-check-cache-916655151 create exclusive lock for repository load indexes check all packs check snapshots, trees and blobs read all data [7:47] 100.00% 6571 / 6571 items duration: 7:47 no errors were found root@debian:~#

    Am Ende seht ihr noch, wie Restic alle Files testet. Mein Script sieht jetzt so aus.

    #!/bin/bash # Script um mit Restic Daten automatisiert zu sichern! # Dient zum Sichern der Homepartition auf dem ROCKPro64 NAS! # Was soll gesichert werden? backup_pfad=/home/frank # Programm Start restic --password-file /root/passwd -r /media/NAS_neu/Restic/Home/ backup $backup_pfad --exclude-file=excludes.txt restic --password-file /root/passwd -r /media/NAS_neu/Restic/Home/ forget --keep-last 3 --keep-monthly 3 --prune # Testen restic --password-file /root/passwd -r /media/NAS_neu/Restic/Home/ check --read-data

    Das dann schön mit einem Cronjob laufen lassen und die Datensicherung ist erledigt 😉

  • Mainline 5.4.x

    Images
    2
    0 Stimmen
    2 Beiträge
    332 Aufrufe
    FrankMF

    Bootet bei mir weder von USB3-SSD noch von SD-Karte.

    USB3-SSD -> https://pastebin.com/QAS92sme
    SD-Karte -> https://pastebin.com/Bsr3WLJ7

  • Wireguard - Traffic routen

    Wireguard
    2
    0 Stimmen
    2 Beiträge
    1k Aufrufe
    FrankMF

    Wie ich bei meinem Hamburger Systemadministrator gelernt habe, geht das auch wesentlich einfacher. Dafür hat Wireguard einen netten Befehl schon parat, nennt sich

    wg-quick up wg0-client

    Dazu muss auf dem Client natürlich vorher alles konfiguriert sein. Das Verzeichnis /etc/wireguard sieht dann so aus.

    root@thinkpad:/etc/wireguard# ls -lha /etc/wireguard/ insgesamt 32K drwx------ 2 root root 4,0K Aug 16 08:47 . drwxr-xr-x 141 root root 12K Aug 16 08:47 .. -rw-r--r-- 1 root root 45 Aug 9 16:48 private.key -rw-r--r-- 1 root root 45 Aug 9 16:48 psk.key -rw-r--r-- 1 root root 45 Aug 9 16:48 public.key -rw-r--r-- 1 root root 275 Aug 16 08:47 wg0-client.conf

    Die drei Schlüssel sind also vorhanden, der Server ist auch entsprechend vorbereitet. Dann brauchen wir auf dem Clienten noch die wg0-client.conf mit folgendem Inhalt.

    [Interface] Address = 10.10.0.4/32 PrivateKey = oM9jWxxxxxxxxxxxxxxxxxxxxxxxxxxxtS4vW8= ListenPort = 50xxx DNS = 10.10.0.2 [Peer] PublicKey = fGg7MxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxTPRqqzU= Endpoint = 136.xxx.xxx.xxx:60xxx AllowedIPs = 0.0.0.0/0 PersistentKeepalive = 21

    Im ersten Teil [Interface] wird die Schnittstelle auf dem Clienten konfiguriert.

    Die Adresse des Clienten Privatekey, findet man in /etc/wireguard/private.key Den Port für die Wireguard Kommunikation, frei wählbar. Der DNS-Server, ist hier mein Wireguard-Server, der einen DNS Dienst bereit hält.

    Im zweiten Teil [Peer] wird die Verbindung zum Server konfiguriert.

    PublicKey, der PublicKey des Servers. Endpoint, ist die IP-Adresse des Servers. AllowedIPs 0.0.0./0 wird den gesamten IPv4 Verkehr über den Tunnel routen. Dient dazu , die Verbindung aufrecht zu erhalten?

    Mit

    wg-quick up wg0-client

    baut er nun die Verbindung auf.

    root@thinkpad:/etc/wireguard# wg-quick up wg0-client [#] ip link add wg0-client type wireguard [#] wg setconf wg0-client /dev/fd/63 [#] ip -4 address add 10.10.0.4/32 dev wg0-client [#] ip link set mtu 1420 up dev wg0-client [#] resolvconf -a tun.wg0-client -m 0 -x [#] wg set wg0-client fwmark 51xxx [#] ip -4 route add 0.0.0.0/0 dev wg0-client table 51xxx [#] ip -4 rule add not fwmark 51xxx table 51xxx [#] ip -4 rule add table main suppress_prefixlength 0 root@thinkpad:/etc/wireguard#

    Damit steht der Tunnel

    9: wg0-client: <POINTOPOINT,NOARP,UP,LOWER_UP> mtu 1420 qdisc noqueue state UNKNOWN group default qlen 1000 link/none inet 10.10.0.4/32 scope global wg0-client valid_lft forever preferred_lft forever

    Ausschalten

    root@thinkpad:/etc/wireguard# wg-quick down wg0-client [#] ip -4 rule delete table 51xxx [#] ip -4 rule delete table main suppress_prefixlength 0 [#] ip link delete dev wg0-client [#] resolvconf -d tun.wg0-client

    Auf meinem Debian 10 Buster ging das erst so nicht, weil ein Paket fehlt.

    root@thinkpad:/etc/wireguard# wg-quick up wg0-client [#] ip link add wg0-client type wireguard [#] wg setconf wg0-client /dev/fd/63 [#] ip -4 address add 10.10.0.4/32 dev wg0-client [#] ip link set mtu 1420 up dev wg0-client [#] resolvconf -a wg0-client -m 0 -x /usr/bin/wg-quick: line 31: resolvconf: command not found [#] ip link delete dev wg0-client

    Wireguard ist so nett und schreibt alles rein 😉 Eine Installation von resolcconf löst das Problem.

    root@thinkpad:/etc/wireguard# apt install resolvconf Paketlisten werden gelesen... Fertig Abhängigkeitsbaum wird aufgebaut. Statusinformationen werden eingelesen.... Fertig Die folgenden NEUEN Pakete werden installiert: resolvconf 0 aktualisiert, 1 neu installiert, 0 zu entfernen und 0 nicht aktualisiert. Es müssen 74,2 kB an Archiven heruntergeladen werden. Nach dieser Operation werden 196 kB Plattenplatz zusätzlich benutzt. [gekürzt]

    Nun kann man den Tunnel mit zwei einfachen Befehlen auf- und wieder abbauen. Als nächstes kommt dann noch die IPv6 Erweiterung, weil im Moment IPv6 Traffic am Tunnel vorbei fliessen würde, wenn man eine öffentliche IPv6 Adresse zugewiesen bekommen hätte. Aber, das muss ich mir noch ein wenig erklären lassen 🙂

  • Wireguard - VPN Server

    Wireguard
    2
    0 Stimmen
    2 Beiträge
    479 Aufrufe
    FrankMF

    Das DNS-Problem ist gelöst. Da die Erklärung was umfangreicher ist, wird das heute nichts mehr. Genug getippt für heute 😁

  • ROCKPro64 - USB-C -> LAN

    ROCKPro64
    1
    0 Stimmen
    1 Beiträge
    277 Aufrufe
    Niemand hat geantwortet