Browse Source

initial commit

Peter Cai 1 year ago
commit
e3941d3095
4 changed files with 46 additions and 0 deletions
  1. 2
    0
      .gitignore
  2. 0
    0
      ext/placeholder
  3. 13
    0
      wg-down.sh
  4. 31
    0
      wg-up.sh

+ 2
- 0
.gitignore View File

@@ -0,0 +1,2 @@
1
+ext/*
2
+!ext/placeholder

+ 0
- 0
ext/placeholder View File


+ 13
- 0
wg-down.sh View File

@@ -0,0 +1,13 @@
1
+#!/bin/bash
2
+CONFIG_NAME="$1"
3
+#DEV_NAME="$2"
4
+source /home/peter/wg/ext/$CONFIG_NAME.conf
5
+
6
+#ip netns exec $CONFIG_NAME ip link del dev $DEV_NAME
7
+#ip netns exec $CONFIG_NAME wg-quick down $CONFIG_NAME
8
+if $PRIVATE_VETH_ENABLED; then
9
+  ip netns exec $CONFIG_NAME ip link del dev "$CONFIG_NAME"1
10
+  ip link del dev "$CONFIG_NAME"0
11
+fi
12
+ip netns del $CONFIG_NAME
13
+

+ 31
- 0
wg-up.sh View File

@@ -0,0 +1,31 @@
1
+#!/bin/bash
2
+CONFIG_NAME="$1"
3
+DEV_NAME="wg-$CONFIG_NAME"
4
+source /home/peter/wg/ext/$CONFIG_NAME.conf
5
+
6
+ip netns add $CONFIG_NAME
7
+ip netns exec $CONFIG_NAME ip link set lo up
8
+ip link add dev $DEV_NAME type wireguard
9
+wg setconf $DEV_NAME /etc/wireguard/$CONFIG_NAME.conf
10
+ip link set $DEV_NAME netns $CONFIG_NAME up
11
+addrs=$(grep -oP "#Address = \K(.*)" /etc/wireguard/$CONFIG_NAME.conf)
12
+IFS=", "; for addr in $addrs; do
13
+  if [[ $addr = *":"* ]]; then
14
+    # IPv6
15
+    ip netns exec $CONFIG_NAME ip -6 addr add $addr dev $DEV_NAME
16
+  else
17
+    # IPv4
18
+    ip netns exec $CONFIG_NAME ip addr add $addr dev $DEV_NAME
19
+  fi
20
+done
21
+
22
+if $PRIVATE_VETH_ENABLED; then
23
+  ip link add dev "$CONFIG_NAME"0 type veth peer name "$CONFIG_NAME"1
24
+  ip link set "$CONFIG_NAME"0 up
25
+  ip link set "$CONFIG_NAME"1 netns $CONFIG_NAME up
26
+  ip addr add $PRIVATE_ADDRESS_HOST dev "$CONFIG_NAME"0
27
+  ip netns exec $CONFIG_NAME ip addr add $PRIVATE_ADDRESS_CLIENT dev "$CONFIG_NAME"1
28
+fi
29
+ip netns exec $CONFIG_NAME ip route add default dev $DEV_NAME
30
+ip netns exec $CONFIG_NAME ip -6 route add default dev $DEV_NAME
31
+

Loading…
Cancel
Save