最近将所有服务器更换为Debian,并在其上安装WireGuard
首先访问WireGuard官方网站获取安装信息:https://www.wireguard.com/install/#installation
bashapt update
bashapt install wireguard
bashcd /etc/wireguard/ umask 077
bashwg genkey > server.key wg pubkey < server.key > server.key.pub
bashvim /etc/wireguard/wg0.conf
wg0.conf文件中的PrivateKey字段。ini[Interface] Address = 192.168.0.1/16 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 = 51820 PrivateKey = {Server_PrivateKey} [Peer] PublicKey = {Client1_PublicKey} AllowedIPs = 192.168.0.2/32 PersistentKeepalive = 25 [Peer] PublicKey = {Client2_PublicKey} AllowedIPs = 192.168.0.3/32 PersistentKeepalive = 25
bashsudo wg-quick up wg0 sudo wg-quick down wg0 sudo wg show
bash
bash
ini
利用wireguard实现远程访问家里网络内任意设备
我是在openwrt上安装的wireguard,你也可以在家里其他路由器上安装
bash
如果该命令返回 net.ipv4.ip_forward = 1,那么 IP 转发功能已经启用了。如果没有,需要修改/etc/sysctl.conf,在该文件中添加
bash
然后,运行sysctl -p命令应用更改。
![]()
待完善
vim /etc/wireguard/wg0.conf
wg genkey > client.key
wg pubkey < client.key > client.key.pub
[Interface]
PrivateKey = {Client_PrivateKey}
Address = 192.168.0.2/16
[Peer]
PublicKey = {Server_PublicKey}
Endpoint = {Server_IP}:51820
AllowedIPs = 192.168.0.0/16
PersistentKeepalive = 25
sysctl net.ipv4.ip_forward
net.ipv4.ip_forward=1