How to block only one IP using iptables?


 
Thread Tools Search this Thread
Operating Systems Linux How to block only one IP using iptables?
Prev   Next
# 4  
Old 11-06-2015
How to block only one IP using iptables?

In order to block an IP on your Linux server you need to use iptables tools (administration tool for IPv4 packet filtering and NAT) 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:


Syntax to block an IP address under Linux

Code:
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 65.55.44.100 for whatever reason then type the command as follows:
Code:
# iptables -A INPUT -s 65.55.44.100 -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 65.55.44.100 to port 25 then type command:
Code:
# iptables -A INPUT -s 65.55.44.100 -p tcp --destination-port 25 -j DROP

The above rule will drop all packets coming from IP 65.55.44.100 to port mail server port 25.

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

Type the following two command:
Code:
# iptables -A INPUT -s 65.55.44.100 -j DROP
# service iptables save


Moderator's Comments:
Mod Comment Use code tags, thanks.

Last edited by zaxxon; 11-06-2015 at 03:55 AM.. Reason: code tags
 
Login or Register to Ask a Question

Previous Thread | Next Thread

2 More Discussions You Might Find Interesting

1. Red Hat

Block an IP for a subnet by iptables

Hi I am looking to block an incomming IP for all the subnet in lab area. Only single Ip from Lab should be access to this incomming IP. Block IP=10.20.50.xx Subnet=10.30.40.xx ............................ ........................... Subnet=10.40.50.xx can anyone explain how to do... (2 Replies)
Discussion started by: boby.kumar
2 Replies

2. Cybersecurity

iptables: block/allow ftp

I have 2 LAN's, seperated by a firewall, running iptables on it. I want only allow ftp access from one to the other LAN. Server 1 in LAN 1 should have ftp access to Server 2 in LAN 2 Server 2 in LAN 2 should not have ftp access to Server 1 in LAN 1. Can someone tell me how to set up the... (5 Replies)
Discussion started by: sTorm
5 Replies
Login or Register to Ask a Question