LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 11-06-2005, 06:05 AM   #1
Niceman2005
Member
 
Registered: Nov 2004
Distribution: Fedora Core 2
Posts: 330

Rep: Reputation: 30
my firewall script: unable to understand its function


Dear friends,

I wrote an ultra simple firewall script but is struggling to understand some issues about it.
A scope of my original script is as follow:

1)
$iptables -P FORWARD DROP
$iptables -P INPUT DROP
$iptables -A INPUT -p ALL -m state --state ESTABLISHED,RELATED -j ACCEPT

the above script works fine. i was able to surf the internet and the firewall runs.

Then i tried to experiment a bit by changing the -p ALL to -p tcp instead, as follow:

2)
$iptables -P FORWARD DROP
$iptables -P INPUT DROP
$iptables -A INPUT -p tcp -m state --state ESTABLISHED,RELATED -j ACCEPT

Upon changing the -p ALL -to -p tcp, internet surfing seems to be blocked. I am suspecting it is something to do with dns, so i tried with the following addition:

3)
$iptables -P FORWARD DROP
$iptables -P INPUT DROP
$iptables -A INPUT -p tcp -m state --state ESTABLISHED,RELATED -j ACCEPT
$iptables -A INPUT -p udp -m state --state NEW,ESTABLISHED,RELATED --destination-port 53 -j ACCEPT

but it doesn't work....
Actually, I can simply use the first script, internet surfing is fine with the first script. But I am just curious...so i tried to experiment...just can't understand why the 3) script doesn't work...

Thanks a lot for taking time reading my thread...thanks a lot.

Regards
Yong
 
Old 11-06-2005, 08:06 AM   #2
Grim Reaper
Member
 
Registered: Apr 2002
Distribution: Gentoo 2006.0 AMD64
Posts: 399

Rep: Reputation: 30
I don't know if this will fix your problem or not, but when I was experimenting recently, I found that you need to allow both TCP and UDP for DNS to work.. so try 3) as:

$iptables -P FORWARD DROP
$iptables -P INPUT DROP
$iptables -A INPUT -p tcp -m state --state ESTABLISHED,RELATED -j ACCEPT
$iptables -A INPUT -p udp -m state --state NEW,ESTABLISHED,RELATED --destination-port 53 -j ACCEPT
$iptables -A INPUT -p tcp -m state --state NEW,ESTABLISHED,RELATED --destination-port 53 -j ACCEPT

just a quick idea..
 
Old 11-06-2005, 12:11 PM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
First of all I hope the script you showed us wasn't the full script because you're missing some things. If it is, please check out the LQ FAQ: Security references for pointers to Iptables scripts, especially the .*guru scripts.


I don't know if this will fix your problem or not, but when I was experimenting recently, I found that you need to allow both TCP and UDP for DNS to work..
True, but you're *making* the requests, so that means --state NEW outbound, and --state ESTABLISHED,RELATED inbound. You only need --state NEW inbound if you're hosting a DNS server (say a caching server for your LAN).

Returning to your original question. If something doesn't work the first thing to look for (goes for *everything*) is to check error and debug output. For that Iptables needs "-j LOG" rules before the "decision":

# First rule match, so INPUT will ACCEPT for debugging purposes
$iptables -P INPUT ACCEPT
# Not forwarding for other hosts, so DROP it
$iptables -P FORWARD DROP
# Stating the obvious
$iptables -P OUTPUT ACCEPT
# Not running servers, so DROP that
$iptables -A INPUT -m state --state NEW -j LOG --log-prefix="IN_DROP_SYN "
$iptables -A INPUT -m state --state NEW -j DROP
# Drop these too
$iptables -A INPUT -m state --state INVALID -j LOG --log-prefix="IN_DROP_INV "
$iptables -A INPUT -m state --state INVALID -j DROP
# Responses
$iptables -A INPUT -p tcp -m state --state ESTABLISHED,RELATED -j ACCEPT
# LOG everything else that doesn't match protocol and state
$iptables -A INPUT -j LOG --log-prefix="IN_DROP_REST "
# Now we got that logged, DROP it like its hot
$iptables -A INPUT -j DROP

Run it for a while and then check your logs for the DROP lines to see which hosts get traffic dropped that *seems* legitimate.
 
Old 11-16-2005, 07:21 PM   #4
Niceman2005
Member
 
Registered: Nov 2004
Distribution: Fedora Core 2
Posts: 330

Original Poster
Rep: Reputation: 30
Hi guys,

thanks a lot for helping!!
 
  


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
iptables; ACK/SYN/etc; understand the bits, and potential firewall entries TheLinuxDuck Linux - Security 2 10-18-2011 09:17 PM
unable to step through function in shared object library using gdb markhod Programming 2 01-03-2009 02:00 AM
Need to understand Firestarter/firewall flashl Linux - Security 6 03-02-2005 06:30 AM
slackware's /etc/rc.d/rc.firewall equivalent ||| firewall script startup win32sux Debian 1 03-06-2004 09:15 PM
Firewall to function as gateway for dhcpd dengi Linux - Networking 1 10-06-2003 07:43 PM

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

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