How to block IP address on a Linux Server

To block an IP on your Linux server you need to use iptables tools  and netfilter firewall. First you need to log into shell as root user. To block an IP address you need to type the iptables command as follows:

iptables -A INPUT -s IP-ADDRESS -j DROP

Replace IP-ADDRESS with your actual IP address. For example, if you wish to block an ip address 209.175.453.23 for whatever reason then type the command as follows:

iptables -A INPUT -s 209.175.453.23 -j DROP

If you have IP tables firewall script, add the above rule to your script.If you just want to block access to one port from an ip 209.175.453.23 to port 22 then type command:

# iptables -A INPUT -s 209.175.453.23 -p tcp --destination-port 22 -j DROP


CentOS / RHEL / Fedora Block An IP And Save It To Config File

Type the following two command:

# iptables -A INPUT -s 209.175.453.23 -j DROP
# service iptables save

HOW TO UNBLOCK AN IP ADDRESS ON A LINUX SERVER

 

Use the following syntax (the -d options deletes the rule from table):


# iptables -D INPUT -s 
209.175.453.23 -j DROP
# service iptables save

  • centos, linux-server, server
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Change HostName in CentOS 7 / RHEL 7

Method 1 : nmcli To view the current hostname : # nmcli general hostname...

How to delete terminal history in Linux

You can clear your bash history like this: cat /dev/null > ~/.bash_history && history...

How to change SSH Port in Linux

# vi /etc/ssh/sshd_configYou have to change port 22 to whatever you want#Port 22 #ta delete kore...

How to install wget on CentOS 7/8

The procedure to install wget command is as follows on CentOS Linux 7/8: Open a terminal...

How to install Webuzo on CentOS 7

Requirements Newly installed CentOS 6.x / 7.x or Red Hat Enterprise Linux 6.x / 7.x or...