Wireguard服務器/客戶端配置

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
相關文章
相關標籤/搜索