查看内核是否支持
sudo modprobe wireguard
安装
yum -y install wireguard-tools
web 单文件版
https://github.com/Safe3/firefly
https://zhuanlan.zhihu.com/p/447375895
启用转发
echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
echo "net.ipv4.conf.all.proxy_arp = 1" >> /etc/sysctl.conf
sysctl -p /etc/sysctl.conf
systemctl stop firewalld
systemctl disable firewalld
ufw disable
可选 与关闭互斥
设置IP地址伪装(NAT):
systemctl start firewalld
systemctl enable firewalld
firewall-cmd --zone=public --add-masquerade --permanent
firewall-cmd --reload
查看转发规则
iptables -L
iptables -L filter -n -v
清除规则
sudo iptables -F
服务器端
iptables -I FORWARD -s 10.10.10.1/24 -i wg0 -d 10.10.10.1/24 -j ACCEPT # 放行 VPN 网段
iptables -I FORWARD -s 10.10.10.1/24 -i wg0 -d 192.168.50.0/24 -j ACCEPT # 放行 VPN 转发到内网的流量
iptables -I FORWARD -s 192.168.50.0/24 -i wg0 -d 10.10.10.1/24 -j ACCEPT # 放行内网 转发到 VPN 的流量
内网转发端
PostUp = iptables -t nat -A POSTROUTING -s 192.168.2.0/24 -j SNAT --to-source 192.168.1.2
PostDown = iptables -t nat -D POSTROUTING -s 192.168.2.0/24 -j SNAT --to-source 192.168.1.2
postdown = iptables -t nat -F