跳转到内容
View in the app

A better way to browse. Learn more.

彼岸论坛

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
欢迎抵达彼岸 彼岸花开 此处谁在 -彼岸论坛

[程序员] WireGuard 如何直接使用局域网的 IP 访问

发表于
本地 阿里云服务器 公司内网
虚拟 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

Featured Replies

No posts to show

创建帐户或登录来提出意见

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.