How to block an IP address with ufw on Ubuntu Linux server

How to block an IP address with ufw on Ubuntu Linux server

To block an IP address with the Uncomplicated Firewall (ufw) on an Ubuntu Linux server, you can use the deny command. For example, to block the IP address 198.51.100.1, you can run the following command:

refer t‮tual:o‬turi.com
sudo ufw deny from 198.51.100.1

This will add a rule to the firewall to block all incoming traffic from the specified IP address.

You can also use the reject command to block an IP address and send an error message to the sender. For example:

sudo ufw reject from 198.51.100.1

This will add a rule to the firewall to block all incoming traffic from the specified IP address and send an error message to the sender.

It's worth noting that these rules apply to incoming traffic only. If you want to block outgoing traffic to a specific IP address, you can use the deny out or reject out command instead. For example:

sudo ufw deny out to 198.51.100.1

This will add a rule to the firewall to block all outgoing traffic to the specified IP address.

To view the current firewall rules, you can use the ufw status command. This will display a list of the active firewall rules, including any rules that you have added to block specific IP addresses.

sudo ufw status

You can also use the ufw delete command to remove specific firewall rules. For example, to delete the rule that blocks incoming traffic from the IP address 198.51.100.1, you can run the following command:

sudo ufw delete deny from 198.51.100.1

This will remove the rule from the firewall, allowing incoming traffic from the specified IP address to pass through.

Created Time:2017-10-28 21:38:58  Author:lautturi