Sometimes, when you don’t work with a specific system, you can forget how to set it up or check its settings. This happened to me when I set up an Ubuntu server. It had been 6-7 years since I last worked on this type of server, and I missed out on some new features and changes that had been made since then.

Here, I will share some information about checking your Ubuntu server ports and the process of opening or closing them. The system offers several methods to accomplish this.

I first checked iptables to ensure everything was properly configured. But what exactly are iptables? It’s an interface to netfilter that is simple and efficient. Within iptables, there are 3 groups – INPUT, OUTPUT, and FORWARD. For each group, you can create a rule for the default action and another for other actions. For example, if you create a rule to deny all input traffic and create a rule for incoming traffic at a specific port, you can receive data only on this port, while all other traffic will be denied.

I needed to address the next step, which was to check ufw, one of the default firewalls. There is another one called firewall-cmd, but I had forgotten about it. After spending 1-2 hours troubleshooting, I deleted all data from iptables and created a restore script. After several tests, I figured out what was going wrong – I fixed the last firewall-cmd by adding one of the required ports to the list. Below, I will share several useful commands.

firewall-cmd --zone=public --list-all #List data for zone
firewall-cmd --runtime-to-permanent #save temploary runtime data
firewall-cmd --zone=public --add-port=1883/tcp #add specific tcp port to zone
firewall-cmd --zone=public --remove-port=18083/tcp #remove specific port from zone

Was this article helpful?