wg安裝
Centos8
$ sudo yum install elrepo-release epel-release
$ sudo yum install kmod-wireguard wireguard-tools
Centos7
$ 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
服務器配置
# 生成服務器私鑰
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 = 1
開啟關閉wg指令:
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