ufw Firewall Tutorial#
Uninstall the package using apt-get --purge remove
package name
Ubuntu Firewall#
You can enable UFW on Linux by following these steps:
- First, check if UFW is installed. Enter the following command in the terminal:
sudo ufw status
If it prompts "command not found," it means UFW is not installed on this system. You need to execute the following command to install UFW:
sudo apt-get install ufw
- To activate UFW, set the default UFW policies to deny:
sudo ufw default deny incoming
sudo ufw default allow outgoing
- Open the necessary ports. For example, open SSH port 22 (modify as needed):
sudo ufw allow 22/tcp
- Finally, enable UFW and check the status:
sudo ufw enable
sudo ufw status
If you see "Status: active" in the output, it means UFW has been successfully enabled.
sudo ufw allow 22
// Open port 22
sudo ufw reload
// Restart UFW firewall
sudo ufw status
// Check firewall status
sudo netstat -tunlp | grep 22
// View information about port 22
sudo ufw disable
// Disable firewall
sudo sudo apt-get install ufw
// Install firewall
sudo ufw enable
// Enable firewall
sudo ufw delete allow 21
// Close port 21
sudo ufw allow 8001/tcp
// Specify opening port 8001 with TCP protocol
sudo ufw delete allow 8001/tcp
// Close port 8001
Resolving Port Occupancy#
- Enter the following command to view all service ports and display the PID number.
netstat -ap
To stop this process, you can use the kill command.
kill 123
// Stop the process with PID 123 and its associated port.
To view port 8080, you can use the grep command:
netstat -ap | grep 3000
To view port 8888, enter the following command in the terminal:
lsof -i:8888