This article explains how to allow or block ports using FirewallD and UFW. Proper port management is essential for securing a Linux server, ensuring that only required services remain accessible.
Table of Contents
Using FirewallD
- Check FirewallD Status
Run the following command:sudo systemctl status firewalld
If the service is inactive, start and enable it:
sudo systemctl start firewalld sudo systemctl enable firewalld
- Allow a Port (Example: Port 8080)
sudo firewall-cmd --permanent --add-port=8080/tcp sudo firewall-cmd --reload
- Block or Remove a Port
sudo firewall-cmd --permanent --remove-port=8080/tcp sudo firewall-cmd --reload
- Verify Active Rules
sudo firewall-cmd --list-ports
Using UFW (Uncomplicated Firewall)
- Check UFW Status
sudo ufw status
If it is inactive, enable it:
sudo ufw enable
- Allow Port 8080 (TCP)
sudo ufw allow 8080/tcp
- Block Port 8080
sudo ufw deny 8080/tcp
- Delete a Specific Rule
sudo ufw delete allow 8080/tcp
- View Rules (Numbered)
sudo ufw status numbered
Important instruction:
- FirewallD: Add or remove ports using firewall-cmd, then reload to apply changes.
- UFW: Allow, deny, or delete ports using ufw, and verify using ufw status.
This way, you can allow or block ports using FirewallD and UFW. If you want additional assistance, feel free to contact our support team.
Managing ports already? Learn How to change the default SSH port
A Linux VPS Hosting solution gives you the flexibility to manage firewall rules, secure services and protect your server from unauthorised access.