Ubuntu – Troubleshooting ‘Open’ Port Not Really Open Issue

iptablesportUbuntu

I used the following command to open port 2022 in Ubuntu:

sudo iptables -A INPUT -p tcp --dport 2022 -j ACCEPT

But if I start a web server on port 2022 it is not reachable.

If I run the command to see open ports:

sudo iptables -vnL

The output starts with

enter image description here

Now, ports that show up there like 3000 or 4000 work, but 2022 does not.

What's going on and how can I enable port 2022?

Best Answer

The order matters. Your entry for 2022 in the iptables is behind DROP, so DROP is matched first and your ACCEPT entry is never reached.

You need to Insert instead of Append (-I instead of -A).