Firewalls are an important aspect of network security. They are designed to protect your system from unauthorized access and malicious traffic. In this blog post, we will show you how to set up a firewall using UFW (Uncomplicated Firewall) in Ubuntu.
Step 1: Install UFW
First, you need to install UFW on your Ubuntu system. To do this, open a terminal and enter the following command:
sudo apt-get install ufw
Step 2: Configure UFW
Once UFW is installed, you need to configure it to allow or deny traffic on specific ports. By default, UFW blocks all incoming traffic and allows all outgoing traffic.
To allow traffic on a specific port, use the following command:
sudo ufw allow <port>/<protocol>
For example, to allow incoming traffic on port 22 (used for SSH connections), you would use the following command:
sudo ufw allow 22/tcp
To deny traffic on a specific port, use the following command:
sudo ufw deny <port>/<protocol>
For example, to deny incoming traffic on port 80 (used for HTTP connections), you would use the following command:
sudo ufw deny 80/tcp
Step 3: Allow Access from Specific IP Addresses
In some cases, you may need to allow access to specific ports from certain IP addresses. To do this, you can use the following command:
sudo ufw allow from <IP address> to any port <port>/<protocol>
For example, to allow incoming traffic on port 22 only from the IP address 192.168.1.100, you would use the following command:
sudo ufw allow from 192.168.1.100 to any port 22/tcp
Step 4: Delete Rules
If you need to delete a rule, you can use the following command:
sudo ufw delete <rule number>
You can find the rule number by running the sudo ufw status numbered
command.
Step 5: Enable UFW
Once you have configured UFW, you can enable it by running the following command:
sudo ufw enable
This will activate the firewall and apply the rules you have configured.
Step 6: Check UFW Status
To check the status of UFW, you can use the following command:
sudo ufw status
This will show you the current status of UFW and the rules that are in effect.
Conclusion
By following these steps, you can configure your firewall to allow or deny traffic on specific ports, and allow access from specific IP addresses. This will help to protect your system from unauthorized access and malicious traffic.