安装
sudo apt install wireguard -y
配置文件
配置文件放到 /etc/wireguard/ 下,比如 /etc/wireguard/wg0.conf
sudo nano /etc/wireguard/wg0.conf [Interface] PrivateKey = xx Address = 10.0.0.12/24 [Peer] PublicKey = xx Endpoint = web.pp.com:10001 AllowedIPs = 10.0.0.0/24, 172.16.31.64/26, 172.16.20.224/27 PersistentKeepalive = 30 #配置里写了 AllowedIPs = 0.0.0.0/0,那么所有流量都会走 wg0。如果只写了内网网段(比如 10.0.0.0/24),那么只有访问那个网段时才会走 WireGuard。
启停
启动连接 sudo wg-quick up wg0 断开连接 sudo wg-quick down wg0 开机自动启动 sudo systemctl enable wg-quick@wg0
查看更多
sudo wg show interface: wg0 public key: xx private key: (hidden) listening port: 36361 peer: xx endpoint: xxx:10001 allowed ips: 10.0.0.0/24, 172.16.31.64/26, 172.16.20.224/27 latest handshake: 33 seconds ago transfer: 2.81 MiB received, 194.58 KiB sent persistent keepalive: every 30 seconds