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

Rep: Reputation: 30
Why this script cannot enable surfing?


Dear friends,

I have the following firewall script, all I want to experiment is a script that stops everything else but allow internet surfing. the script is as follow:

#!/bin/sh

iptables="/sbin/iptables"

$iptables -P FORWARD DROP
$iptables -P INPUT DROP
$iptables -P OUTPUT DROP


$iptables -A OUTPUT -p tcp -m state --state NEW --destination-port 80 -j ACCEPT

$iptables -A OUTPUT -p udp -m state --state NEW --destination-port 53 -j ACCEPT

$iptables -A OUTPUT -p tcp -m state --state NEW --destination-port 53 -j ACCEPT

$iptables -A INPUT -p tcp -m state --state ESTABLISHED,RELATED --destination-port 80 -j ACCEPT

$iptables -A INPUT -p udp -m state --state ESTABLISHED,RELATED --destination-port 53 -j ACCEPT

$iptables -A INPUT -p tcp -m state --state ESTABLISHED,RELATED --destination-port 53 -j ACCEPT
echo "firewall rules applied"

As seen above, i have enabled DNS port 53, http port 80 but it doesn't allow internet surfing...where did I go wrong here?

thanks for takin time reading my thread...thanks a lot.

regards
Fong
 
Old 12-24-2005, 04:12 PM   #2
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
give this cleaned-up version of your script a shot:
Code:
#!/bin/sh

iptables="/sbin/iptables"

echo "0" > /proc/sys/net/ipv4/ip_forward

$iptables -F
$iptables -F -t nat
$iptables -F -t mangle

$iptables -X
$iptables -X -t nat
$iptables -X -t mangle

$iptables -P FORWARD DROP
$iptables -P INPUT DROP
$iptables -P OUTPUT DROP

$iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
$iptables -A OUTPUT -o lo -j ACCEPT
$iptables -A OUTPUT -p tcp -m state --state NEW --dport 80 -j ACCEPT
$iptables -A OUTPUT -p udp -m state --state NEW --dport 53 -j ACCEPT
$iptables -A OUTPUT -p tcp -m state --state NEW --dport 443 -j ACCEPT

$iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
$iptables -A INPUT -i lo -j ACCEPT

echo "firewall rules applied"

Last edited by win32sux; 12-24-2005 at 04:45 PM.
 
Old 12-24-2005, 04:24 PM   #3
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Mint, MX, antiX, SystemRescue
Posts: 2,337

Rep: Reputation: 358Reputation: 358Reputation: 358Reputation: 358
Quote:
Originally Posted by Niceman2005
$iptables -A OUTPUT -p tcp -m state --state NEW --destination-port 80 -j ACCEPT
The above rule will allow your outgoing requests to port 80 (web surfing traffic) for initial connections (SYN), but it won't allow subsequent packets (ACK, etc.) I don't believe. This because you limited the rule to "--state NEW". I'd modify it to:

$iptables -A OUTPUT -p tcp --destination-port 80 -j ACCEPT

Quote:
$iptables -A INPUT -p tcp -m state --state ESTABLISHED,RELATED --destination-port 80 -j ACCEPT
I think you intended for this rule to allow the incoming replies to your web surfing traffic, but it won't. You limited it to only things coming in on port 80, which is not where you web surfing replies will be coming. These replies will be coming back to higher numbered ports (random). Ports above 1025. Simply remove the "--destination-port 80" part so your rule looks like this:

$iptables -A INPUT -p tcp -m state --state ESTABLISHED,RELATED -j ACCEPT
 
Old 12-25-2005, 01:31 AM   #4
Niceman2005
Member
 
Registered: Nov 2004
Distribution: Fedora Core 2
Posts: 330

Original Poster
Rep: Reputation: 30
thanks a lot friends!

Your help helped me to understand better now. thanks a lot!
 
Old 01-09-2006, 04:37 AM   #5
fotoguy
Senior Member
 
Registered: Mar 2003
Location: Brisbane Queensland Australia
Distribution: Custom Debian Live ISO's
Posts: 1,291

Rep: Reputation: 62
Is this running on a router with 2 network cards or a workstation with a single network card?
 
Old 01-09-2006, 05:55 AM   #6
Niceman2005
Member
 
Registered: Nov 2004
Distribution: Fedora Core 2
Posts: 330

Original Poster
Rep: Reputation: 30
This one I am working on a workstation.
Its ok now, I gradually understood the concept already.
thanks a lot
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Anonymous surfing ? Tanc Linux - Newbie 8 11-02-2010 04:54 AM
Enable a second X server with a script. Linux.tar.gz Linux - Software 4 05-26-2005 10:32 PM
Anonymous Surfing tiredoflogins General 2 10-18-2004 03:23 AM
Surfing The Internet carlgulliver100 Linux - Networking 0 02-11-2004 03:14 PM
Surfing without KDE etc. sourceman Linux - General 12 06-26-2002 04:26 PM

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

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