Sub topic 2
Changing Rules Without Cutting Off SSH
This chapter assumes you know basic Linux command line use and sudo, understand TCP and UDP ports, can manage services with systemctl, and know that SSH normally listens on TCP port 22.
Changing rules without cutting off SSH
Confirm that SSH is allowed before you change anything. Test changes in the runtime configuration first, and add a timeout so a mistake clears itself.
sudo firewall-cmd --list-services
sudo firewall-cmd --add-service=ssh --timeout=5mWhen the change works, save it with sudo firewall-cmd --runtime-to-permanent.
Opening a service by name
A service is a named group of ports that firewalld knows about. Opening the http service allows TCP port 80.
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --reload
sudo firewall-cmd --list-servicesThe --permanent flag writes the change to disk. The --reload flag applies it.
Opening a port and protocol
Use a port number and protocol when no service name exists for your application.
sudo firewall-cmd --permanent --add-port=8080/tcp
sudo firewall-cmd --reload
sudo firewall-cmd --query-port=8080/tcpThe last command prints yes when the port is open.
Closing a service or port
Remove the same items you added. The removal takes effect after a reload.
sudo firewall-cmd --permanent --remove-service=http
sudo firewall-cmd --permanent --remove-port=8080/tcp
sudo firewall-cmd --reloadExercise
You add --add-port=8080/tcp with --permanent but skip --reload. Is port 8080 open right now?
Show answer
No. The permanent change is saved to disk but not applied to the running configuration until you run --reload.