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…“) |
|||
Zeile 4: | Zeile 4: | ||
= 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> | |||
<syntaxhighlight lang="bash"> | |||
SCRIPT_SERVICE=/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 | |||
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 | |||
# === Nun legen wir das WireGuard UI Download und Update Script an. | |||
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 | |||
= Fehlersuche = | = Fehlersuche = |
Version vom 31. März 2023, 17:14 Uhr
Links
Installation
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
SCRIPT_SERVICE=/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
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
# === Nun legen wir das WireGuard UI Download und Update Script an.
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
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
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
- 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
Fehlersuche
Test, ob Ping-Pakete ankommen
- Auf dem Server:
tcpdump icmp -i wg0