iptables: syntax from drop AND log packets


 
Thread Tools Search this Thread
Special Forums IP Networking iptables: syntax from drop AND log packets
# 1  
Old 03-28-2011
iptables: syntax from drop AND log packets

Good afternoon everyone,
It's the iptables n00b again. valiantly learning and reading (and asking for occasional help when I hit a wall - which I think I just did)

So far I've gotten logging enabled for iptables.

Now, I want to drop AND log an IP connection attempt.

Could some wise eyes please confirm that to drop - AND LOG - an IP there are not one, but two rules which must be stuffed in there?

Let's say I want to prevent connections from 10.1.1.115 and log the attempt. The reading I've done so far seems to say I must do this:

Code:
iptables -A INPUT -s 10.1.1.115 -j LOG --log-prefix 'SWAMP-THING'--log-level 4 #or 7 maybe? I just need date/time/IP

iptables -A INPUT -s 10.1.1.115 -j DROP

I'm guessing there's no way to combine the two into a single command (which for brevity, I could maybe alias somehow?)

Regards & TIA for any suggestions and pointers (and expertise)

putter
# 2  
Old 03-28-2011
Yes, you always need 2 different rules. However, you can create a new chain (eg log-and-drop) that contains those 2 rules, and have your regular chains jump there if needed.
Code:
iptables -N log-and-drop # create new chain
iptables -A log-and-drop -j LOG --log-prefix 'SWAMP-THING'--log-level 4
iptables -A log-and-drop -J DROP

iptables -A INPUT -s 10.1.1.115 -j log-and-drop

You might also want to limit the number of log messages by using the (aptly named) limit module (described here), lest someone DoS' your server by filling the log file.
This User Gave Thanks to pludi For This Post:
# 3  
Old 03-28-2011
iptables: syntax from drop AND log packets

Quote:
Originally Posted by pludi
Yes, you always need 2 different rules. However, you can create a new chain (eg log-and-drop) that contains those 2 rules, and have your regular chains jump there if needed.
Code:
iptables -N log-and-drop # create new chain
iptables -A log-and-drop -j LOG --log-prefix 'SWAMP-THING'--log-level 4
iptables -A log-and-drop -J DROP

iptables -A INPUT -s 10.1.1.115 -j log-and-drop

You might also want to limit the number of log messages by using the (aptly named) limit module (Note from response - a URL quote pointing to the resource is disallowed below 5 posts by me - putter)
Wow - thanks on a number of levels for this. First and foremost for absolute clarity. I actually understand the guidance you've given.

Secondly for decoding some of the rather opaque writeups which have touched on this subject elsewhere, but which in themselves were not the easiest to understand.

Third by demystifying two other things (thus causing one of those rare and treasured "Eureka moments") - what a chain is, and what a jump is.

Time to read up on limits, try and "put it all together" and come back with something that hopefully looks ready to test.

Thanks so much, your help is hugely appreciated. Back later.

putter
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Red Hat

iptables applied in local machine, can't ssh remote machine after chain changed to DROP

I want to SSH to 192.168.1.15 Server from my machine, my ip was 192.168.1.99 Source Destination was UP, with IP 192.168.1.15. This is LAN Network there are 30 Machine's Connected to the network and working fine, I'm Playing around the local machine's because I need to apply the same rules in... (2 Replies)
Discussion started by: babinlonston
2 Replies

2. UNIX for Advanced & Expert Users

iptables - similar syntax to cisco acl

Hi All, can we write iptables rules on linux in a way similar to cisco acl ?? (2 Replies)
Discussion started by: coolatt
2 Replies

3. Linux

how to allow incoming UDP packets with iptables

I am looking for an iptables command to allow incoming UDP packets for my Linux server also is there a command I can use to set the default action for outgoing packets to accept? Thank you (1 Reply)
Discussion started by: crimputt
1 Replies

4. IP Networking

iptables syntax

Hi, Can someone help to explain what is --to-source in the iptables rule below: iptables -t nat -A POSTROUTING -s 192.168.1.100 -o eth0 \ -j SNAT --to-source 97.158.253.26 especially why the option has double dash (--) is it a comment? Thanks (1 Reply)
Discussion started by: plee61
1 Replies

5. UNIX for Advanced & Expert Users

copy packets from one port to another by iptables

I would like to copy data flow (not redirect!!!) from 1567 port to another 1194 port on same computer. The 1567 Port already binded by Scream program (it is bisy). Is it possible to do it by iptables or for it nesessary another programs? Can you help me in the decision of this question? (1 Reply)
Discussion started by: yanat
1 Replies

6. Cybersecurity

pass syntax iptables to ipfw

Hello, excuse my English. Please could tell me how I can pass this syntax for iptables to ipfw. iptables -A OUTPUT -p tcp --dport 80 -m state --state NEW -m recent --set --name thor --rdest -j ACCEPT iptables -A INPUT -p tcp -m tcp --tcp-flag RST RST -m state --state ESTABLISHED -m recent... (0 Replies)
Discussion started by: dot357
0 Replies

7. Cybersecurity

~ IPTables : Limit Incoming UDP Packets With a Certain Length ~

Hello, I am currently trying to limit incoming UDP length 20 packets on a per IP basis to 5 a second using IPTables on a Linux machine (CentOS 5.2). Basically, if an IP is sending more than 5 length 20 UDP packet a second to the local machine, I would like the machine to drop the excess... (1 Reply)
Discussion started by: tomboy123
1 Replies

8. UNIX for Advanced & Expert Users

Forwarding internal internet packets to internal webserver using iptables

Hi, I need to redirect internal internet requests to a auth client site siting on the gateway. Currently users that are authenticated to access the internet have there mac address listed in the FORWARD chain. All other users need to be redirected to a internal site for authentication. Can... (1 Reply)
Discussion started by: mshindo
1 Replies
Login or Register to Ask a Question