WireGuard安装及配置
1.安装
sudo apt update
sudo apt install wireguard
2.生成本机key
wg genkey | tee privatekey | wg pubkey > publickey
3.配置
这里分服务端配置以及客户端配置
a) 服务端配置
[Interface]
Address = 192.168.33.1/24
MTU = 1420
PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -A FORWARD -o %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -D FORWARD -o %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
ListenPort = 39900
PrivateKey = {本机私钥}
[Peer]
PublicKey = {接入机器公钥}
AllowedIPs = 192.168.33.99/32
b) 客户端配置
[Interface]
Address = 192.168.33.2/32
PrivateKey = {本机私钥}
[Peer]
PublicKey = {服务端公钥}
Endpoint = {服务端公网ip}:39900
AllowedIPs = 192.168.33.0/24
PersistentKeepalive = 25
4.配置文件位置
常见位置:/etc/wireguard
有时候也在:/usr/local/etc/wireguard
一般来说修改其中的wg0.conf就可以了
# 快速启动
sudo wg-quick up wg0
# 快速关闭
sudo wg-quick down wg0
5.直接使用客户端
待补充