LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 03-24-2007, 08:40 PM   #1
t163r
LQ Newbie
 
Registered: Apr 2001
Posts: 15

Rep: Reputation: 0
iptables log new connections to ports


Hi

I would like to do the following and hope some can give some advice.

- Log any new incoming traffic on two known ports on my system.
- I only need the ip address that connects, no more info is needed.
- I don't need to know how often, so no duplicates of a single ip address is needed.
Meaning - If it's already logged, don't bother log it again. Hence the "new" in the first line here.
- Ignore (don't log) a list of "known" ip addresses

Is this possible? (The duplicate and known list stuff...)

I think I need to set up my own chain and build the rules in it, then apply it like this :
Code:
iptables -A INPUT -p tcp --dport 1234 -j LOGNEW
(where LOGNEW is my chain)

The reason is to monitor traffic to these two ports, if any, from others then the ip's on the known list.
I know I should just allow traffic in from the known list and block the rest, but they are on dhcp so...

Even just a hint in the right direction here would be very nice.

Thank you
 
Old 03-25-2007, 06:48 PM   #2
SiegeX
Member
 
Registered: Jul 2004
Location: Silicon Valley, CA
Distribution: Slackware
Posts: 171

Rep: Reputation: 38
Quote:
- I only need the ip address that connects, no more info is needed.
You really don't have much control over this, you can look into ulogd to send the logs to a different file or database via -j ULOG target.
Quote:
- I don't need to know how often, so no duplicates of a single ip address is needed.
Probably the best way to do this is to log only new connections to the port. This will not prevent multiple logs per IP but it will limit it by only recording one log per session. You could always do some post-processing of your logs if you want to remove duplicates, look into the 'uniq' command for that.

Quote:
- Ignore (don't log) a list of "known" ip addresses
This can be easy to accomplish if the list of "known" ip's are in an easy to define range. Otherwise this will require multiple rules, one per ip.

So for example, if you want to log new connections to ports 21 and 22 but allow known IP's in the range 1.2.3.0-1.2.3.255 to pass through unlogged I would do something like this.

iptables -N LOGNEW
iptables -A INPUT -i $WAN_IF -p tcp -m state --state NEW -m multiport --dports 21,22 -j LOGNEW
iptables -A LOGNEW -m iprange --src-range 1.2.3.0-1.2.3.255 -j RETURN
iptables -A LOGNEW -j ULOG --ulog-prefix "[LOGNEW] "

Note that $WAN_IF is a placeholder for whatever interface you want to do the logging on.

Last edited by SiegeX; 03-25-2007 at 06:50 PM.
 
  


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
Deleted /var/log/messages, can't log any files-iptables chingyenccy Linux - Newbie 7 02-27-2005 04:03 PM
Urgent: Opening ports for passive FTP connections in smoothwall? orange400 Linux - Networking 2 05-27-2004 05:15 AM
IPtables Log Analyzer from http://www.gege.org/iptables/ brainlego Linux - Software 0 08-11-2003 06:08 AM
iptables, changing log file from /var/log/messages acid2000 Linux - Networking 3 03-11-2003 08:38 PM
List of IP connections and Ports sarmadys Linux - Networking 1 12-06-2001 12:26 PM

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

All times are GMT -5. The time now is 12:35 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