LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian
User Name
Password
Debian This forum is for the discussion of Debian Linux.

Notices


Reply
  Search this Thread
Old 05-16-2010, 04:57 AM   #1
Anarion
LQ Newbie
 
Registered: Sep 2009
Posts: 13

Rep: Reputation: 0
iptables, problem with port 80


Hello Guys,
recently I have been working on iptables and trying to understand how to use it. Here's a little script I have written to setup a basic firewall for myself:
Code:
#!/bin/bash

if [ `id -u` -ne 0 ]; then
        echo "You need root privilege"
        exit 1
fi

PROG=/sbin/iptables

$PROG -F

function sethttp {
        echo "Opening http port..."
        $PROG -A INPUT -p tcp --dport 80 -j ACCEPT
}

function sethttps {
        echo "Opening https port..."
        $PROG -A INPUT -p tcp --dport 443 -j ACCEPT
}

function settorrent {
        echo "Opening torrent port..."
        $PROG -A INPUT -p tcp --dport 52413 -j ACCEPT
}

while getopts "hst" option; do
        case "$option" in
                h) sethttp;;
                s) sethttps;;
                t) settorrent;;
                *) echo "DOH!"
        esac
done

$PROG -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
$PROG -A OUTPUT -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
$PROG -A INPUT -i lo -j ACCEPT
$PROG -A OUTPUT -o lo -j ACCEPT
$PROG -A INPUT -j DROP
$PROG -A FORWARD -j REJECT

echo "Done setting up the firewall! Enjoy :)"
exit 0
OK, this can take 3 arguments that open ports 80, 443 and 52413. And at the end, some default rules are applied. But here's the thing I don't understand:
if I don't give the argument for port 80, I can still view web pages... and also, when I remove the line:
Code:
$PROG -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
Whether I say it to open port 80 or not, I can't view any web pages.

Would you please tell me what's the deal with that line?

Thanks
 
Old 05-16-2010, 09:32 AM   #2
Dutch Master
Senior Member
 
Registered: Dec 2005
Posts: 1,686

Rep: Reputation: 124Reputation: 124
I'm no iptables expert, not by a long shot , but I think the key is in the "established,related" part... Do note that the order (sequence) of rules applied matters! IPtables will apply the first rule that matches the incomming pattern, disgarding the rest of the chain.
 
  


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 Port Forwarding Problem fuze Linux - Networking 2 04-26-2009 01:55 AM
Port forwarding problem in iptables. vedang Linux - Server 15 01-17-2008 03:04 AM
Port Forwarding Problem using IPTABLES ^vampire^ Linux - Networking 1 10-12-2006 06:27 AM
iptables, port forward problem... wildwolf Linux - Security 11 01-12-2004 07:38 AM
IPTables Port Forwarding Problem delusi0n Linux - Networking 0 10-02-2001 01:34 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian

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