How to Allow or Block Ports Using FirewallD and UFW

August 29, 2025 / Security and Backup

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

  1. 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
  2. Allow a Port (Example: Port 8080)
    sudo firewall-cmd --permanent --add-port=8080/tcp
    sudo firewall-cmd --reload
    
  3. Block or Remove a Port
    sudo firewall-cmd --permanent --remove-port=8080/tcp
    sudo firewall-cmd --reload
    
  4. Verify Active Rules
    sudo firewall-cmd --list-ports

Using UFW (Uncomplicated Firewall)

  1. Check UFW Status
    sudo ufw status

    If it is inactive, enable it:

    sudo ufw enable
  2. Allow Port 8080 (TCP)
    sudo ufw allow 8080/tcp
  3. Block Port 8080
    sudo ufw deny 8080/tcp
  4. Delete a Specific Rule
    sudo ufw delete allow 8080/tcp
  5. 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

Controlling network access and strengthening Linux server security?
A Linux VPS Hosting solution gives you the flexibility to manage firewall rules, secure services and protect your server from unauthorised access.
Spread the love