forked from psyhomb/wireguard-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwgcg-install-wireguard.sh
executable file
·59 lines (48 loc) · 1.64 KB
/
wgcg-install-wireguard.sh
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
# Author: Milos Buncic
# Date: 2019/10/01
# Description: Prepare Wireguard server
set -e
echo "Installing Wireguard and required dependencies on the server, please wait..."
echo
# Installing wireguard kernel module and required dependencies
# DEPRECATION NOTICE: WireGuard packages have now moved into official Ubuntu repository (Ubuntu 20.04, 19.10, 18.04, and 16.04)
#add-apt-repository ppa:wireguard/wireguard
apt-get update && apt-get install -y linux-headers-$(uname -r) wireguard
mkdir -p /etc/wireguard
# Allow module to be loaded at boot time
echo wireguard > /etc/modules-load.d/wgcg.conf
# Load the module
echo -e "\nLoading module..."
echo -e "NOTE: If error encountered please try upgrading the Linux kernel to the latest version available and reboot\n"
modprobe -v wireguard
### Generate wgfw.sh script - will be used for adding required firewall rules
cat > /usr/local/bin/wgfw.sh <<EOF && chmod +x /usr/local/bin/wgfw.sh
#!/bin/bash
# Author: Milos Buncic
# Date: 2019/09/25
# Description: Add required Wireguard firewall rules
# Local private interface
PRIVATE_INTERFACE="$(ip a | awk -F'[ :]' '/^2:/ {print $3}')"
rules() {
local action=\${1}
iptables -t nat \${action} POSTROUTING -o \${PRIVATE_INTERFACE} -j MASQUERADE
}
case \${1} in
'add')
echo 1 > /proc/sys/net/ipv4/ip_forward
rules -A
;;
'del')
rules -D
echo 0 > /proc/sys/net/ipv4/ip_forward
;;
*)
echo "Usage: \$(basename \${0}) add|del"
esac
EOF
### Enable permanent IP forwarding (routing)
#cat > /etc/sysctl.d/10-wgcg.conf <<'EOF' && sysctl -p /etc/sysctl.d/10-wgcg.conf
## Enable IP forwarding (routing) - WireGuard
#net.ipv4.ip_forward = 1
#EOF