LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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
  Search this Thread
Old 08-15-2002, 03:53 AM   #1
Chou
LQ Newbie
 
Registered: Aug 2002
Location: Singapore
Posts: 7

Rep: Reputation: 0
Question Ftp server through a router


I am trying to set up an ftp server that is accessible from the internet.

I have no problems logging into the ftp from other LAN computers, but I can't get a response when trying to log in from another computer on the internet.

My network looks like is:
LAN <-> [eth0] gateway with ftp server [eth1] <-> hardware DSL router <-> internet

The DSL router is set up to do NAT. I have set a rule to forward incoming packets to port 21 to the gateway.

Any ideas where I might be missing a step? Are there any network tools that I can use to check if I'm getting any incoming requests at the gateway's eth1?

Any help would be appreciated.
 
Old 08-15-2002, 09:25 AM   #2
Rich
LQ Newbie
 
Registered: Jan 2001
Location: Raleigh, NC
Posts: 11

Rep: Reputation: 0
Question

If port 21 is opened on your router and directed to the gateway FTP server, this should work.

Just for grins, how do you initiate the FTP from outside your network?

For example, you would need to FTP to the ISP assigned DSL router IP address unless you have it set up in a DNS somewhere on the Internet.

Another common problem is that hosts behind the router can not access other hosts behind the router using the ISP assigned DSL router IP.

Just some thoughts...
 
Old 08-15-2002, 09:49 AM   #3
sarin
Member
 
Registered: May 2001
Location: India, Kerala, Thrissur
Distribution: FC 7-10
Posts: 354
Blog Entries: 2

Rep: Reputation: 34
I don't have a solution to your problem. But you can use iptables to find the packets that come to a host. Some thing like "iptables -t nat -I PREROUTING -d server_ip -j LOG" should work. If you want you can give protocol and destination port option.
Also I have read some where that ftp uses port 20 for data transfer. Don't know much about this. But opening port 21 should allow you to login to the server.
--Sarin
 
Old 08-15-2002, 10:51 AM   #4
CyberEE
LQ Newbie
 
Registered: May 2001
Posts: 17

Rep: Reputation: 0
Try starting your ftp daemon with the option for eth1 it may be defalting to eth0.
 
Old 08-16-2002, 03:06 AM   #5
Chou
LQ Newbie
 
Registered: Aug 2002
Location: Singapore
Posts: 7

Original Poster
Rep: Reputation: 0
Thanks all for your suggestions, I'll give them a try when I'm free. Someone on another forum mentioned that ftp works by opening another connection on an arbitrary port for each user. I may have to break open a range of ports for ftp to work if this is the cause of problem.

Rich: I'm using a dynamic DNS service (www.dyndns.org). It rules.
 
Old 08-16-2002, 05:02 AM   #6
mschrijn
LQ Newbie
 
Registered: Dec 2001
Location: Eindhoven, the Netherlands
Distribution: Redhat 8.0 / 9.0
Posts: 8

Rep: Reputation: 0
I think you might want to have a look at the following document about the explanation of active/passive ftp: http://www.slacksite.com/other/ftp.html

If you are using active ftp with your client software, you will need to open up port 20 as well.
Also ports above 1024 are needed, which ports though is not to tell as the "client" determines the port number.

As far as I know you can tell the client which range of ports to use, so you can control the range of ports to open up in your firewall for ftp communication.

I hope this will help, or lead you to solving your problem.
 
Old 08-16-2002, 01:21 PM   #7
Griffon26
Member
 
Registered: Sep 2001
Location: The Netherlands
Distribution: Gentoo, Debian, Mandrake, LFS
Posts: 182

Rep: Reputation: 30
Quote:
Originally posted by Chou
I may have to break open a range of ports for ftp to work if this is the cause of problem.
That won't be necessary.

If you are using iptables there is a feature called connection tracking. That means you can tell your firewall how to determine what packets belong to which connection. You have to tell it for each protocol (ftp, irc, ...) separately.

For ftp this is done with:
Code:
/sbin/modprobe ip_conntrack_ftp
Now your firewall knows that the extra connections that are made for ftp (called data connections) are related to the ones on port 21.

By adding the following line to your firewall script, you can tell it to allow such traffic:

Code:
iptables -A forward -p tcp -m state --state ESTABLISHED,RELATED -j ACCEPT
You can check out my firewall script if you want to see more examples: ftp://griffon26.kfk4ever.com/pub/iptables.txt

I originally took an example script from http://www.linuxguruz.org/iptables/ and modified it to suit my needs.

Last edited by Griffon26; 08-16-2002 at 01:23 PM.
 
Old 08-17-2002, 11:32 AM   #8
TruckStuff
Member
 
Registered: Apr 2002
Posts: 498

Rep: Reputation: 30
Usually you will need to enable ACTIVE transfers on the FTP client side. This makes connections through routers much easier because the connection opens port 20 for control stuff rather than some abitrary port. The connection tracking in iptables is nice, but it didn't do the job for me. Check out http://www.linuxguruz.org/iptables for some good iptables scripts for FTP servers.
 
Old 08-19-2002, 01:09 AM   #9
Chou
LQ Newbie
 
Registered: Aug 2002
Location: Singapore
Posts: 7

Original Poster
Rep: Reputation: 0
Griffon26: Thanks for the info. While I still can't successfully connect from the internet, it did help me protect my server from the LAN.

TruckStuff: In principle, I'd like to support PASV clients so people won't have to mess with their own firewalls to get active clients to work. Thanks for the suggestion anyway.

As for why I can't connect either way, I'm tempted to blame the hardware router (that sits between the server and the internet) for blocking inbound requests despite the settings to forward ports 20-22 (I can't connect from outside using ssh either).

Is there a diagnostic util I can run on the server that would indicate if someone's trying to connect to a specified port?
 
Old 08-19-2002, 06:32 AM   #10
Griffon26
Member
 
Registered: Sep 2001
Location: The Netherlands
Distribution: Gentoo, Debian, Mandrake, LFS
Posts: 182

Rep: Reputation: 30
Quote:
Griffon26: Thanks for the info. While I still can't successfully connect from the internet, it did help me protect my server from the LAN.
And here I am, thinking you are trying to protect your computer from the internet

I made a chain called "blocked" in my script and send everything I want to reject to that chain.

So you'll have something like:

Code:
iptables -A FORWARD ... -j ACCEPT
...
iptables -A FORWARD ... -j ACCEPT
iptables -A FORWARD ... -j blocked
The blocked chain could look like this:
Code:
# Reject blocked traffic from within the LAN quietly
# (you don't want to see all windows sharing broadcast packets in your logs)
$IPTABLES -A blocked -i ! $EXT_IF -j REJECT

# Only log everything that gets past the previous line
$IPTABLES -A blocked -s ! $LANSUBNET -m limit -j LOG --log-level 6 --log-prefix "BLOCKED EXT PACKET: "
$IPTABLES -A blocked -s $LANSUBNET -m limit -j LOG --log-level 6 --log-prefix "BLOCKED SPOOFED PACKET: "
$IPTABLES -A blocked -j REJECT
Note that the -m limit parameter will make sure that your syslogd isn't flooded. But as a result of that, not all packets will be logged if there are a lot of them in a short period of time.

Last edited by Griffon26; 08-19-2002 at 06:34 AM.
 
Old 08-20-2002, 08:19 PM   #11
Chou
LQ Newbie
 
Registered: Aug 2002
Location: Singapore
Posts: 7

Original Poster
Rep: Reputation: 0
Great! Checking the logs and using tcpdump, I managed to debug my network. Also found out my net connection was afflicted with the Curse of the Mysteriously Changing External IP, which seems to happen every hour or so without warning.

Anyway, I can now connect from a remote computer using both passive and active ftp clients without ripping any more holes in my firewall. Thanks all for your help.

Last small problem: when trying to connect to the external IP from an _internal_ computer (on the same LAN as the server), I get "connection refused". Connecting to the server's internal IP still works fine though. Any ideas what might be the problem here?
 
Old 08-21-2002, 05:00 AM   #12
Griffon26
Member
 
Registered: Sep 2001
Location: The Netherlands
Distribution: Gentoo, Debian, Mandrake, LFS
Posts: 182

Rep: Reputation: 30
You probably have to allow traffic to and from the internal interface but addressed to the external IP.

iptables -A INPUT -i $LAN_IF -d $EXT_IP -j somechain
iptables -A OUTPUT -i $LAN_IF -s $EXT_IP -j somechain

As you can see in my iptables script, I created some rules to split up the traffic based on direction, origin and destination.

I have chains for traffic from LAN to internet, LAN to server, server to internet, etc. I added the lines above and replaced 'somechain' in the first line with the chain for LAN to server traffic and 'somechain' in the second line with the chain for server to LAN traffic.

Whether or not to actually allow traffic is determined by the rules for those chains.
 
  


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
FTP Server & Speedtouch Router ss_ffs Linux - Networking 1 06-14-2004 07:19 PM
simple ftp server for embedded router amitchandel Linux - Software 2 06-09-2004 10:20 PM
web,ftp server behind a router bashrc2 Linux - Networking 3 04-26-2004 06:45 PM
ftp server behind a freesco router? progster Linux - Networking 3 03-27-2002 10:30 PM
iptables router with ftp server bbenz3 Linux - Networking 6 02-26-2002 11:45 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 06:49 PM.

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