Networking Forums

Networking Forums > Computer Networking > Linux Networking > iptables rule to block external, but accept local port (8009) connection

Reply
Thread Tools Display Modes

iptables rule to block external, but accept local port (8009) connection

 
 
OtisUsenet
Guest
Posts: n/a

 
      02-14-2006, 07:56 AM
Hello,

I'm trying to use iptables to block external access to port 8009, while
keeping any local communication with port 8009 open. Port 8009 is a
servlet engine (e.g. Tomcat port). Apache (httpd) talks to Tomcat via
port 8009. Since I have both Tomcat and Apache on the same host, I
just want that host to be able to talk to port 8009, and nobody else.

I'm having only partial success:
I can successfully block external access, but I'm also noticing that my
rules are making some (not all) connections to/from port 8009 stay in
SYN_SENT state (netstat -tupan | grep 8009 shows this).

Here are my rules:

# this DROPs all packets for port 8009
$IPTABLES -A INPUT -p TCP --dport 8009 -m state --state NEW -j DROP
$IPTABLES -A INPUT -p UDP --dport 8009 -m state --state NEW -j DROP

# this alone should enable all traffic to/from loopback to pass through
# however, I don't recally know whether loopback device carries this
traffic....
$IPTABLES -A INPUT -i lo -j ACCEPT
$IPTABLES -A OUTPUT -o lo -j ACCEPT

# the above ACCEPT rules don't do it, so I've tried these
$IPTABLES -A INPUT -i lo -p TCP -s 127.0.0.1 -j ACCEPT
$IPTABLES -A OUTPUT -o lo -p TCP -s 127.0.0.1 -j ACCEPT
$IPTABLES -A INPUT -i lo -p TCP -s local.ip.here -j ACCEPT
$IPTABLES -A OUTPUT -o lo -p TCP -s local.ip.here -j ACCEPT
$IPTABLES -A INPUT -i eth0 -p TCP -s local.ip.here -j ACCEPT
$IPTABLES -A OUTPUT -o eth0 -p TCP -s local.ip.here -j ACCEPT

This still doesn't do it. I see that the connection from httpd -> port
8009 end up in SYN_SENT state, like this:

Proto Recv-Q Send-Q Local Address Foreign Address
State PID/Program name
tcp 0 1 127.0.0.1:58594 127.0.0.1:8009
SYN_SENT 24097/httpd
tcp 0 1 127.0.0.1:58595 127.0.0.1:8009
SYN_SENT 24099/httpd
tcp 0 1 127.0.0.1:58592 127.0.0.1:8009
SYN_SENT 24096/httpd
tcp 0 1 127.0.0.1:58593 127.0.0.1:8009
SYN_SENT 24098/httpd
....

Do you see any problems with my rules?
I've also tried using ".... -p TCP -d 127.0.0.1..." (the important
piece here being that "-d" in addition to "-s"), also without any luck.

Any help would be much appreciated.
Thanks!

 
Reply With Quote
 
 
 
 
Eric Lalitte
Guest
Posts: n/a

 
      02-14-2006, 08:10 AM
"OtisUsenet" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com
> # this DROPs all packets for port 8009
> $IPTABLES -A INPUT -p TCP --dport 8009 -m state --state NEW -j DROP
> $IPTABLES -A INPUT -p UDP --dport 8009 -m state --state NEW -j DROP


1- you should use --syn with TCP
2- you accept the syn in the connection, but no other packets...
That's why you see the SYN_sent state.

You should add first:
$IPTABLES -A INPUT -p TCP -m state --state ESTABLISHED, RELATED
\ -j ACCEPT

And, a very important thing:
The order of the rules in iptables does matter, a lot :-)
Iptables gets the firt matching rule, so be careful with the order of
them.



--
Posted via Mailgate.ORG Server - http://www.Mailgate.ORG
 
Reply With Quote
Reply

Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
iptables rule to block FTP-NAT-Helper-Traffic Kevin Kempfer Linux Networking 5 11-29-2008 09:08 PM
using iptables to block OUTBOUND port 25? deja3-user@bitrealm.com Linux Networking 6 02-18-2008 05:58 AM
iptables: rule with RETURN target just after a rule with ACCEPT target Neroku Linux Networking 0 04-25-2007 08:13 AM
iptables: rule with RETURN target after a rule with the ACCEPT target Neroku Linux Networking 0 04-24-2007 08:43 PM
iptables rule for ssh port forwarding Nicola Gatti Linux Networking 0 01-27-2004 10:38 AM



1 2 3 4 5 6 7 8 9 10 11