LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 04-07-2006, 05:06 PM   #1
leosgb
Member
 
Registered: Nov 2004
Location: Brazil
Distribution: Gentoo
Posts: 363

Rep: Reputation: 31
iptables blocks services (HTTPS and FTP)


Hi,

I have been strugling with some problems here and I just realized they are caused by my firewall. I was wondering if anyone could give me some advice here. I am trying to get SSL to work w/ apache and it is all configured and running. If I stop iptables I can connect to it correctly. So the only cause can be iptables I have the same problem w/ my FTP server.

HTTPS --> port 443
FTP --> port 34012 (I would rather not use the standard port)

Can anyone help me, please?

My rules:
# Generated by iptables-save v1.3.5 on Fri Apr 7 12:38:27 2006
*raw
:PREROUTING ACCEPT [9397:898320]
:OUTPUT ACCEPT [9159:1463145]
COMMIT
# Completed on Fri Apr 7 12:38:27 2006
# Generated by iptables-save v1.3.5 on Fri Apr 7 12:38:27 2006
*nat
:PREROUTING ACCEPT [64:13883]
:POSTROUTING ACCEPT [27:3880]
:OUTPUT ACCEPT [27:3880]
COMMIT
# Completed on Fri Apr 7 12:38:27 2006
# Generated by iptables-save v1.3.5 on Fri Apr 7 12:38:27 2006
*filter
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [323:29805]
-A INPUT -p tcp -m multiport --dports 139,445 -j ACCEPT
-A INPUT -p udp -m multiport --dports 137,138 -j ACCEPT
-A INPUT -p udp -m udp --dport 67:69 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 137:139 -j ACCEPT
-A INPUT -s 127.0.0.1 -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -s 192.168.1.0/255.255.255.0 -p icmp -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A INPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-port-unreachable
-A INPUT -p udp -m udp --dport 137 -j ACCEPT
-A INPUT -p udp -m udp --dport 138 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 139 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 445 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 34012 -j ACCEPT
-A INPUT -p tcp -m tcp --sport 443 -j ACCEPT
-A INPUT -j DROP
-A OUTPUT -o lo -j ACCEPT
-A OUTPUT -p tcp -m tcp --sport 22 -j ACCEPT
-A OUTPUT -p tcp -m tcp --dport 443 -j ACCEPT
COMMIT
# Completed on Fri Apr 7 14:11:07 2006

Last edited by leosgb; 04-07-2006 at 05:17 PM.
 
Old 04-07-2006, 11:09 PM   #2
centauricw
Member
 
Registered: Dec 2005
Location: Lawrenceville GA
Distribution: Slackware, CentOS. Red Hat Enterprise Linux
Posts: 216

Rep: Reputation: 31
My guess from looking at the rules you posted is that it's the REJECT statement:

Quote:
...
-A INPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-port-unreachable
-A INPUT -p udp -m udp --dport 137 -j ACCEPT
...
The REJECT statement doesn't appear to have any constraints except that it's an input package, so everything that reaches this rule will be rejected and the rules after it will never be checked. Both your SSL and FTP rules are after this REJECT rule.
 
Old 04-08-2006, 11:42 AM   #3
leosgb
Member
 
Registered: Nov 2004
Location: Brazil
Distribution: Gentoo
Posts: 363

Original Poster
Rep: Reputation: 31
You are right. I moved that rule down and it worked. I wasnt aware that the rules were checked in the order they are written. Will be more careful next time. Now I can connect from everywhere except for making file transfers which indicates me that I dont have a valid data channel. I can issue all commands fine so I have a woring control channel. What other ports do I have to open to make sure transfers will take place?

I have this in my proftpd.conf:

PassivePorts 30098 30197

I am going to open them now and see what happens. Thanks for your reply!

----------------------------------
EDIT
I open those ports in my router and firewall and when I try to use it this is what i get:
for a "ls" command.
425 Unable to build data connection: Connection refused

All connections are being forwarded to my server now and all ports should be open. This is how I did it:
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpts:30098:30197

Can you help me?

Last edited by leosgb; 04-08-2006 at 11:57 AM.
 
Old 04-08-2006, 12:02 PM   #4
win32sux
Moderator
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 367Reputation: 367Reputation: 367Reputation: 367
make sure you have the ip_conntrack_ftp module loaded...
 
Old 04-09-2006, 04:09 AM   #5
booksh
LQ Newbie
 
Registered: Mar 2006
Location: qatar
Distribution: ubuntu 11.04 Natty Narwhal
Posts: 20

Rep: Reputation: 0
hi iam new member i hope get some help ..
 
Old 04-09-2006, 04:17 AM   #6
booksh
LQ Newbie
 
Registered: Mar 2006
Location: qatar
Distribution: ubuntu 11.04 Natty Narwhal
Posts: 20

Rep: Reputation: 0
i need to know about ip table .. (blocking and forward) which command type to do this ... iam wait ..
 
Old 04-09-2006, 05:57 AM   #7
pk21
Member
 
Registered: Jun 2002
Location: Netherlands - Amsterdam
Distribution: RedHat 9
Posts: 547

Rep: Reputation: 30
Why is the rule -A INPUT -p tcp -m tcp --sport 443 -j ACCEPT ??? I think it should be the destination port 443, not the source port.

A INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT

And as win32sux already mentioned, you should check if ip_conntrack_ftp module is loaded. Just type "lsmod" and see if it is in there.
 
Old 04-10-2006, 07:38 PM   #8
leosgb
Member
 
Registered: Nov 2004
Location: Brazil
Distribution: Gentoo
Posts: 363

Original Poster
Rep: Reputation: 31
I changed it. Thanks. But what was really blocking my https was this line:

-A INPUT -j REJECT --reject-with icmp-port-unreachable

It should be the last one not in the middle as it was before. After I moved it down I got it to work. But no success w/ my FTP yet. I believe it is a router problem.
 
Old 04-10-2006, 07:43 PM   #9
win32sux
Moderator
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 367Reputation: 367Reputation: 367Reputation: 367
did you confirm the ftp module is loaded??
 
Old 04-10-2006, 07:46 PM   #10
leosgb
Member
 
Registered: Nov 2004
Location: Brazil
Distribution: Gentoo
Posts: 363

Original Poster
Rep: Reputation: 31
I tried lsmod but nothing returned. I am running 2.6.15 Gentoo here.

Module Size Used by
snd_dummy 11328 0
s2io 57160 0
i2c_core 19712 0
nvidia 4855984 0

I guess it is built in the kernel:

grep TRACK .config
CONFIG_IP_NF_CONNTRACK=y <========= Right?
CONFIG_IP_NF_CONNTRACK_MARK=y
CONFIG_IP_NF_CONNTRACK_EVENTS=y
# CONFIG_IP_NF_CONNTRACK_NETLINK is not set
CONFIG_IP_NF_MATCH_CONNTRACK=y
# CONFIG_IP_NF_TARGET_NOTRACK is not set
 
Old 04-11-2006, 12:48 PM   #11
pk21
Member
 
Registered: Jun 2002
Location: Netherlands - Amsterdam
Distribution: RedHat 9
Posts: 547

Rep: Reputation: 30
Just try: insmod ip_conntrack_ftp
And check with lsmod if the module gets loaded.
 
Old 04-11-2006, 12:57 PM   #12
win32sux
Moderator
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 367Reputation: 367Reputation: 367Reputation: 367
Quote:
Originally Posted by leosgb
I tried lsmod but nothing returned. I am running 2.6.15 Gentoo here.

Module Size Used by
snd_dummy 11328 0
s2io 57160 0
i2c_core 19712 0
nvidia 4855984 0

I guess it is built in the kernel:

grep TRACK .config
CONFIG_IP_NF_CONNTRACK=y <========= Right?
CONFIG_IP_NF_CONNTRACK_MARK=y
CONFIG_IP_NF_CONNTRACK_EVENTS=y
# CONFIG_IP_NF_CONNTRACK_NETLINK is not set
CONFIG_IP_NF_MATCH_CONNTRACK=y
# CONFIG_IP_NF_TARGET_NOTRACK is not set
what you are pointing to there is just the general conntrack, not the FTP specific...

i'm on linux 2.4, but here's what my .config looks like, as well as the loaded module:

Code:
bash-3.1$ cat /boot/config | grep _FTP
CONFIG_IP_NF_FTP=m
CONFIG_IP_NF_NAT_FTP=m
bash-3.1$ /sbin/lsmod | grep ftp
ip_conntrack_ftp        3632   0 (unused)
ip_conntrack           18564   1 (autoclean) [ip_conntrack_ftp ipt_state iptable_nat]
 
Old 04-11-2006, 01:13 PM   #13
leosgb
Member
 
Registered: Nov 2004
Location: Brazil
Distribution: Gentoo
Posts: 363

Original Poster
Rep: Reputation: 31
Ok. I have it:
grep FTP /usr/src/linux/.config
CONFIG_IP_NF_FTP=y <<<<<====== built in.
# CONFIG_IP_NF_TFTP is not set
CONFIG_IP_NF_NAT_FTP=y <<<<<====== built in.

It works now. I changed it to the default port as suggested in a different thread. I will leave it as is for now since this is a temporary setup. Once my friend is done w/ his transfer I will kill proftpd again.

So, to help booksh, if this is what he is looking for:
0)make sure you have kernel requirements, you can check it by "grep PARAMETER /usr/src/linux/.config":
CONFIG_IP_NF_FTP=m or y (if you use module use lsmod to check if it loaded)
CONFIG_IP_NF_NAT_FTP=m or y
CONFIG_IP_NF_CONNTRACK=y or m
1) set the router to forward ports for FTP, here I used 20 and 21. Dont forget the passive mode ports too. I used 30098 to 30197.
2)open these ports in your firewall:
iptables -A INPUT -p tcp -m tcp --dport 30098:30197 -j ACCEPT
iptables -A INPUT -p tcp -m tcp --dport 21 -j ACCEPT
iptables -A INPUT -p tcp -m tcp --dport 20 -j ACCEPT
3)follow the instructions to setup proftpd that are easily available.
4)start the server, /etc/init.d/proftpd start
5)have fun!
 
  


Reply

Tags
help


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
iptables blocks access to network leupi Linux - Networking 3 03-29-2005 09:23 AM
iptables causes delay and blocks irrationally niehls Linux - Networking 4 08-21-2004 01:16 PM
https and other services kaboom Linux - General 4 01-04-2004 11:42 AM
Iptables and https sturla69 Linux - Security 6 09-16-2003 10:13 PM
FTP or HTTPS... ThecknoDecker Linux - Newbie 5 08-01-2003 02:45 PM


All times are GMT -5. The time now is 02:35 PM.

Main Menu
 
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
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration