cd /etc/wireguard/ # 生成服务端公钥和仅钥 wg genkey | tee /etc/wireguard/$HOSTNAME.private.key | wg pubkey > /etc/wireguard/$HOSTNAME.public.key # 配置密钥读写权限 chmod 600 /etc/wireguard/$HOSTNAME.private.key /etc/wireguard/$HOSTNAME.public.key
systemctl start wg-quick@laptop.service systemctl status wg-quick@laptop.service ● wg-quick@laptop.service - WireGuard via wg-quick(8) for laptop Loaded: loaded (/lib/systemd/system/wg-quick@.service; disabled; vendor preset: enabled) Active: active (exited) since Wed 2024-05-15 12:35:51 CST; 10s ago Docs: man:wg-quick(8) man:wg(8) https://www.wireguard.com/ https://www.wireguard.com/quickstart/ https://git.zx2c4.com/wireguard-tools/about/src/man/wg-quick.8 https://git.zx2c4.com/wireguard-tools/about/src/man/wg.8 Process: 122170 ExecStart=/usr/bin/wg-quick up laptop (code=exited, status=0/SUCCESS) Main PID: 122170 (code=exited, status=0/SUCCESS)
5月 15 12:35:50 ian-ThinkPad-X270 wg-quick[122170]: [#] ip -4 address add 10.0.0.2/24 dev laptop 5月 15 12:35:50 ian-ThinkPad-X270 wg-quick[122170]: [#] ip linkset mtu 1420 up dev laptop 5月 15 12:35:50 ian-ThinkPad-X270 wg-quick[122206]: [#] resolvconf -a tun.laptop -m 0 -x 5月 15 12:35:50 ian-ThinkPad-X270 wg-quick[122170]: [#] wg set laptop fwmark 51820 5月 15 12:35:51 ian-ThinkPad-X270 wg-quick[122170]: [#] ip -4 route add 0.0.0.0/0 dev laptop table 51820 5月 15 12:35:51 ian-ThinkPad-X270 wg-quick[122170]: [#] ip -4 rule add not fwmark 51820 table 51820 5月 15 12:35:51 ian-ThinkPad-X270 wg-quick[122170]: [#] ip -4 rule add table main suppress_prefixlength 0 5月 15 12:35:51 ian-ThinkPad-X270 wg-quick[122170]: [#] sysctl -q net.ipv4.conf.all.src_valid_mark=1 5月 15 12:35:51 ian-ThinkPad-X270 wg-quick[122170]: [#] nft -f /dev/fd/63 5月 15 12:35:51 ian-ThinkPad-X270 systemd[1]: Finished WireGuard via wg-quick(8) for laptop. # 测试到服务器的连接 ip addr show laptop 17: laptop: <POINTOPOINT,NOARP,UP,LOWER_UP> mtu 1420 qdisc noqueue state UNKNOWN group default qlen 1000 link/none inet 10.0.0.2/24 scope global laptop valid_lft forever preferred_lft forever
ping 10.0.0.1 PING 10.0.0.1 (10.0.0.1) 56(84) bytes of data. 64 bytes from 10.0.0.1: icmp_seq=1 ttl=64 time=57.4 ms 64 bytes from 10.0.0.1: icmp_seq=2 ttl=64 time=56.3 ms 64 bytes from 10.0.0.1: icmp_seq=3 ttl=64 time=48.7 ms