This is an explanation of how to set a firewall using the ufw command in Ubuntu.
The goal is to be able to block communication coming in from outside the server for each port number.
If your VPS or cloud service provides firewall functionality, it may be useful to use it. If you are on-premises or have a desire to control it with commands, you can use the ufw command.
Check the firewall status
Use the "ufw status" command to check the status of the firewall.
sudo ufw status
To enable the firewall, use the "ufw enable" command.
sudo ufw enable
If you have enabled a firewall, be careful not to drop the device until you have checked the firewall. The SSL connection you are connecting to is not affected.
If the SSH connection port is blocked, communication will not be possible, and in the case of VPS or cloud server, it will be operated from the web console, and in the case of on-premises, if the web console is not prepared, it will be operated from the console of the local machine. You will need to do it. Please work with caution.
To disable the firewall, use the "ufw disable" command.
sudo ufw disable
Let's open the port.
#HTTP port sudo ufw allow 80 # HTTPS port sudo ufw allow 443 #Default SSH port sudo ufw allow 22 # SSH port set arbitrarily sudo ufw allow 51234
Close the released port
Use "ufw delete" to close the released port. The rule name will be something like "allow 22".
sudo ufw delete allow 22