Wiregard: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
(Die Seite wurde neu angelegt: „= Links = * https://adminforge.de/linux-allgemein/vpn/wireguard-vpn-server-mit-web-interface-einrichten/ * = Installation = = Fehlersuche = == Test, ob Ping…“) |
|||
(4 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) | |||
Zeile 1: | Zeile 1: | ||
= Links = | = Links = | ||
* https://adminforge.de/linux-allgemein/vpn/wireguard-vpn-server-mit-web-interface-einrichten/ | * https://adminforge.de/linux-allgemein/vpn/wireguard-vpn-server-mit-web-interface-einrichten/ | ||
* | * https://github.com/ngoduykhanh/wireguard-ui | ||
= Installation = | = Installation = | ||
<syntaxhighlight lang="bash"> | |||
apt update && apt install -y wireguard curl tar | |||
cd /etc/wireguard | |||
# Port öffnen: | |||
ufw allow 51820/udp | |||
# IP-forwarding: | |||
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf | |||
echo "net.ipv6.conf.all.forwarding=1" >> /etc/sysctl.conf | |||
sysctl -p | |||
</syntaxhighlight> | |||
== WireGuard UI Startscript erstellen == | |||
<syntaxhighlight lang="bash"> | |||
SCRIPT_START=/etc/wireguard/start-wgui.sh | |||
cat <<EOF > $SCRIPT_START | |||
#!/bin/bash | |||
cd /etc/wireguard | |||
./wireguard-ui -bind-address 0.0.0.0:5000 | |||
EOF | |||
chmod +x $SCRIPT_START | |||
</syntaxhighlight> | |||
== WireGuard UI == | |||
<syntaxhighlight lang="bash"> | |||
SERVICE=/etc/systemd/system/wgui-web.service | |||
cat <<EOF > $SERVICE | |||
[Unit] | |||
Description=WireGuard UI | |||
[Service] | |||
Type=simple | |||
ExecStart=$SCRIPT_START | |||
[Install] | |||
WantedBy=multi-user.target | |||
EOF | |||
</syntaxhighlight> | |||
== WireGuard UI Download und Update Script == | |||
<syntaxhighlight lang="bash"> | |||
SCRIPT_UPDATE=/etc/wireguard/update.sh | |||
cat <<EOF > $SCRIPT_UPDATE | |||
#!/bin/bash | |||
VER=\$(curl -sI https://github.com/ngoduykhanh/wireguard-ui/releases/latest | grep "location:" | cut -d "/" -f8 | tr -d '\r') | |||
echo "downloading wireguard-ui \$VER" | |||
curl -sL "https://github.com/ngoduykhanh/wireguard-ui/releases/download/\$VER/wireguard-ui-\$VER-linux-amd64.tar.gz" -o wireguard-ui-\$VER-linux-amd64.tar.gz | |||
echo -n "extracting "; tar xvf wireguard-ui-\$VER-linux-amd64.tar.gz | |||
echo "restarting wgui-web.service" | |||
systemctl restart wgui-web.service | |||
EOF | |||
chmod +x $SCRIPT_UPDATE | |||
# Ausführen | |||
cd /etc/wireguard ; ./update.sh | |||
</syntaxhighlight> | |||
* ACHTUNG: Die -bind-address 0.0.0.0:5000 sollte aus Sicherheitsgründen, sobald der erste Tunnel steht, gegen die WireGuard Server IP-Adresse 10.252.1.0 ausgetauscht werden! | |||
== WireGuard Konfigurationsdatei von Systemd überwachen lassen == | |||
<syntaxhighlight lang="bash"> | |||
WG_ID=wg0 | |||
cat <<EOF > /etc/systemd/system/wgui.service | |||
[Unit] | |||
Description=Restart WireGuard | |||
After=network.target | |||
[Service] | |||
Type=oneshot | |||
ExecStart=/bin/systemctl restart wg-quick@$WG_ID.service | |||
[Install] | |||
RequiredBy=wgui.path | |||
EOF | |||
cat <<EOF > /etc/systemd/system/wgui.path | |||
[Unit] | |||
Description=Watch /etc/wireguard/$WG_ID.conf for changes | |||
[Path] | |||
PathModified=/etc/wireguard/$WG_ID.conf | |||
[Install] | |||
WantedBy=multi-user.target | |||
EOF | |||
</syntaxhighlight> | |||
== Dienste aktivieren und starten == | |||
<syntaxhighlight lang="bash"> | |||
WG_ID=wg0 | |||
touch /etc/wireguard/wg0.conf | |||
systemctl enable wgui.{path,service} wg-quick@$WG_ID.service wgui-web.service | |||
systemctl start wgui.{path,service} | |||
</syntaxhighlight> | |||
== WireGuard UI öffnen und einstellen == | |||
* Im Browser: http://<server>:5000 | |||
* admin admin | |||
* Global Settings | |||
** Endpoint kontrollieren | |||
** DNS ersetzen: 1.1.1.1 durch 176.9.93.198, 176.9.1.117 | |||
* Wireguard Server | |||
** Post Up Script: Öffentliches Interface sei eth0: | |||
<pre>iptables -A FORWARD -i %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE | |||
</pre> | |||
* Post Down Script: | |||
<pre>iptables -D FORWARD -i %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE | |||
</pre> | |||
* Wireguard Clients | |||
** neue Clients eintragen | |||
= Linux-Client installieren = | |||
<syntaxhighlight lang="bash"> | |||
apt install wireguard-tools | |||
</syntaxhighlight> | |||
* Konfiguration von Server downloaden (mit wireguard-gui) oder selber erstellen: | |||
<syntaxhighlight lang="bash"> | |||
WG_ID=wg0 | |||
CONFIG=/etc/wireguard/$WG_ID.conf | |||
if [ -e $CONFIG ]; then | |||
echo "+++ $CONFIG already exists" | |||
else | |||
cat <EOS >$CONFIG | |||
[Interface] | |||
Address = 10.58.100.3/32 | |||
PrivateKey = IS_A_PRIVATE_KEYGXRXzAsIK4H3dzHXno= | |||
DNS = 176.9.93.198,176.9.1.117 | |||
MTU = 1450 | |||
FwMark = 0xca6c | |||
[Peer] | |||
PublicKey = /IS_ANY_VALUE_4jj/NfSYO7ROfGk4fVo6ei+YmgE= | |||
PresharedKey = kO19Y3S62g8Cw9Pfg7A57NZloqBlW9FpbWjzed10sjQ= | |||
AllowedIPs = 10.58.0.0/16 | |||
Endpoint = 207.180.255.91:51820 | |||
PersistentKeepalive = 15 | |||
EOS | |||
fi | |||
</syntaxhighlight> | |||
<syntaxhighlight lang="bash"> | |||
WG_ID=wg0 | |||
wg-quick up $WG_ID | |||
</syntaxhighlight> | |||
= Fehlersuche = | = Fehlersuche = |
Aktuelle Version vom 31. März 2023, 19:13 Uhr
Links[Bearbeiten]
- https://adminforge.de/linux-allgemein/vpn/wireguard-vpn-server-mit-web-interface-einrichten/
- https://github.com/ngoduykhanh/wireguard-ui
Installation[Bearbeiten]
apt update && apt install -y wireguard curl tar
cd /etc/wireguard
# Port öffnen:
ufw allow 51820/udp
# IP-forwarding:
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
echo "net.ipv6.conf.all.forwarding=1" >> /etc/sysctl.conf
sysctl -p
WireGuard UI Startscript erstellen[Bearbeiten]
SCRIPT_START=/etc/wireguard/start-wgui.sh
cat <<EOF > $SCRIPT_START
#!/bin/bash
cd /etc/wireguard
./wireguard-ui -bind-address 0.0.0.0:5000
EOF
chmod +x $SCRIPT_START
WireGuard UI[Bearbeiten]
SERVICE=/etc/systemd/system/wgui-web.service
cat <<EOF > $SERVICE
[Unit]
Description=WireGuard UI
[Service]
Type=simple
ExecStart=$SCRIPT_START
[Install]
WantedBy=multi-user.target
EOF
WireGuard UI Download und Update Script[Bearbeiten]
SCRIPT_UPDATE=/etc/wireguard/update.sh
cat <<EOF > $SCRIPT_UPDATE
#!/bin/bash
VER=\$(curl -sI https://github.com/ngoduykhanh/wireguard-ui/releases/latest | grep "location:" | cut -d "/" -f8 | tr -d '\r')
echo "downloading wireguard-ui \$VER"
curl -sL "https://github.com/ngoduykhanh/wireguard-ui/releases/download/\$VER/wireguard-ui-\$VER-linux-amd64.tar.gz" -o wireguard-ui-\$VER-linux-amd64.tar.gz
echo -n "extracting "; tar xvf wireguard-ui-\$VER-linux-amd64.tar.gz
echo "restarting wgui-web.service"
systemctl restart wgui-web.service
EOF
chmod +x $SCRIPT_UPDATE
# Ausführen
cd /etc/wireguard ; ./update.sh
- ACHTUNG: Die -bind-address 0.0.0.0:5000 sollte aus Sicherheitsgründen, sobald der erste Tunnel steht, gegen die WireGuard Server IP-Adresse 10.252.1.0 ausgetauscht werden!
WireGuard Konfigurationsdatei von Systemd überwachen lassen[Bearbeiten]
WG_ID=wg0
cat <<EOF > /etc/systemd/system/wgui.service
[Unit]
Description=Restart WireGuard
After=network.target
[Service]
Type=oneshot
ExecStart=/bin/systemctl restart wg-quick@$WG_ID.service
[Install]
RequiredBy=wgui.path
EOF
cat <<EOF > /etc/systemd/system/wgui.path
[Unit]
Description=Watch /etc/wireguard/$WG_ID.conf for changes
[Path]
PathModified=/etc/wireguard/$WG_ID.conf
[Install]
WantedBy=multi-user.target
EOF
Dienste aktivieren und starten[Bearbeiten]
WG_ID=wg0
touch /etc/wireguard/wg0.conf
systemctl enable wgui.{path,service} wg-quick@$WG_ID.service wgui-web.service
systemctl start wgui.{path,service}
WireGuard UI öffnen und einstellen[Bearbeiten]
- Im Browser: http://<server>:5000
- admin admin
- Global Settings
- Endpoint kontrollieren
- DNS ersetzen: 1.1.1.1 durch 176.9.93.198, 176.9.1.117
- Wireguard Server
- Post Up Script: Öffentliches Interface sei eth0:
iptables -A FORWARD -i %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
- Post Down Script:
iptables -D FORWARD -i %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
- Wireguard Clients
- neue Clients eintragen
Linux-Client installieren[Bearbeiten]
apt install wireguard-tools
- Konfiguration von Server downloaden (mit wireguard-gui) oder selber erstellen:
WG_ID=wg0
CONFIG=/etc/wireguard/$WG_ID.conf
if [ -e $CONFIG ]; then
echo "+++ $CONFIG already exists"
else
cat <EOS >$CONFIG
[Interface]
Address = 10.58.100.3/32
PrivateKey = IS_A_PRIVATE_KEYGXRXzAsIK4H3dzHXno=
DNS = 176.9.93.198,176.9.1.117
MTU = 1450
FwMark = 0xca6c
[Peer]
PublicKey = /IS_ANY_VALUE_4jj/NfSYO7ROfGk4fVo6ei+YmgE=
PresharedKey = kO19Y3S62g8Cw9Pfg7A57NZloqBlW9FpbWjzed10sjQ=
AllowedIPs = 10.58.0.0/16
Endpoint = 207.180.255.91:51820
PersistentKeepalive = 15
EOS
fi
WG_ID=wg0
wg-quick up $WG_ID
Fehlersuche[Bearbeiten]
Test, ob Ping-Pakete ankommen[Bearbeiten]
- Auf dem Server:
tcpdump icmp -i wg0