從同一對等方存取對等方的 Wireguard IP 位址

從同一對等方存取對等方的 Wireguard IP 位址

我設定了 Wireguard。我可以連接到對等點 1 和對等點10.200.200.12 上的位址。10.200.200.1

對等點 1 的配置:

[Interface]
Address = 10.200.200.1/24
ListenPort = 51820
PrivateKey = ************

# substitute eth0 in the following lines to match the Internet-facing interface
# if the server is behind a router and receives traffic via NAT, these iptables rules are not needed
PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -A FORWARD -o %i -j ACCEPT; iptables -t nat -A POSTROUTING -o enp0s2 -j MASQUERADE
PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -D FORWARD -o %i -j ACCEPT; iptables -t nat -D POSTROUTING -o enp0s2 -j MASQUERADE

[Peer]
# foo
PublicKey = ***************
#PresharedKey = PRE-SHARED_KEY
AllowedIPs = 10.200.200.2/8

#PersistentKeepalive = 25

curl 10.200.200.1:2001給我

*   Trying 10.200.200.1:2001...
* connect to 10.200.200.1 port 2001 failed: Connection refused
* Failed to connect to 10.200.200.1 port 2001 after 0 ms: Connection refused
* Closing connection 0
curl: (7) Failed to connect to 10.200.200.1 port 2001 after 0 ms: Connection refused

不過我可以 ping 通10.200.200.1

答案1

好吧,我明白了——這有兩個部分:

sysctl

sudo sysctl -w net.ipv4.conf.all.route_localnet=1

sudo sysctl -w net.ipv4.ip_forward=1

若要連線到本地工作:

sudo iptables -t nat -A OUTPUT -d 10.200.200.1 -j DNAT --to-destination 127.0.0.1

相關回答:https://stackoverflow.com/a/70310399/15436715

相關內容