I am running Ubuntu server 22.04, and have a peculiar port forwarding issue with a local machine. This machine has two Ethernet interfaces and the connected enp1s0 interface has an IP address 192.168.1.50. Full ip configuration is following:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:e0:4f:68:02:bb brd ff:ff:ff:ff:ff:ff
inet 192.168.1.50/24 metric 100 brd 192.168.1.255 scope global enp1s0
valid_lft forever preferred_lft forever
inet6 240f:74:de92::d1e/128 scope global dynamic noprefixroute
valid_lft 35597sec preferred_lft 35597sec
inet6 fd41:d8b6:99ba::d1e/128 scope global dynamic noprefixroute
valid_lft 35597sec preferred_lft 35597sec
inet6 fd41:d8b6:99ba:0:2e0:4fff:fe68:2bb/64 scope global mngtmpaddr noprefixroute
valid_lft forever preferred_lft forever
inet6 240f:74:de92:0:2e0:4fff:fe68:2bb/64 scope global dynamic mngtmpaddr noprefixroute
valid_lft 98462sec preferred_lft 98462sec
inet6 fe80::2e0:4fff:fe68:2bb/64 scope link
valid_lft forever preferred_lft forever
3: eno1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
link/ether 00:e0:4c:68:01:6e brd ff:ff:ff:ff:ff:ff
altname enp2s0
4: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
link/ether 02:42:55:86:e6:e5 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
valid_lft forever preferred_lft forever
I have set up port forwarding rules for my router so that any TCP or UDP packets coming from wan to port 22211 are forwarded to lan 192.168.1.50 port 22211
In my ufw configuration, I have allowed allowed routing of this port:
$ sudo ufw status
[sudo] password for *
Status: active
To Action From
-- ------ ----
22211/tcp ALLOW Anywhere
22211/tcp (v6) ALLOW Anywhere (v6)
Now, if I start a simple netcat socket (nc -l -p 22211) for this port, I can reach it with telnet via another machine in the local network just fine. Here is tcudump log when I telnet from another local machine. I connect, and send a letter a and press enter:
$ sudo tcpdump -pnvvi enp1s0 port 22211
tcpdump: listening on enp1s0, link-type EN10MB (Ethernet), snapshot length 262144 bytes
21:01:48.350024 IP (tos 0x0, ttl 64, id 59572, offset 0, flags [DF], proto TCP (6), length 60)
192.168.1.196.38840 > 192.168.1.50.22211: Flags [S], cksum 0x527d (correct), seq 3440167578, win 32120, options [mss 1460,sackOK,TS val 3772353734 ecr 0,nop,wscale 7], length 0
21:01:48.350139 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto TCP (6), length 60)
192.168.1.50.22211 > 192.168.1.196.38840: Flags [S.], cksum 0x3a60 (correct), seq 495600843, ack 3440167579, win 65160, options [mss 1460,sackOK,TS val 102903428 ecr 3772353734,nop,wscale 7], length 0
21:01:48.351892 IP (tos 0x0, ttl 64, id 59573, offset 0, flags [DF], proto TCP (6), length 52)
192.168.1.196.38840 > 192.168.1.50.22211: Flags [.], cksum 0x66b7 (correct), seq 1, ack 1, win 251, options [nop,nop,TS val 3772353737 ecr 102903428], length 0
21:01:50.698846 IP (tos 0x0, ttl 64, id 59574, offset 0, flags [DF], proto TCP (6), length 55)
192.168.1.196.38840 > 192.168.1.50.22211: Flags [P.], cksum 0xf275 (correct), seq 1:4, ack 1, win 251, options [nop,nop,TS val 3772356082 ecr 102903428], length 3
But when I try telnet form outside my local network, for some reason the connection is never established. For the longest time I was sure that my port forwarding configuration was off (although same router forward other ports to another machine in my local network just fine, and I basically just mirrored the configuration to another port), but as you can see from tcpdump logs below, packets arrive to the enp1s0 interface:
$ sudo tcpdump -pnvvi enp1s0 port 22211
tcpdump: listening on enp1s0, link-type EN10MB (Ethernet), snapshot length 262144 bytes
20:58:05.448829 IP (tos 0x0, ttl 50, id 0, offset 0, flags [DF], proto TCP (6), length 64)
126.33.109.168.9875 > 192.168.1.50.22211: Flags [S], cksum 0x4448 (correct), seq 2086171535, win 65535, options [mss 1240,nop,wscale 6,nop,nop,TS val 560510789 ecr 0,sackOK,eol], length 0
20:58:06.593532 IP (tos 0x0, ttl 50, id 0, offset 0, flags [DF], proto TCP (6), length 64)
126.33.109.168.9875 > 192.168.1.50.22211: Flags [S], cksum 0x405f (correct), seq 2086171535, win 65535, options [mss 1240,nop,wscale 6,nop,nop,TS val 560511790 ecr 0,sackOK,eol], length 0
20:58:07.613818 IP (tos 0x0, ttl 50, id 0, offset 0, flags [DF], proto TCP (6), length 64)
126.33.109.168.9875 > 192.168.1.50.22211: Flags [S], cksum 0x3c76 (correct), seq 2086171535, win 65535, options [mss 1240,nop,wscale 6,nop,nop,TS val 560512791 ecr 0,sackOK,eol], length 0
20:58:08.603603 IP (tos 0x0, ttl 50, id 0, offset 0, flags [DF], proto TCP (6), length 64)
126.33.109.168.9875 > 192.168.1.50.22211: Flags [S], cksum 0x388c (correct), seq 2086171535, win 65535, options [mss 1240,nop,wscale 6,nop,nop,TS val 560513793 ecr 0,sackOK,eol], length 0
20:58:09.563590 IP (tos 0x0, ttl 50, id 0, offset 0, flags [DF], proto TCP (6), length 64)
126.33.109.168.36371 > 192.168.1.50.22211: Flags [S], cksum 0xcd21 (correct), seq 2086171535, win 65535, options [mss 1240,nop,wscale 6,nop,nop,TS val 560514795 ecr 0,sackOK,eol], length 0
I can also see that netcat is listening to all interfaces (the 0.0.0.0 part):
$ sudo ss -tulpn | grep 22211
tcp LISTEN 0 1 0.0.0.0:22211 0.0.0.0:* users:(("nc",pid=3344,fd=3))
The routing table looks like following:
$ sudo route -vn
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.1.254 0.0.0.0 UG 0 0 0 enp1s0
0.0.0.0 192.168.1.1 0.0.0.0 UG 100 0 0 enp1s0
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
192.168.1.0 0.0.0.0 255.255.255.0 U 100 0 0 enp1s0
192.168.1.1 0.0.0.0 255.255.255.255 UH 100 0 0 enp1s0
So I am lost why the packets coming from outside network never reach the local socket in port 22211... Is there some additional firewall configuration that I'm supposed to configure ?
Edit: interestingly, indeed ping 8.8.8.8 times out (while for example ping google.com works fine)
eno1is down, but there appears to be no changesudo route -vnto show the numeric values please? That way we don't need to guess the meaning of the 2 default routes. Can you also confirm that you can ping some well known address from 192.168.1.50, e.g.8.8.8.8?ping google.comchoose? (It's shown in the first line.) This sounds like you've firewalled yourself away from IPv4, but still have fully functioning IPv6.route delete default 192.168.1.1*or 254)). Being able to ping 8.8.8.8 is your most important issue. Resolving that may well resolve everything.