동일한 피어에서 피어의 Wireguard IP 주소에 액세스합니다.

동일한 피어에서 피어의 Wireguard IP 주소에 액세스합니다.

Wireguard를 설정했습니다. Peer 1, Peer 2의 주소인 에 연결할 수 있습니다 10.200.200.1. 그러나 Peer 1에서는 연결할 수 없습니다. 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

그래도 핑은 할 수 있어요 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

관련 정보