170 字
1 分钟
WireGuard 搭建与配置
安装
apt install wireguard常用控制命令:
sudo wg-quick up wg0 # 启动sudo wg-quick down wg0 # 停止sudo wg show # 状态开启端口转发
编辑 /etc/sysctl.conf:
net.ipv4.ip_forward=1net.ipv6.conf.all.forwarding=1sudo sysctl -p生成密钥对
cd /etc/wireguard/umask 077
# 服务端密钥wg genkey | tee privatekey | wg pubkey > publickey
# 客户端密钥wg genkey > client1.keywg pubkey < client1.key > client1.key.pub服务端配置
/etc/wireguard/wg0.conf:
[Interface]Address = 10.0.0.1/24SaveConfig = truePrivateKey = <server-private-key>ListenPort = 51820
[Peer]PublicKey = <client-public-key>AllowedIPs = 10.0.0.2/32,192.168.0.0/24启动并设置开机自启:
sudo systemctl enable wg-quick@wg0sudo wg-quick up wg0客户端配置
[Interface]PrivateKey = <client-private-key>Address = 10.0.0.2/24DNS = 8.8.8.8
[Peer]PublicKey = <server-public-key>Endpoint = <server-ip>:51820AllowedIPs = 0.0.0.0/0PersistentKeepalive = 25iPhone、Windows、Mac 等均可使用相同格式的配置文件导入。
WireGuard 搭建与配置
https://iiii.fun/posts/linux/wireguard-setup/