#!/bin/bash # 添加wireguard源 #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 -y qrencode curl iptables wireguard # 开启BBR LSBBR=$(sysctl net.ipv4.tcp_congestion_control) if [[ ${LSBBR} =~ "bbr" ]]; then echo "已开启BBR" else echo "正在开启BBR" echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf sysctl -p fi # 开启转发 IPNETF=$(cat /proc/sys/net/ipv4/ip_forward) if [[ ${IPNETF} -eq "1" ]]; then echo "已开启转发" else echo "正在开启转发" echo 1 > /proc/sys/net/ipv4/ip_forward sed -i 's/#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/g' /etc/sysctl.conf sysctl -p fi # 创建wireguard文件夹 WGMKDIR=/etc/wireguard if [[ ! -d ${WGMKDIR} ]]; then echo "正在创建wireguard文件夹" mkdir -p ${WGMKDIR} else echo "wireguard文件夹已创建" fi cd ${WGMKDIR} # Wireguard 生成密钥对 umask 077 && wg genkey | tee sprivate.key | wg pubkey > spublic.key umask 077 && wg genkey | tee cprivate.key | wg pubkey > cpublic.key umask 077 && wg genpsk > preshared.key # Wireguard服务器私钥 sprivatekey=$( /etc/wireguard/wg0.conf < /etc/wireguard/client.conf <