
Uncomplicated Firewall (UFW) is the default firewall configuration tool on Ubuntu and most of the debian based distributions. It offers a simplified interface for managing complex iptables rules, making it more straightforward to control incoming and outgoing traffic.
This article explains the most commonly used UFW commands to help secure your server.
Before you begin, you need to:
Check the status of the firewall. By default, UFW is active on Vultr Compute instances..
If the output displays the status as inactive, run the below command to enable UFW.
The command above enables UFW and instantly adds a rule to allow SSH, ensuring your session stays active.
Enable UFW
Activate the UFW firewall to start enforcing the configured rules.
Disable UFW
To disable the firewall and stop enforcing rules.
Reset UFW
To delete all existing rules and restore UFW to its default inactive state.
To guard your servers against unauthorized access and reduce exposure to potential threats, it's important to allow only the traffic necessary for your applications. This section demonstrates practical UFW configurations for common server scenarios, helping you build a secure and controlled network environment by explicitly permitting essential services while blocking all other unsolicited connections.
In this section, you configure UFW to allow only SSH connections and block all other inbound traffic. This setup provides a secure baseline for newly deployed servers that do not yet run public-facing services.
Set the default policies to deny all incoming traffic and allow all outgoing traffic.
Allow SSH connections.
View the ufw status.
Output:
To host websites or web applications, your server must be accessible over standard web ports. This configuration allows traffic for essential services HTTP (port 80), and HTTPS (port 443), while blocking all other unsolicited connections.
Allow HTTP traffic.
Allow HTTPS traffic.
View the ufw status.
Output:
To expose a specific service running on your server, you can allow traffic on its associated port. This is useful for enabling access to applications like databases, VPNs, or custom services.
To allow traffic on a specific port using the TCP protocol, such as MySQL (port 3306):
The command above allows the TCP traffic on port 3306.
To allow traffic on a specific port using the UDP protocol, such as for an OpenVPN server (port 1194):
The command above allows the UDP traffic on port 1194.
In cases where you want to limit access to specific, trusted sources such as office networks, VPN gateways, or monitoring systems you can allow traffic from a specific IP address.
To allow all traffic from a trusted IP:
To allow a trusted IP access to a specific port (e.g., SSH):
If you no longer need a rule or have added one incorrectly, you can remove it using its rule number.
Run the below command to list all the active rules with numbering:
Delete a rule using it's number.
In this article, you have explored how to secure your Linux server using UFW. You configured default firewall policies, allowed essential services like SSH and web traffic, opened specific ports and protocols, whitelisted trusted IP addresses, and also have deleted unwanted firewall rules.
0 Comments
Be the first to comment and share your perspective with the community.