firewalld: How to Open and Close Ports
If you are using firewalld[1] to protect your system, you may at times need to open local ports to let traffic into your machine.
Before making any changes, you can check your active zones:
sudo firewall-cmd --get-active-zonesAnd then find all open ports in a given zone (public used in this example).
sudo firewall-cmd --zone=public --list-portsTo open a new port (let's say port 8080), run the following. You may substitute tcp for udp if you require that protocol.
sudo firewall-cmd --zone=public --add-port=8080/tcpAfter testing, you may elect to make the change persist by setting the --permanent flag per the below:
sudo firewall-cmd --permanent --zone=public --add-port=8080/tcpInversely, if you need to close a port:
sudo firewall-cmd --zone=public --remove-port=8080/tcp
# Make the change persist using the `--permanent` flag
sudo firewall-cmd --permanent --zone=public --remove-port=8080/tcpRemember to reload the active config with sudo firewall-cmd --reload.