LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-21-2005, 02:50 PM   #1
ilnli
Member
 
Registered: Jul 2004
Location: Pakistan
Distribution: Slackware 10.0, SUSE 9.1, RH 7, 7.3, 8, 9, FC2
Posts: 413

Rep: Reputation: 32
iptables


Can any one provide me a customizable iptables script that have a very good logging capabilities.
 
Old 01-21-2005, 02:59 PM   #2
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
I can give you a decent example...

Code:
#!/bin/sh

#Change the part after the = to the where you IPTABLES is on your system
IPTABLES=/sbin/iptables

case "$1" in
  start|reload|restart)
        #flush existing rules
        ${IPTABLES} -F INPUT

        #This allows all data that has been sent out to get reply's back.
        ${IPTABLES} -A INPUT -j ACCEPT -m state --state ESTABLISHED -i eth0 -p icmp
        ${IPTABLES} -A INPUT -j ACCEPT -m state --state ESTABLISHED -i eth0 -p tcp
        ${IPTABLES} -A INPUT -j ACCEPT -m state --state ESTABLISHED -i eth0 -p udp

        #Allow incoming SSH requests
        ${IPTABLES} -A INPUT -p tcp --dport ssh -j ACCEPT

        #Allow incoming NTP - Disabled because I'm not running a time server:)
        #${IPTABLES} -A INPUT -p udp --dport ntp -j ACCEPT

        #Allow incoming netbios and microsoft-ds for Samba
        #Someday I might experiement to see which of these is actually required.
        #so I can close off the rest.
        ${IPTABLES} -A INPUT -p tcp --dport netbios-ssn -j ACCEPT
        ${IPTABLES} -A INPUT -p tcp --dport microsoft-ds -j ACCEPT
        ${IPTABLES} -A INPUT -p udp --dport netbios-ns -j ACCEPT
        ${IPTABLES} -A INPUT -p udp --dport netbios-dgm -j ACCEPT

        #Allow incoming ipp connections for network printing
        ${IPTABLES} -A INPUT -p tcp --dport ipp -j ACCEPT
        ${IPTABLES} -A INPUT -p udp --dport ipp -j ACCEPT

        #Drop and log all other data
        #The logging is set so if more than 5 packets are dropped in
        #three seconds they will be ignored. This helps to prevent a DOS attack
        #Crashing the computer the firewall is running on
        ${IPTABLES} -A INPUT -m limit --limit 3/second --limit-burst 5 -i ! lo -j LOG
        ${IPTABLES} -A INPUT -i ! lo -j DROP
        ;;
  stop)
        #flush existing rules
        ${IPTABLES} -F INPUT
        ;;
  status)
        ${IPTABLES} -L -v -n
        ;;
  *)
        echo "Usage: $0 {start|restart|reload|stop|status}"
        exit 1
esac

exit 0
That is the script I use. The logging is pretty self explainitory, it logs everything that is dropped unless the packets are coming to fast (don't want a DOS attack!).

If you want to add/remove ports just add/remove rules.
 
Old 01-21-2005, 03:02 PM   #3
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
Btw, if you wanted more logging you can easily add it.

Say I wanted to log SSH traffic.... I'd add a rule like this:

${IPTABLES} -A INPUT -p tcp --dport ssh -j LOG
 
Old 01-21-2005, 03:10 PM   #4
ilnli
Member
 
Registered: Jul 2004
Location: Pakistan
Distribution: Slackware 10.0, SUSE 9.1, RH 7, 7.3, 8, 9, FC2
Posts: 413

Original Poster
Rep: Reputation: 32
where should i add this rule I mean at which number ?
 
Old 01-21-2005, 03:14 PM   #5
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
For consistancy sake if I were logging ssh packets I'd add the rule right before the ssh ACCEPT rule but it really doesn't matter.
 
Old 01-22-2005, 12:53 AM   #6
ilnli
Member
 
Registered: Jul 2004
Location: Pakistan
Distribution: Slackware 10.0, SUSE 9.1, RH 7, 7.3, 8, 9, FC2
Posts: 413

Original Poster
Rep: Reputation: 32
any one else with something more great?
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
An error occured getting IPtables status from the command /etc/rc.d/init.d/iptables s CrazyMAzeY Linux - Newbie 10 08-12-2010 05:25 AM
Iptables - Couldn't load target `ACCPET':/lib/iptables/libipt_ACCPET.so: z00t Linux - Security 3 01-26-2004 02:24 AM
IPtables Log Analyzer from http://www.gege.org/iptables/ brainlego Linux - Software 0 08-11-2003 06:08 AM
iptables book wich one can you pll recomment to be an iptables expert? linuxownt Linux - General 2 06-26-2003 04:38 PM
My iptables script is /etc/sysconfig/iptables. How do i make this baby execute on boo ForumKid Linux - General 3 01-22-2002 07:36 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:43 PM.

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