-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwg-netns-remove
executable file
·40 lines (31 loc) · 1.14 KB
/
wg-netns-remove
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash
#
# Author: Max Idermark
# GitHub Repo: https://github.com/Accelerox/wireguard-namespace
#
# This script removes all WireGuard VPN instances, their corresponding namespaces, and the bridge.
#
# Usage: ./wg-netns-remove
# Check if the script is run with sudo
if [[ $EUID -ne 0 ]]; then
echo "This script must be run with sudo"
exit 1
fi
# Get a list of all the VPN instances' namespaces
namespaces=$(ip netns list | grep -oP '^\w+(?=\s)')
# Remove all the VPN instances' namespaces and their corresponding folders
for ns in $namespaces; do
# Remove the namespace
ip netns del ${ns}
# Remove the bridge connection to the namespace
ip link del veth-nsbr-${ns}
# Remove the virtual Ethernet (veth) interfaces
ip link del veth-init-${ns}
# Remove the WireGuard interface from the default/init namespace (auto done)
#ip link del wg0-${ns}
# Remove the namespace folder
rm -rf /etc/netns/${ns}
echo "Removed namespace: ${ns}"
done
# Remove the bridge br0
nmcli connection delete bridge-br0