• About Us
  • Disclaimer
  • Indeks
Kebumen Update
No Result
View All Result
  • Web Hosting and Server Management
  • Monitoring & Maintenance
  • Security & Hardening
  • Panels & Tools
  • Cloud & DevOps
  • Tech
  • Web Hosting and Server Management
  • Monitoring & Maintenance
  • Security & Hardening
  • Panels & Tools
  • Cloud & DevOps
  • Tech
No Result
View All Result
Kebumen Update
No Result
View All Result
Home Security & Hardening

How to Secure Your Linux Server with UFW Firewall

awbsmed by awbsmed
April 12, 2025
in Security & Hardening
0
How to Manage a Firewall on Linux (UFW) - This will secure your network.
ADVERTISEMENT

 

When it comes to securing a Linux server, one of the most effective tools at your disposal is a firewall. UFW (Uncomplicated Firewall) is a simple-to-use, yet powerful tool for managing your firewall rules. It’s available by default on many Linux distributions, especially Ubuntu, and is designed to make configuring firewall rules as easy as possible. UFW can protect your server from a variety of threats, including unauthorized access, DDoS attacks, and other common network-based vulnerabilities.

READ ALSO

Fortifying Digital Assets to Explain Secure Hosting

Installing Let’s Encrypt SSL on Your VPS (Free & Easy)

This guide will walk you through the process of setting up and configuring UFW on your Linux server. Whether you’re hosting a personal website or running an enterprise application, following these steps will help you bolster your server’s security significantly.


A. Why UFW?

UFW is a front-end to iptables, the standard firewall for Linux systems. It simplifies the management of firewall rules by providing a command-line interface to iptables, without the need to understand its complex syntax. Here’s why you should consider using UFW:

A. User-Friendly: UFW is specifically designed to be easy for beginners.
B. Effective: Even though it’s simple to use, UFW is powerful and effective at blocking unwanted traffic.
C. Preconfigured Rules: It comes with basic, sensible default rules that you can customize to suit your needs.
D. Integration with Other Tools: It works well with other system tools like fail2ban, which helps to protect your server from brute-force attacks.


B. Installing UFW

Before you can start using UFW, you need to install it on your server. Most modern Linux distributions, such as Ubuntu, come with UFW pre-installed. If not, you can easily install it using your package manager.

1. Install UFW on Ubuntu/Debian

To install UFW on a system that doesn’t already have it, use the following commands:

bash
sudo apt update
sudo apt install ufw

2. Install UFW on CentOS/RHEL

If you are using a Red Hat-based system, UFW is not available in the default repositories, but you can install it from the EPEL repository.

bash
sudo yum install epel-release
sudo yum install ufw

After installation, UFW is ready to be configured.


C. Enabling UFW

After installation, you need to enable UFW for it to start protecting your server. But before doing that, make sure that you don’t lock yourself out of the system. If you are connected via SSH, allow SSH connections first.

1. Allow SSH Connections

Before enabling UFW, allow SSH connections to ensure that you don’t lose access to your server:

bash
sudo ufw allow ssh

This will ensure that the firewall doesn’t block incoming SSH connections, which are essential for remote management.

2. Enable UFW

Once SSH is allowed, enable the firewall:

bash
sudo ufw enable

You’ll see a message asking you to confirm that you want to proceed. After you confirm, UFW will start and automatically apply the default rules.

3. Check UFW Status

You can verify that UFW is active and see the default rules by running:

bash
sudo ufw status verbose

This will display the active status and any rules that are in place. By default, UFW will block all incoming connections and allow outgoing connections.


D. Configuring UFW Rules

Now that UFW is up and running, it’s time to configure your firewall rules. UFW operates based on a default deny policy, meaning it will block all incoming traffic unless you explicitly allow it. Below are some common rules and their descriptions.

1. Allowing HTTP and HTTPS Traffic

If you’re hosting a website, you’ll need to allow HTTP (port 80) and HTTPS (port 443) traffic:

bash
sudo ufw allow http
sudo ufw allow https

Or you can use port numbers directly:

bash
sudo ufw allow 80
sudo ufw allow 443

2. Allowing SSH Traffic

SSH is crucial for remote administration, so make sure to allow SSH traffic:

bash
sudo ufw allow ssh

Alternatively, if you are using a non-standard port for SSH, you can specify the port:

bash
sudo ufw allow 2222/tcp

This will allow SSH traffic on port 2222.

3. Allowing Other Services

If you need to allow other services, such as FTP or MySQL, you can add them similarly:

bash
sudo ufw allow ftp
sudo ufw allow mysql

You can also specify ports directly:

bash
sudo ufw allow 21/tcp
sudo ufw allow 3306/tcp

4. Allowing Specific IP Addresses

Sometimes, you may want to allow access only from specific IP addresses. This is useful for allowing trusted users to access your server while blocking others.

For example, to allow SSH only from a specific IP:

bash
sudo ufw allow from 192.168.1.100 to any port 22

This rule allows SSH traffic only from the IP address 192.168.1.100.

5. Denying Unwanted Traffic

If you want to block specific IP addresses or ports, you can use the deny option:

bash
sudo ufw deny 21
sudo ufw deny from 192.168.1.200

This blocks FTP traffic on port 21 and denies access from the IP 192.168.1.200.


E. Managing UFW Rules

Once you’ve configured your firewall rules, you might need to modify or delete them. Here’s how:

1. Listing All Rules

You can list all the rules that have been applied using the following command:

bash
sudo ufw status numbered

This will display the rules in a numbered format, which will make it easier to delete specific rules.

2. Deleting Rules

To delete a rule, you can use the following command with the rule number from the previous step:

bash
sudo ufw delete 1

This will remove the first rule from the list.

3. Disabling UFW

If you ever need to disable UFW (for troubleshooting or other reasons), you can do so with:

bash
sudo ufw disable

However, be sure to re-enable it once you’ve finished troubleshooting:

bash
sudo ufw enable

F. Logging and Monitoring UFW

UFW has logging capabilities that allow you to monitor and keep track of traffic being blocked or allowed by your firewall. You can enable logging with the following command:

bash
sudo ufw logging on

By default, UFW logs messages to /var/log/ufw.log. You can check the logs using:

bash
sudo tail -f /var/log/ufw.log

This is particularly useful for diagnosing security issues or investigating potential intrusions.


G. Advanced UFW Configuration

While the default UFW setup is sufficient for most users, advanced configurations can provide additional layers of security for your server.

1. Rate Limiting

To prevent brute-force attacks on services like SSH, you can enable rate limiting. This will limit the number of connections that can be made within a certain time frame:

bash
sudo ufw limit ssh

This command limits SSH connections to 6 attempts per minute.

2. Custom Rules

For more advanced users, UFW allows you to define custom rules. For instance, you can allow or deny traffic based on IP address, protocol, or port. Here’s an example of a custom rule that allows traffic from a specific network:

bash
sudo ufw allow from 192.168.1.0/24 to any port 8080

This allows traffic from the IP range 192.168.1.0/24 on port 8080.


H. Best Practices for UFW Security

To ensure your server remains secure, here are a few best practices to follow:

A. Only open necessary ports: Keep your server’s open ports to a minimum.
B. Use IP whitelisting for critical services: Restrict access to your SSH or database server to trusted IPs.
C. Use strong, unique passwords for all accounts: Combine this with SSH key authentication for even more security.
D. Enable logging: Keep an eye on traffic and potential attacks with UFW’s logging feature.
E. Test your firewall configuration: Use tools like nmap to test open ports and verify that the firewall is working as expected.


Conclusion

Securing your Linux server with UFW is a powerful, straightforward way to block unwanted traffic and protect your server from common network attacks. By following this guide, you now know how to install, configure, and manage UFW, as well as some advanced security techniques to further harden your server.

By keeping your firewall rules organized, monitoring logs, and applying best practices, you can ensure that your server remains secure and resistant to external threats.

Tags: configure UFWfirewall rulesLinux securityserver firewallserver securityUbuntu firewall setupUFW firewallUFW management
ADVERTISEMENT

Related Posts

Fortifying Digital Assets to Explain Secure Hosting
Security & Hardening

Fortifying Digital Assets to Explain Secure Hosting

July 25, 2025
How to install Let's Encrypt SSL using DirectAdmin | LinuxCloudVPS Blog
Security & Hardening

Installing Let’s Encrypt SSL on Your VPS (Free & Easy)

April 12, 2025
Securing SSH Access on Your Ubuntu Server // Step-by-Step Tutorial
Security & Hardening

SSH Hardening: Disable Root Login & Use Key Authentication

April 12, 2025
Top 10 Best Practices for Secure Software Development
Security & Hardening

10 Essential Server Security Practices You Shouldn’t Ignore

April 12, 2025
Next Post
Securing SSH Access on Your Ubuntu Server // Step-by-Step Tutorial

SSH Hardening: Disable Root Login & Use Key Authentication

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

High-Performance Servers Ensure Future-Proof Tech

High-Performance Servers Ensure Future-Proof Tech

by Salsabilla Yasmeen Yunanta
August 26, 2025
0

The year 2025 marks a new era in the world of computing, where the demand for speed, efficiency, and scalability...

Server Boosts Become A Strong Mechanism for Communities

Server Boosts Become A Strong Mechanism for Communities

by Salsabilla Yasmeen Yunanta
July 31, 2025
0

In the rapidly expanding digital landscape, where online communities thrive as hubs for connection, collaboration, and shared interests, the concept...

Advance Server Allows Game Developers to Optimize Feedback

Advance Server Allows Game Developers to Optimize Feedback

by Salsabilla Yasmeen Yunanta
July 31, 2025
0

In the fast-paced, ever-evolving world of online gaming, where user experience and competitive balance are paramouthe purpose, operational mechanics, and...

Powering Digital: Backend Innovations Surge

Powering Digital: Backend Innovations Surge

by Salsabilla Yasmeen Yunanta
July 25, 2025
0

The visible elegance of a website or mobile application, the smooth user experience, and the instant responsiveness we've come to...

Kebumen Update

KebumenUpdate.com diterbitkan oleh PT BUMI MEDIA PUBLISHING dengan sertifikat pendirian Kementerian Hukum dan Hak Asasi Manusia Republik Indonesia Nomor: AHU-012340.AH.01.30.Tahun 2022

  • About Us
  • Editor
  • Code of Ethics
  • Privacy Policy
  • Cyber Media Guidelines

Copyright © 2025 Kebumen Update. All Right Reserved

No Result
View All Result
  • Homepages
    • Home Page 1
    • Home Page 2
  • Tech

Copyright © 2025 Kebumen Update. All Right Reserved