Sponsored Content
Operating Systems Linux How to block only one IP using iptables? Post 302958361 by magnus29 on Wednesday 21st of October 2015 01:29:47 PM
Old 10-21-2015
How to block only one IP using iptables?

Hi friends,

I have a linux machine without iptables running and we have a new requirement to block a remote machine ( IP = 172.1.1.1 ) completely accessing our linux machine in both directions. So I need to allow "everything" except that IP address. So i tried below:

If I set the below in /etc/sysconfig/iptables file and do service iptables restart then everything is allowed (included the blocked IP)

Code:
# Default IPtables config
*filter
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT DROP [26:8868]

-A INPUT -j ACCEPT
-A OUTPUT -j ACCEPT

-A INPUT --src 172.1.1.1 -j REJECT
-A OUTPUT --dst 172.1.1.1 -j REJECT

COMMIT

If I try the below then it blocks everything

Code:
# Default IPtables config
*filter
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT DROP [26:8868]

-A INPUT --src 172.1.1.1 -j REJECT
-A OUTPUT --dst 172.1.1.1 -j REJECT

-A INPUT -j ACCEPT
-A OUTPUT -j ACCEPT


COMMIT

I'm new to iptables and not sure what am I doing wrong, appreciate if any expert could help me out here please Smilie
 

2 More Discussions You Might Find Interesting

1. 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

2. 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
IPTABLES-XML(8) 														   IPTABLES-XML(8)

NAME
iptables-xml -- Convert iptables-save format to XML SYNOPSIS
iptables-xml [-c] [-v] DESCRIPTION
iptables-xml is used to convert the output of iptables-save into an easily manipulatable XML format to STDOUT. Use I/O-redirection pro- vided by your shell to write to a file. -c, --combine combine consecutive rules with the same matches but different targets. iptables does not currently support more than one target per match, so this simulates that by collecting the targets from consecutive iptables rules into one action tag, but only when the rule matches are identical. Terminating actions like RETURN, DROP, ACCEPT and QUEUE are not combined with subsequent targets. -v, --verbose Output xml comments containing the iptables line from which the XML is derived iptables-xml does a mechanistic conversion to a very expressive xml format; the only semantic considerations are for -g and -j targets in order to discriminate between <call> <goto> and <nane-of-target> as it helps xml processing scripts if they can tell the difference between a target like SNAT and another chain. Some sample output is: <iptables-rules> <table name="mangle"> <chain name="PREROUTING" policy="ACCEPT" packet-count="63436" byte-count="7137573"> <rule> <conditions> <match> <p>tcp</p> </match> <tcp> <sport>8443</sport> </tcp> </conditions> <actions> <call> <check_ip/> </call> <ACCEPT/> </actions> </rule> </chain> </table> </iptables-rules> Conversion from XML to iptables-save format may be done using the iptables.xslt script and xsltproc, or a custom program using libxsltproc or similar; in this fashion: xsltproc iptables.xslt my-iptables.xml | iptables-restore BUGS
None known as of iptables-1.3.7 release AUTHOR
Sam Liddicott <azez@ufomechanic.net> SEE ALSO
iptables-save(8), iptables-restore(8), iptables(8) Jul 16, 2007 IPTABLES-XML(8)
All times are GMT -4. The time now is 05:00 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy