Wireguard
see also:
INSTALL #
Download win/linux: official web online installer: [www.wireguard.com/install](Installation - WireGuard). win offline installer: download.wireguard.com/windows-client/.
ubuntu:
apt install wireguard
CONFIG #
Win #


ps1:“状态”的“已连接”,只是表示第一次握手成功,之后即使网络不通也不影响此状态。
ps2:windows 配置文件名必须是 wg0.conf 才能导入。
Nix #
sudo vi /etc/wireguard/wg0.conf
配置文件内容 #
- wgX.conf 接口配置文件,每个接口(NIC)对应一个 .conf
- 每个 conf 文件都包括两个部分: interface 和 peer,如果是 server,则在 interface 部分配置 ListenPort 即可
- 每次服务启动,可能需要 10s 左右或更久建立连接,如果想快,可以在 server 端 ping 某个 client,或者互相 ping
# 自己信息
[Interface]
Address = 10.66.2.2/32
PrivateKey = 自己私钥
#ListenPort = 51820
# 对侧信息
[Peer]
Endpoint = 对方公网IP:51820
PublicKey = 对方公钥
AllowedIPs = 10.66.2.1/24
PersistentKeepalive = 25
Tips #
生成一对 key (key pair),并保存成文件:
( umask 077; ts=$(date +%F-%H%M%S); echo "$ts"; wg genkey | tee "${ts}-privatekey" | wg pubkey > "${ts}-publickey"; echo 'private:'; cat "${ts}-privatekey"; echo 'public:'; cat "${ts}-publickey" )
使能并重启所有服务,使改动生效:
sudo systemctl enable [email protected]; sudo systemctl reload [email protected]; sudo systemctl restart [email protected]; sudo systemctl status [email protected]