LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 08-27-2006, 05:41 PM   #1
blkcamarozr28
Member
 
Registered: Oct 2005
Location: Honolulu, Hawaii
Distribution: Fedora Core 1-7, CentOS 4/5, Ubuntu/Xubuntu
Posts: 63

Rep: Reputation: 15
Question IPTABLES: How do you log denied packets


How do you log the deny & permitted packets when using IPTABLES? From time to time I need to write custom rules so being able to see what is being denied helps a lot.

My system runs CentOS4.3 & FC1-5. Thanks!


Wilson
 
Old 08-27-2006, 06:16 PM   #2
fotoguy
Senior Member
 
Registered: Mar 2003
Location: Brisbane Queensland Australia
Distribution: Custom Debian Live ISO's
Posts: 1,291

Rep: Reputation: 62
You will need to adjust these to your system and place them at the bottom of the script after your allow rules, some custom logging rules will look like this:

Code:
iptables -A INPUT -p tcp -j LOG --log-prefix "TCP LOGDROP: "
iptables -A INPUT -p udp -j LOG --log-prefix "UDP LOGDROP: "
iptables -A INPUT -p icmp -j LOG --log-prefix "ICMP LOGDROP: "
iptables -A INPUT -f -j LOG --log-prefix "FRAGMENT LOGDROP:  "
iptables -A INPUT -j DROP # make sure anything is drop after logging

These are pretty generic you may need to read up on iptables to find out how to use these rules properly

Last edited by fotoguy; 08-27-2006 at 06:18 PM.
 
Old 08-27-2006, 08:32 PM   #3
blkcamarozr28
Member
 
Registered: Oct 2005
Location: Honolulu, Hawaii
Distribution: Fedora Core 1-7, CentOS 4/5, Ubuntu/Xubuntu
Posts: 63

Original Poster
Rep: Reputation: 15
Thanks! Does this automatically put the logs in /var/log/messages?
 
Old 08-27-2006, 10:46 PM   #4
fotoguy
Senior Member
 
Registered: Mar 2003
Location: Brisbane Queensland Australia
Distribution: Custom Debian Live ISO's
Posts: 1,291

Rep: Reputation: 62
Yes it should send all logs to /var/log/messages. Then if you want to view them you could make a cron job, or just run a script to find the logged packets and copy them to another file for easier viewing, or emailing to someone later.

Code:
#!/bin/sh
grep "TCP LOGDROP:" /var/log/messages >> /text/file/somewhere.txt
grep "UDP LOGDROP:" /var/log/messages >> /text/file/somewhere.txt
grep "ICMP LOGDROP:" /var/log/messages >> /text/file/somewhere.txt
grep "FRAGMENT LOGDROP:" /var/log/messages >> /text/file/somewhere.txt
exit 0
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
log dropped packets from queue exeon Linux - Networking 2 03-26-2005 09:36 AM
Deleted /var/log/messages, can't log any files-iptables chingyenccy Linux - Newbie 7 02-27-2005 04:03 PM
Is it possible to log packets in/out of a specific port? jon_k Linux - Software 5 08-12-2004 06:07 AM
iptables, changing log file from /var/log/messages acid2000 Linux - Networking 3 03-11-2003 08:38 PM
Snort to log ALL packets, and print them to the console?!? bripage Linux - Security 5 10-01-2002 08:40 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 11:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration