I use debian 10 with kernel 4.19 and nftables as port forwarding tool. The rule is like
table ip nat {
chain prerouting {
type nat hook prerouting priority -100; policy accept;
ip daddr 10.250.181.103 tcp dport 25565 counter packets 0 bytes 0 log
ip daddr 10.250.181.103 tcp dport 25568 counter packets 0 bytes 0 log
ip daddr 10.250.181.103 tcp dport 25573 counter packets 0 bytes 0 log
ip daddr 10.250.181.103 tcp dport 25565 counter packets 0 bytes 0 dnat to 192.168.56.1:25565
ip daddr 10.250.181.103 tcp dport 25568 counter packets 0 bytes 0 dnat to 192.168.56.1:25568
ip daddr 10.250.181.103 tcp dport 25573 counter packets 0 bytes 0 dnat to 192.168.56.1:25573
}
chain postrouting {
type nat hook postrouting priority 100; policy accept;
ip saddr != 192.168.56.0/24 ip daddr 192.168.56.0/24 counter packets 0 bytes 0 masquerade
}
}
(The SNAT is because of 192.168.56.1 is Windows and does not support policy-based routing)
The port forwarding work well when I ssh to the system. However, it does not work after several seconds I log out from it.
What configs can I check to find out the reason?
conntrack -L
or better keepconntrack -E
running to see what are the "mappings" done during NAT and if something strange appears when it doesn't work anymore. – A.B Apr 26 '20 at 9:39192.168.56.0/24
with the host machine. It has another network interface and uses wireguard as tunnel to the very public gateway and internal ip is10.250.181.103
(peer:10.250.181.1
). "ssh to the system" means I ssh to192.168.56.101
from192.168.56.1
as a non-root user. – Steven Yang Apr 26 '20 at 10:13conntrack -E
in tmux shows[NEW] tcp 6 120 SYN_SENT src=<accesser ip> dst=10.250.181.103 sport=56978 dport=25568 [UNREPLIED] src=192.168.56.1 dst=192.168.56.101 sport=25568 dport=56978
when the connection fails. – Steven Yang Apr 26 '20 at 10:14192.168.56.1
itself and pinning the192.168.56.1
continuously in tmux seems to solve the problem. – Steven Yang Apr 26 '20 at 10:33