A Comprehensive Guide to Configuring Firewall Settings on Linux Mint

Learn how to set up and manage a firewall on Linux Mint using both command-line and graphical tools, ensuring your system remains secure without compromising accessibility.

Introduction

In an era where cyber threats are increasingly sophisticated, securing your system is paramount. A firewall acts as a gatekeeper, monitoring and controlling incoming and outgoing network traffic based on predefined rules. Linux Mint, renowned for its user-friendliness, offers robust tools to configure firewall settings effectively. This guide explores how to set up and manage a firewall using both command-line and graphical tools, ensuring your system remains secure without compromising accessibility.


Why a Firewall Matters

A firewall is your first line of defense against unauthorized access. It helps:

  • Block malicious traffic and hacking attempts.
  • Restrict unnecessary network services.
  • Protect sensitive data from exposure.

Linux Mint includes Uncomplicated Firewall (UFW), a simplified interface for the powerful iptables framework. For users preferring a GUI, GUFW provides intuitive controls. Let’s dive into configuring both.


Prerequisites

Before proceeding:

  1. Ensure you have sudo privileges.

  2. Update your system:

    sudo apt update && sudo apt upgrade -y  
    
  3. Verify UFW is installed (pre-installed on most Linux Mint systems):

    sudo ufw --version  
    

    If not installed, use:

    sudo apt install ufw  
    

Method 1: Configuring UFW via Command Line

Step 1: Enable UFW
By default, UFW is inactive. Enable it with:

sudo ufw enable  

Caution: Ensure you allow SSH (port 22) first if connecting remotely to avoid being locked out.

Step 2: Set Default Policies
UFW defaults to blocking all incoming traffic and allowing all outgoing. Confirm this with:

sudo ufw default deny incoming  
sudo ufw default allow outgoing  

For stricter security, restrict outgoing traffic too:

sudo ufw default deny outgoing  

(Note: This requires manually allowing specific outgoing services.)

Step 3: Allow Essential Services

  • SSH (Secure Shell):

    sudo ufw allow ssh  # or port 22  
    
  • HTTP/HTTPS (Web Servers):

    sudo ufw allow http  # port 80  
    sudo ufw allow https  # port 443  
    
  • Custom Ports:

    sudo ufw allow 8080  # e.g., for a custom web app  
    

Step 4: Deny Unwanted Traffic
Block specific IP addresses or subnets:

sudo ufw deny from 192.168.1.100  
sudo ufw deny from 203.0.113.0/24  

Step 5: Check Status and Rules
View active rules:

sudo ufw status verbose  

Delete a rule:

sudo ufw delete allow http  # or specify rule number from status  

Step 6: Disable or Reset UFW
To temporarily disable:

sudo ufw disable  

Reset all rules:

sudo ufw reset  

Method 2: Using GUFW (Graphical Interface)

Step 1: Install GUFW
Install via terminal or Software Manager:

sudo apt install gufw  

Step 2: Launch and Enable Firewall
Open GUFW from the menu. Click the toggle switch to Enable the firewall.

Step 3: Configure Rules

  • Predefined Rules:
    Click RulesAdd. Choose from presets like SSH, HTTP, or Samba.
  • Custom Rules:
    Specify ports (e.g., 8080/tcp), IP addresses, or ranges under Advanced.

Step 4: Set Policies
Under Defaults, adjust incoming/outgoing traffic policies.

Step 5: Monitor Traffic
Use the Report tab to view active connections and logged events.


Advanced Configuration Tips

1. Rate Limiting
Prevent brute-force attacks by limiting connection attempts:

sudo ufw limit ssh  

2. Application Profiles
Some apps (e.g., Apache, Nginx) create UFW profiles. List them with:

sudo ufw app list  

Allow an app profile:

sudo ufw allow 'Nginx Full'  

3. Logging
Enable logging to monitor blocked/allowed traffic:

sudo ufw logging on  

Logs are stored at /var/log/ufw.log.

4. Integrate with Fail2Ban
Install Fail2Ban to block IPs with suspicious activity:

sudo apt install fail2ban  

Configure rules in /etc/fail2ban/jail.local.

5. Backup and Restore Rules
Export rules:

sudo ufw export > ufw_backup.txt  

Import later:

sudo ufw import ufw_backup.txt  

Best Practices

  1. Least Privilege Principle: Only allow necessary ports/services.
  2. Regular Audits: Review rules with sudo ufw status periodically.
  3. Combine Layers: Use UFW with intrusion detection tools like Fail2Ban.
  4. Test Configurations: After setting rules, test connectivity (e.g., nmap -Pn your-ip).
  5. Physical Access: Always configure firewall rules locally first to avoid lockouts.

Troubleshooting Common Issues

  • Locked Out of SSH: Physically access the machine and run:

    sudo ufw allow ssh && sudo ufw reload  
    
  • Service Not Working: Check if the relevant port is allowed.

  • Conflicting Firewalls: Ensure other tools (e.g., iptables) aren’t conflicting.


Conclusion

Configuring a firewall on Linux Mint is straightforward with UFW and GUFW, catering to both command-line enthusiasts and GUI users. By defining clear rules, monitoring traffic, and adhering to security best practices, you can safeguard your system against modern threats. Whether you’re hosting a web server or securing a personal desktop, a well-configured firewall is indispensable.

Further Reading

By mastering these tools, you’ll enhance your Linux Mint system’s security posture, ensuring peace of mind in an interconnected world.


Last modified 20.02.2025: new kotlin and mint content (93a1000)