|
@@ -1,30 +1,69 @@
|
|
#!/bin/bash
|
|
#!/bin/bash
|
|
-
|
|
|
|
-# wireguard-install
|
|
|
|
# WireGuard installer for Ubuntu 18.04 LTS, Debian 9 and CentOS 7.
|
|
# WireGuard installer for Ubuntu 18.04 LTS, Debian 9 and CentOS 7.
|
|
|
|
|
|
-# This script will let you setup your own VPN server in no more than a minute, even if you haven't used WireGuard before.
|
|
|
|
|
|
+# This script will let you setup your own VPN server in no more than a minute, even if you haven't used WireGuard before.
|
|
# It has been designed to be as unobtrusive and universal as possible.
|
|
# It has been designed to be as unobtrusive and universal as possible.
|
|
|
|
|
|
|
|
+# wireguard-install
|
|
|
|
+wireguard_install(){
|
|
|
|
+ if [ -e /etc/centos-release ]; then
|
|
|
|
+ DISTRO="CentOS"
|
|
|
|
+ elif [ -e /etc/debian_version ]; then
|
|
|
|
+ DISTRO=$( lsb_release -is )
|
|
|
|
+ else
|
|
|
|
+ echo "Your distribution is not supported (yet)"
|
|
|
|
+ exit
|
|
|
|
+ fi
|
|
|
|
|
|
-# 一键安装wireguard 脚本
|
|
|
|
-wget -qO- git.io/fptwc | bash
|
|
|
|
|
|
+ if [ "$DISTRO" == "Ubuntu" ]; then
|
|
|
|
+ apt update
|
|
|
|
+ apt install software-properties-common -y
|
|
|
|
+ echo .read | add-apt-repository ppa:wireguard/wireguard
|
|
|
|
+ apt update
|
|
|
|
+ apt install wireguard resolvconf qrencode -y
|
|
|
|
+
|
|
|
|
+ elif [ "$DISTRO" == "Debian" ]; then
|
|
|
|
+ echo "deb http://deb.debian.org/debian/ unstable main" > /etc/apt/sources.list.d/unstable.list
|
|
|
|
+ printf 'Package: *\nPin: release a=unstable\nPin-Priority: 90\n' > /etc/apt/preferences.d/limit-unstable
|
|
|
|
+ apt update
|
|
|
|
+ apt install wireguard resolvconf qrencode -y
|
|
|
|
+
|
|
|
|
+ elif [ "$DISTRO" == "CentOS" ]; then
|
|
|
|
+ curl -Lo /etc/yum.repos.d/wireguard.repo https://copr.fedorainfracloud.org/coprs/jdoss/wireguard/repo/epel-7/jdoss-wireguard-epel-7.repo
|
|
|
|
+ yum install -y epel-release
|
|
|
|
+ yum install -y wireguard-dkms wireguard-tools
|
|
|
|
+ yum -y install qrencode iptables-services
|
|
|
|
+
|
|
|
|
+ systemctl stop firewalld && systemctl disable firewalld
|
|
|
|
+ systemctl enable iptables && systemctl start iptables
|
|
|
|
+ iptables -F && service iptables save && service iptables restart
|
|
|
|
|
|
|
|
+ fi
|
|
|
|
+
|
|
|
|
+ mkdir -p /etc/wireguard
|
|
|
|
+ cd /etc/wireguard
|
|
|
|
+ wg genkey | tee sprivatekey | wg pubkey > spublickey
|
|
|
|
+ wg genkey | tee cprivatekey | wg pubkey > cpublickey
|
|
|
|
+ chmod 777 -R /etc/wireguard
|
|
|
|
+ systemctl enable wg-quick@wg0
|
|
|
|
+}
|
|
|
|
|
|
-# WireGuard VPN多用户服务端 自动配置脚本 支持IPV6
|
|
|
|
|
|
+if [ ! -f '/usr/bin/wg' ]; then
|
|
|
|
+ wireguard_install
|
|
|
|
+fi
|
|
|
|
|
|
|
|
+# WireGuard VPN Multi-user Configuration Script, Support IPV6
|
|
#############################################################
|
|
#############################################################
|
|
-
|
|
|
|
let port=$RANDOM/2+9999
|
|
let port=$RANDOM/2+9999
|
|
mtu=1420
|
|
mtu=1420
|
|
ip_list=(2 5 8 178 186 118 158 198 168 9)
|
|
ip_list=(2 5 8 178 186 118 158 198 168 9)
|
|
ipv6_range="fd08:620c:4df0:65eb::"
|
|
ipv6_range="fd08:620c:4df0:65eb::"
|
|
|
|
|
|
|
|
|
|
-# 安装 bash wgmtu 脚本用来设置服务器
|
|
|
|
|
|
+# Get WireGuard Management Command : bash wgmtu
|
|
wget -O ~/wgmtu https://raw.githubusercontent.com/hongwenjun/vps_setup/english/wgmtu.sh
|
|
wget -O ~/wgmtu https://raw.githubusercontent.com/hongwenjun/vps_setup/english/wgmtu.sh
|
|
|
|
|
|
-# 定义文字颜色
|
|
|
|
|
|
+# 瀹氫箟鏂囧瓧棰滆壊
|
|
Green="\033[32m" && Red="\033[31m" && GreenBG="\033[42;37m" && RedBG="\033[41;37m"
|
|
Green="\033[32m" && Red="\033[31m" && GreenBG="\033[42;37m" && RedBG="\033[41;37m"
|
|
Font="\033[0m" && Yellow="\033[0;33m" && SkyBlue="\033[0;36m"
|
|
Font="\033[0m" && Yellow="\033[0;33m" && SkyBlue="\033[0;36m"
|
|
|
|
|
|
@@ -51,7 +90,7 @@ if [[ $# > 0 ]]; then
|
|
fi
|
|
fi
|
|
|
|
|
|
host=$(hostname -s)
|
|
host=$(hostname -s)
|
|
-# 获得服务器ip,自动获取
|
|
|
|
|
|
+# 鑾峰緱鏈嶅姟鍣╥p锛岃嚜鍔ㄨ幏鍙�
|
|
if [ ! -f '/usr/bin/curl' ]; then
|
|
if [ ! -f '/usr/bin/curl' ]; then
|
|
apt update && apt install -y curl
|
|
apt update && apt install -y curl
|
|
fi
|
|
fi
|
|
@@ -61,14 +100,9 @@ if [ ! -e '/var/ip_addr' ]; then
|
|
fi
|
|
fi
|
|
serverip=$(cat /var/ip_addr)
|
|
serverip=$(cat /var/ip_addr)
|
|
|
|
|
|
-# 安装二维码插件
|
|
|
|
-if [ ! -f '/usr/bin/qrencode' ]; then
|
|
|
|
- apt -y install qrencode
|
|
|
|
-fi
|
|
|
|
-
|
|
|
|
#############################################################
|
|
#############################################################
|
|
|
|
|
|
-# 打开ip4/ipv6防火墙转发功能
|
|
|
|
|
|
+# 鎵撳紑ip4/ipv6闃茬伀澧欒浆鍙戝姛鑳�
|
|
sysctl_config() {
|
|
sysctl_config() {
|
|
sed -i '/net.ipv4.ip_forward/d' /etc/sysctl.conf
|
|
sed -i '/net.ipv4.ip_forward/d' /etc/sysctl.conf
|
|
sed -i '/net.ipv6.conf.all.forwarding/d' /etc/sysctl.conf
|
|
sed -i '/net.ipv6.conf.all.forwarding/d' /etc/sysctl.conf
|
|
@@ -82,16 +116,16 @@ sysctl_config() {
|
|
}
|
|
}
|
|
sysctl_config
|
|
sysctl_config
|
|
|
|
|
|
-# wg配置文件目录 /etc/wireguard
|
|
|
|
|
|
+# wg閰嶇疆鏂囦欢鐩�綍 /etc/wireguard
|
|
mkdir -p /etc/wireguard
|
|
mkdir -p /etc/wireguard
|
|
chmod 777 -R /etc/wireguard
|
|
chmod 777 -R /etc/wireguard
|
|
cd /etc/wireguard
|
|
cd /etc/wireguard
|
|
|
|
|
|
-# 然后开始生成 密匙对(公匙+私匙)。
|
|
|
|
|
|
+# 鐒跺悗寮€濮嬬敓鎴� 瀵嗗寵瀵�(鍏�寵+绉佸寵)銆�
|
|
wg genkey | tee sprivatekey | wg pubkey > spublickey
|
|
wg genkey | tee sprivatekey | wg pubkey > spublickey
|
|
wg genkey | tee cprivatekey | wg pubkey > cpublickey
|
|
wg genkey | tee cprivatekey | wg pubkey > cpublickey
|
|
|
|
|
|
-# 生成服务端配置文件
|
|
|
|
|
|
+# 鐢熸垚鏈嶅姟绔�厤缃�枃浠�
|
|
cat <<EOF >wg0.conf
|
|
cat <<EOF >wg0.conf
|
|
[Interface]
|
|
[Interface]
|
|
PrivateKey = $(cat sprivatekey)
|
|
PrivateKey = $(cat sprivatekey)
|
|
@@ -108,7 +142,7 @@ AllowedIPs = 10.0.0.188/32, ${ipv6_range}188
|
|
|
|
|
|
EOF
|
|
EOF
|
|
|
|
|
|
-# 生成简洁的客户端配置
|
|
|
|
|
|
+# 鐢熸垚绠€娲佺殑瀹㈡埛绔�厤缃�
|
|
cat <<EOF >client.conf
|
|
cat <<EOF >client.conf
|
|
[Interface]
|
|
[Interface]
|
|
PrivateKey = $(cat cprivatekey)
|
|
PrivateKey = $(cat cprivatekey)
|
|
@@ -126,7 +160,7 @@ PersistentKeepalive = 25
|
|
|
|
|
|
EOF
|
|
EOF
|
|
|
|
|
|
-# 添加 2-9 号多用户配置
|
|
|
|
|
|
+# 娣诲姞 2-9 鍙峰�鐢ㄦ埛閰嶇疆
|
|
for i in {2..9}
|
|
for i in {2..9}
|
|
do
|
|
do
|
|
ip=10.0.0.${ip_list[$i]}
|
|
ip=10.0.0.${ip_list[$i]}
|
|
@@ -157,20 +191,24 @@ EOF
|
|
done
|
|
done
|
|
|
|
|
|
|
|
|
|
-# 重启wg服务器
|
|
|
|
|
|
+# restart WG server
|
|
wg-quick down wg0
|
|
wg-quick down wg0
|
|
wg-quick up wg0
|
|
wg-quick up wg0
|
|
-
|
|
|
|
|
|
+wg
|
|
|
|
|
|
next() {
|
|
next() {
|
|
printf "# %-70s\n" "-" | sed 's/\s/-/g'
|
|
printf "# %-70s\n" "-" | sed 's/\s/-/g'
|
|
}
|
|
}
|
|
|
|
|
|
-echo -e "# Windows 客户端配置,请复制配置文本"
|
|
|
|
|
|
+echo
|
|
|
|
+echo_SkyBlue ":: Windows Client configuration, Please copy the conf text."
|
|
cat /etc/wireguard/client.conf && next
|
|
cat /etc/wireguard/client.conf && next
|
|
cat /etc/wireguard/wg_${host}_2.conf && next
|
|
cat /etc/wireguard/wg_${host}_2.conf && next
|
|
cat /etc/wireguard/wg_${host}_3.conf && next
|
|
cat /etc/wireguard/wg_${host}_3.conf && next
|
|
|
|
|
|
-echo_GreenBG "# WireGuard Management Command."
|
|
|
|
|
|
+echo_RedBG " One-Step Automated Install WireGuard Script For Debian_9 Ubuntu Centos_7 "
|
|
|
|
+echo_GreenBG " Open Source Project: https://github.com/hongwenjun/vps_setup "
|
|
|
|
+
|
|
|
|
+echo_Yellow ":: WireGuard Management Command."
|
|
echo_SkyBlue "Usage: ${GreenBG} bash wgmtu ${SkyBlue} [ setup | remove | vps | bench | -U ] "
|
|
echo_SkyBlue "Usage: ${GreenBG} bash wgmtu ${SkyBlue} [ setup | remove | vps | bench | -U ] "
|
|
-echo_SkyBlue " [ v2ray | vnstat | log | trace | -h ] "
|
|
|
|
|
|
+echo_SkyBlue " [ v2ray | vnstat | log | trace | -h ] "
|