-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwg-netns-stop
executable file
·39 lines (30 loc) · 1.1 KB
/
wg-netns-stop
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
#!/bin/bash
#
# Author: Max Idermark
# GitHub Repo: https://github.com/Accelerox/wireguard-namespace
#
# This script stops a WireGuard VPN instance and namespace with a given identifier.
# It removes the corresponding namespace, bridge connection, and virtual Ethernet (veth) interfaces.
#
# Usage: ./wg-netns-stop <identifier>
# Check if the script is run with sudo
if [[ $EUID -ne 0 ]]; then
echo "This script must be run with sudo"
exit 1
fi
if [[ $# -ne 1 ]]; then
echo "Usage: $0 <identifier>"
exit 1
fi
identifier=$1
# Remove the namespace
ip netns del ${identifier}
# Remove the bridge connection to the namespace
ip link del veth-nsbr-${identifier}
# Remove the virtual Ethernet (veth) interfaces
ip link del veth-init-${identifier}
# Remove the WireGuard interface from init namespace (auto removed, hence commented)
#ip link del wg0-${identifier}
# Remove the namespace folder
rm -rf /etc/netns/${identifier}
echo "Namespace and veth config for $identifier removed."