WireGuard 如何直接使用局域网的 IP 访问

查看 23|回复 0
作者:eunrui   
[td][/td]
[td]本地[/td]
[td]阿里云服务器[/td]
[td]公司内网[/td]
虚拟 IP(wireguard)
10.0.8.2
10.0.8.1(服务端)
10.0.8.3
实际 IP
192.168.1.47
x.x.x.x
192.168.11.222
阿里云上部署用的wg-easy,以下是默认的配置
# Note: Do not edit this file directly.
# Your changes will be overwritten!
# Server
[Interface]
PrivateKey = KA8QwuT3CzNNGGWD9iXl7YxSqtI5urW89+k8oO5bDWM=
Address = 10.0.8.1/24
ListenPort = 51820
PreUp =
PostUp =  iptables -t nat -A POSTROUTING -s 10.0.8.0/24 -o eth0 -j MASQUERADE; iptables -A INPUT -p udp -m udp --dport 51820 -j ACCEPT; iptables -A FORWARD -i wg0 -j ACCEPT; iptables -A FORWARD -o wg0 -j ACCEPT;
PreDown =
PostDown =  iptables -t nat -D POSTROUTING -s 10.0.8.0/24 -o eth0 -j MASQUERADE; iptables -D INPUT -p udp -m udp --dport 51820 -j ACCEPT; iptables -D FORWARD -i wg0 -j ACCEPT; iptables -D FORWARD -o wg0 -j ACCEPT;
# Client: test (6a258866-5164-4ecc-9873-2b1cc4dc6806)
[Peer]
PublicKey = 1jGq3SNpQhm0ucRGpNevW0dnAVYk3y5aFTdb5mk4EHg=
PresharedKey = V9iL5IfalLvZiuGeXRZe3EUtutLnBXJYs5R90RNsbSs=
AllowedIPs = 10.0.8.2/32
# Client: server (9d0012cd-0248-4ee8-b845-c3cbf07172d7)
[Peer]
PublicKey = UqJD/AaTXBLi1kAMZn99TT4eapO8hdtAmyUeK9TdkhY=
PresharedKey = r2WVnILyhEsZNhRhDN5dcfP84xLrQ6/Z9ohGSq0rNLs=
AllowedIPs = 10.0.8.3/32
目前按照上面的虚拟 ip ,可以互相 ping 通,但是没办法直接访问局域网中的 IP ,看过这个帖子/t/857269,按照 1 楼 V 友说的配置的 iptables ,添加到了内网服务器上 wireguard 配置,如下
[Interface]
PrivateKey = qGn5f2GtvQm/5GmudGGgdzb2IBt4nzZYudYDvVfd0H8=
Address = 10.0.8.3/24
DNS = 114.114.114.114
PreUp=iptables -t nat -A POSTROUTING -s 10.0.0.0/24 -j SNAT --to-source 192.168.11.222
PostDown=iptables -t nat -D POSTROUTING -s 10.0.0.0/24 -j SNAT --to-source 192.168.11.222
[Peer]
PublicKey = cXPP7xJXo/QDDiEiwEfuDsUq1ytjSXsulawokP4eg3Q=
PresharedKey = r2WVnILyhEsZNhRhDN5dcfP84xLrQ6/Z9ohGSq0rNLs=
AllowedIPs = 10.0.8.0/24
PersistentKeepalive = 25
Endpoint = xx.xx.xx.xx:51820
加完虚拟 ip 都无法 ping 通了,请教下大家,这个该怎么加呢。
以下是 wg-easy 分配给我本地的客户端
[Interface]
PrivateKey = IPh0aFShR2hw+53TPLiXvt7kLofdjkxYSPLhG4yvMnc=
Address = 10.0.8.2/24
DNS = 114.114.114.114
[Peer]
PublicKey = cXPP7xJXo/QDDiEiwEfuDsUq1ytjSXsulawokP4eg3Q=
PresharedKey = V9iL5IfalLvZiuGeXRZe3EUtutLnBXJYs5R90RNsbSs=
AllowedIPs = 10.0.8.0/24, 192.168.11.0/24
Endpoint = xx.xx.xx.xx:51820
PersistentKeepalive = 25
您需要登录后才可以回帖 登录 | 立即注册

返回顶部