Score:0

IPtables port forwarding to host machine IP

us flag

In an LXC container I have Wireguard installed and the client connects normally and I see the port and the information, but when I try to curl to localhost (127.0.0.1) or to the local ip (192.168.1.180) it doesn't connect.

192.168.1.180 (Host IP) 10.7.0.2 (IP)

10.7.0.2:6060 <-> 192.168.1.180:6060

curl -I 10.7.0.2:6060

-Resolve OK --

curl -I 127.0.1:6060 (OR) curl -I 192.168.1.180:6060

Responde unreachable

My IPtables rules:

iptables -A FORWARD -i eth0 -j ACCEPT;
iptables -t nat -A PREROUTING -p tcp --dport 6060:6060 -j DNAT --to-destination 10.7.0.2;
iptables -w -t nat -A POSTROUTING -o eth0 -j MASQUERADE;

IPv4 Forward is active:

#sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 1

Server Wireguard Config:

root@wiretest:/etc/wireguard# cat wg0.conf
# Do not alter the commented lines
# They are used by wireguard-install
# ENDPOINT asd.demo.net

[Interface]
Address = 10.7.0.1/24
PrivateKey = CI0heA/1InAo........
ListenPort = 51820
        
# BEGIN_PEER nodotest
[Peer]
PublicKey = y1t+k9cR06F7/y6ANJtEx.......
PresharedKey = +Tya8VsxbB3i9hkIRf......
AllowedIPs = 10.7.0.2/32
# END_PEER nodotest
root@wiretest:/etc/wireguard#

Client Config:

root@wiredocker:/etc/wireguard# cat wg0.conf
[Interface]
Address = 10.0.0.2/24
DNS = 8.8.8.8
PrivateKey = +GLTuJnydedy2QMvTj5SGdr......

[Peer]
PublicKey = qlNPgT7Fwbjmexq09EVF........
PresharedKey = +Tya8VsxbB3i9hkIR......
AllowedIPs = 0.0.0.0/0, ::/0
Endpoint = asd.demo.net:51820
PersistentKeepalive = 25
root@wiredocker:/etc/wireguard# 

Server IPTables List:

# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     udp  --  anywhere             anywhere             udp dpt:51823

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     all  --  anywhere             anywhere             state RELATED,ESTABLISHED
ACCEPT     all  --  10.7.0.0/24          anywhere            

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
 

Thanks !

A.B avatar
cl flag
A.B
Please don't use Docker when doing any troubleshooting involving networking not directly related to Docker. Have it removed or completely disabled and reboot. Running Docker never helps (eg: https://serverfault.com/questions/963759/docker-breaks-libvirt-bridge-network)
us flag
i have the same problem without Docker :S
A.B avatar
cl flag
A.B
Maybe but you might miss a working configuration later because of it
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.