Wiregard: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
(2 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 = | ||
Zeile 14: | Zeile 14: | ||
sysctl -p | sysctl -p | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== WireGuard UI Startscript erstellen == | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
SCRIPT_START=/etc/wireguard/start-wgui.sh | SCRIPT_START=/etc/wireguard/start-wgui.sh | ||
Zeile 23: | Zeile 24: | ||
EOF | EOF | ||
chmod +x $SCRIPT_START | chmod +x $SCRIPT_START | ||
</syntaxhighlight> | |||
== WireGuard UI == | |||
<syntaxhighlight lang="bash"> | |||
SERVICE=/etc/systemd/system/wgui-web.service | SERVICE=/etc/systemd/system/wgui-web.service | ||
cat <<EOF > $SERVICE | cat <<EOF > $SERVICE | ||
Zeile 36: | Zeile 39: | ||
WantedBy=multi-user.target | WantedBy=multi-user.target | ||
EOF | EOF | ||
</syntaxhighlight> | |||
== WireGuard UI Download und Update Script == | |||
<syntaxhighlight lang="bash"> | |||
SCRIPT_UPDATE=/etc/wireguard/update.sh | SCRIPT_UPDATE=/etc/wireguard/update.sh | ||
cat <<EOF > $SCRIPT_UPDATE | cat <<EOF > $SCRIPT_UPDATE | ||
Zeile 105: | Zeile 109: | ||
<pre>iptables -A FORWARD -i %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE | <pre>iptables -A FORWARD -i %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE | ||
</pre> | </pre> | ||
* Post Down Script: | |||
<pre>iptables -D FORWARD -i %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE | <pre>iptables -D FORWARD -i %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE | ||
</pre> | </pre> | ||
* Wireguard Clients | * Wireguard Clients | ||
** neue Clients eintragen | ** 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