Wireguard 现在是非常流行啊,方便灵活的配置并且快速组建网络通道。

习惯了用Debian

首先当然是添加安装源了

add deb http://deb.debian.org/debian buster-backports main to sources.list

更新并安装几个主要的软件

sudo apt-get update
sudo apt install wireguard iptables unbound unbound-host bind9-dnsutils

添加wg的配置文件 wg0.conf

cat << EOF > /etc/wireguard/wg0.conf
[Interface]
Address = 10.200.100.1/24
SaveConfig = true
PrivateKey = [Your private key]
ListenPort = 51820

[Peer]
PublicKey = [Your private key]
AllowedIPs = 10.200.100.2/32
EOF

设置一下文件权限然后激活

chown -v root:root /etc/wireguard/wg0.conf
chmod -v 600 /etc/wireguard/wg0.conf
wg-quick up wg0
systemctl enable [email protected]

当然IP转发是必须的

echo net.ipv4.ip_forward=1 >> /etc/sysctl.conf
sudo sysctl -p
echo 1 > /proc/sys/net/ipv4/ip_forward

配置IPtables 规则也是必须的,我自然是放在rc.local

/usr/sbin/iptables -A INPUT -s 10.200.200.0/24 -p tcp -m tcp --dport 53 -m conntrack --ctstate NEW -j ACCEPT
/usr/sbin/iptables -A INPUT -s 10.200.200.0/24 -p udp -m udp --dport 53 -m conntrack --ctstate NEW -j ACCEPT
/usr/sbin/iptables -A FORWARD -i wg0 -o wg0 -m conntrack --ctstate NEW -j ACCEPT