You can use the iptables
command to drop traffic from a specific IP address in Linux. Here’s how:
- Open a terminal window.
- Run the following command to block incoming traffic from the IP address:
sudo iptables -A INPUT -s <ip_address> -j DROP
Where <ip_address>
is the IP address you want to block.
For example, to block incoming traffic from IP address 192.168.0.100
, you would run the following command:
sudo iptables -A INPUT -s 192.168.0.100 -j DROP
Note that the changes to iptables rules are not permanent and will be lost after a reboot. To make the changes permanent, you can save the iptables rules to a file and then restore the rules after each reboot. This can be done using the iptables-save
and iptables-restore
commands.
It’s important to be cautious when using iptables
to block traffic, as you can potentially block traffic that you need for your system to function properly. Before making any changes, make sure you understand what you’re doing and the potential consequences.