wg安装
Centos8服务器
$ sudo yum install elrepo-release epel-release $ sudo yum install kmod-wireguard wireguard-tools
Centos7ui
$ sudo yum install epel-release https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm $ sudo yum install yum-plugin-elrepo $ sudo yum install kmod-wireguard wireguard-tools
服务器配置code
# 生成服务器私钥 wg genkey > privatekey # 生成服务器公钥 wg pubkey < privatekey > publickey # 生成口令(每一个peer一个) wg genpsk > presharedkey # 服务器配置文件设置 cat /etc/wireguard/wg0.conf [Interface] Address = 192.168.8.1/24 PostUp = iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE PostDown = iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE ListenPort = 53 # 注意该端口是UDP端口 PrivateKey = 服务器私钥 [Peer] PublicKey = 客户端公钥 PresharedKey = 口令 AllowedIPs = 192.168.8.10/32 [Peer] PublicKey = 客户端公钥 PresharedKey = 口令 AllowedIPs = 192.168.8.10/32
若是在Centos7操做,注意跑下yum update(对内核版本有要求)
系统转发注意开启
net.ipv4.ip_forward = 1ip
开启关闭wg指令:table
wg-quick up wg0 wg-quick down wg0
客户端配置文件服务器端
[Interface] PrivateKey = 客户端私钥 Address = 192.168.8.10/32 DNS = 114.114.114.114 [Peer] PublicKey = 服务器公钥 PresharedKey = 口令 AllowedIPs = 0.0.0.0/0 Endpoint = 服务器IP:服务器端口 PersistentKeepalive = 30