|
@@ -10,6 +10,9 @@
|
|
# Debian9 安装 WireGuard 步骤
|
|
# Debian9 安装 WireGuard 步骤
|
|
# 详细参考逗比 https://doub.io/wg-jc1/
|
|
# 详细参考逗比 https://doub.io/wg-jc1/
|
|
|
|
|
|
|
|
+
|
|
|
|
+debian_wireguard_install(){
|
|
|
|
+
|
|
# Debian 默认往往都没有 linux-headers 内核,而安装使用 WireGuard 必须要
|
|
# Debian 默认往往都没有 linux-headers 内核,而安装使用 WireGuard 必须要
|
|
|
|
|
|
# 更新软件包源
|
|
# 更新软件包源
|
|
@@ -25,10 +28,10 @@ dpkg -l|grep linux-headers
|
|
# 添加 unstable 软件包源,以确保安装版本是最新的
|
|
# 添加 unstable 软件包源,以确保安装版本是最新的
|
|
echo "deb http://deb.debian.org/debian/ unstable main" > /etc/apt/sources.list.d/unstable.list
|
|
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
|
|
printf 'Package: *\nPin: release a=unstable\nPin-Priority: 90\n' > /etc/apt/preferences.d/limit-unstable
|
|
-
|
|
|
|
|
|
+
|
|
# 更新一下软件包源
|
|
# 更新一下软件包源
|
|
apt update
|
|
apt update
|
|
-
|
|
|
|
|
|
+
|
|
# 开始安装 WireGuard ,和辅助库 resolvconf
|
|
# 开始安装 WireGuard ,和辅助库 resolvconf
|
|
apt install wireguard resolvconf -y
|
|
apt install wireguard resolvconf -y
|
|
|
|
|
|
@@ -54,7 +57,7 @@ echo "[Interface]
|
|
PrivateKey = $(cat sprivatekey)
|
|
PrivateKey = $(cat sprivatekey)
|
|
|
|
|
|
# VPN中本机的内网IP,一般默认即可,除非和你服务器或客户端设备本地网段冲突
|
|
# VPN中本机的内网IP,一般默认即可,除非和你服务器或客户端设备本地网段冲突
|
|
-Address = 10.0.0.1/24
|
|
|
|
|
|
+Address = 10.0.0.1/24
|
|
|
|
|
|
# 运行 WireGuard 时要执行的 iptables 防火墙规则,用于打开NAT转发之类的。
|
|
# 运行 WireGuard 时要执行的 iptables 防火墙规则,用于打开NAT转发之类的。
|
|
# 如果你的服务器主网卡名称不是 eth0 ,那么请修改下面防火墙规则中最后的 eth0 为你的主网卡名称。
|
|
# 如果你的服务器主网卡名称不是 eth0 ,那么请修改下面防火墙规则中最后的 eth0 为你的主网卡名称。
|
|
@@ -119,7 +122,7 @@ PersistentKeepalive = 25"|sed '/^#/d;/^\s*$/d' > client.conf
|
|
|
|
|
|
# 赋予配置文件夹权限
|
|
# 赋予配置文件夹权限
|
|
chmod 777 -R /etc/wireguard
|
|
chmod 777 -R /etc/wireguard
|
|
-
|
|
|
|
|
|
+
|
|
sysctl_config() {
|
|
sysctl_config() {
|
|
sed -i '/net.core.default_qdisc/d' /etc/sysctl.conf
|
|
sed -i '/net.core.default_qdisc/d' /etc/sysctl.conf
|
|
sed -i '/net.ipv4.tcp_congestion_control/d' /etc/sysctl.conf
|
|
sed -i '/net.ipv4.tcp_congestion_control/d' /etc/sysctl.conf
|
|
@@ -131,7 +134,7 @@ sysctl_config() {
|
|
# 开启 BBR
|
|
# 开启 BBR
|
|
sysctl_config
|
|
sysctl_config
|
|
lsmod | grep bbr
|
|
lsmod | grep bbr
|
|
-
|
|
|
|
|
|
+
|
|
# 打开防火墙转发功能
|
|
# 打开防火墙转发功能
|
|
echo 1 > /proc/sys/net/ipv4/ip_forward
|
|
echo 1 > /proc/sys/net/ipv4/ip_forward
|
|
echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
|
|
echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
|
|
@@ -146,6 +149,12 @@ systemctl enable wg-quick@wg0
|
|
# 查询WireGuard状态
|
|
# 查询WireGuard状态
|
|
wg
|
|
wg
|
|
|
|
|
|
|
|
+# 以上配置文本只做参考文档使用,实际生成 WireGuard 多用户配置
|
|
|
|
+
|
|
|
|
+# 一键 WireGuard 多用户配置共享脚本
|
|
|
|
+wget -qO- https://git.io/fpnQt | bash
|
|
|
|
+
|
|
|
|
+}
|
|
# ======= 容错:检查系统,调用 Ubuntu Centos 系统对应安装脚本 ========
|
|
# ======= 容错:检查系统,调用 Ubuntu Centos 系统对应安装脚本 ========
|
|
check_sys(){
|
|
check_sys(){
|
|
if [[ -f /etc/redhat-release ]]; then
|
|
if [[ -f /etc/redhat-release ]]; then
|
|
@@ -168,8 +177,8 @@ check_sys(){
|
|
|
|
|
|
wireguard_config(){
|
|
wireguard_config(){
|
|
if [[ ${release} == "centos" ]]; then
|
|
if [[ ${release} == "centos" ]]; then
|
|
- yum install -y wget vim curl
|
|
|
|
- # CentOS 7 一键脚本安装WireGuard (官方脚本自动升级内核)
|
|
|
|
|
|
+ yum install -y wget vim curl
|
|
|
|
+ # CentOS 7 一键脚本安装WireGuard (官方脚本自动升级内核)
|
|
wget -qO- git.io/fhnhS | bash
|
|
wget -qO- git.io/fhnhS | bash
|
|
fi
|
|
fi
|
|
|
|
|
|
@@ -179,10 +188,9 @@ wireguard_config(){
|
|
fi
|
|
fi
|
|
|
|
|
|
if [[ ${release} == "debian" ]]; then
|
|
if [[ ${release} == "debian" ]]; then
|
|
- # 一键 WireGuard 多用户配置共享脚本
|
|
|
|
- wget -qO- https://git.io/fpnQt | bash
|
|
|
|
|
|
+ debian_wireguard_install
|
|
fi
|
|
fi
|
|
}
|
|
}
|
|
|
|
|
|
-# 以上配置文本只是参考文档使用,实际生成 WireGuard 多用户配置
|
|
|
|
|
|
+
|
|
check_sys && wireguard_config
|
|
check_sys && wireguard_config
|