The ufw firewall is a powerful tool for securing your Linux system. It provides an easy-to-use interface for managing your firewall rules and can help protect your system from external threats. In this article, we will show you how to configure the ufw firewall on your Linux system.
Before we begin, it’s important to note that the ufw firewall is only available on Ubuntu and other Debian-based Linux distributions. If you are using a different Linux distribution, you will need to use a different firewall application.
To start, you will need to install the ufw firewall on your system. This can be done with the following command:
sudo apt-get install ufw
Once the ufw firewall is installed, you can start the firewall with the following command:
sudo ufw enable
This will start the ufw firewall and apply any default rules that are defined.
Next, you can configure the firewall rules. The ufw firewall uses a set of predefined rules to control incoming and outgoing network traffic. These rules are organized into three categories:
- Allow: Rules in this category allow incoming or outgoing traffic that matches the specified criteria.
- Deny: Rules in this category block incoming or outgoing traffic that matches the specified criteria.
- Reject: Rules in this category block incoming or outgoing traffic that matches the specified criteria and send a reply to the sender indicating that the connection has been rejected.
To add a new rule to the firewall, you can use the ufw
command followed by the rule type (allow
, deny
, or reject
), the protocol (tcp
, udp
, or icmp
), and the port or service name. For example, to allow incoming SSH connections, you can use the following command:
sudo ufw allow ssh
This will add a new rule to the firewall that allows incoming traffic on port 22
(the default port for SSH connections).
You can also specify a specific IP address or range of IP addresses for a rule. For example, to allow incoming connections from a specific IP address, you can use the following command:
sudo ufw allow from 192.168.1.100
This will add a new rule to the firewall that allows incoming traffic from the specified IP address.
To view the current firewall rules, you can use the ufw status
command. This will display a list of all the current rules, along with their status and the number of connections that have been allowed or denied by each rule.
To delete a rule, you can use the ufw delete
command followed by the rule number or name. For example, to delete the rule that allows incoming SSH connections, you can use the following command:
sudo ufw delete allow ssh
This will remove the rule from the firewall and prevent any new connections using that rule.
In summary, configuring the ufw firewall on your Linux system is a simple and effective way to secure your system from external threats. By using the ufw
command and a set of predefined rules, you can control the incoming and outgoing network traffic on your system and protect it from unauthorized access.