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 04-16-2011, 10:47 PM   #1
vonlz
LQ Newbie
 
Registered: Apr 2011
Posts: 13

Rep: Reputation: 0
Problem with FTP server


hi everybody
i have a problem with my ftp server
i have two network my Lan network 172.16.1.0/24 and external 192.168.1.0/24
my firewall server has 2 card eth0:172.16.1.1 and eth1 192.168.1.150
after i configured my ftp server with NAT-IN help external can access to my FTP server ip:172.16.1.10/24.i realize that My Lan can access to My FTP server but external client cann't access to my FTP server.
this is my rules on iptables
iptables –t nat –A PREROUTING –d 192.168.1.150 –i eth1 –p tcp –m tcp –dport 20 –j DNAT –to-destination 172.16.1.10:20
iptables –t nat –A PREROUTING –d 192.168.1.150 –i eth1 –p tcp –m tcp –dport 21 –j DNAT –to-destination 172.16.1.10:21
i also configure natin for webserver and mailserver.External can access but ftp then external cann't established port
i hope that everybody can help me resovle my problem thank a lot.
 
Old 04-16-2011, 11:04 PM   #2
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
You only need to specify the forwarding of port 21. The other port(s) get picked up by the RELATED match. In any case, the port 20 rule you have wouldn't be the cause of this problem, so lets set that aside for now. How are you handling the packets in your FORWARD chain? What about SNAT/MASQUERADE in the POSTROUTING chain? Basically, you'd want something like this (example):
Code:
iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -p TCP -i eth1 -o eth0 --dport 21 -d 172.16.1.10 -m state --state NEW -j ACCEPT
iptables -t nat -A PREROUTING -p TCP -i eth1 --dport 21 -j DNAT --to-destination 172.16.1.10
iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
Of course, make sure you have routing enabled and the FTP connection tracking module loaded:
Code:
echo 1 > /proc/sys/net/ipv4/ip_forward
modprobe ip_conntrack_ftp

Last edited by win32sux; 04-16-2011 at 11:07 PM.
 
Old 04-16-2011, 11:46 PM   #3
vonlz
LQ Newbie
 
Registered: Apr 2011
Posts: 13

Original Poster
Rep: Reputation: 0
thank you a lot but after i configured,external client access to my FTP Server then appear authentication dialog and i type user and pass.
but i wait 10s then appear error 425 falied for established connection hic.i use netstat -ano |grep 21 then realize Establish but port 20 then LIST.
My Lan access ftp OK but external then failed
 
Old 04-17-2011, 12:45 AM   #4
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Sorry, instead of ip_conntrack_ftp, the module I should have suggested is ip_nat_ftp, as this is a router. I think you'll be okay once you load it. If not, add a LOG rule to show us what the filtered packet looks like when the 425 happens.

Last edited by win32sux; 04-17-2011 at 12:52 AM.
 
Old 04-17-2011, 11:12 PM   #5
vonlz
LQ Newbie
 
Registered: Apr 2011
Posts: 13

Original Poster
Rep: Reputation: 0
thank you.i configure look like you propose but it still doesn't work.
this is my rules with iptables.My Lan network 172.16.1.0/24 access FTP server good but external client 192.168.1.0/24 access FTP Server appear errorr 425 failed established connection although FTP server when i type netstat -ano | grep 21 then established but wait sometimes 425 errorr appear.
# Generated by iptables-save v1.3.5 on Mon Apr 18 10:37:38 2011
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [51:7768]
:RH-Firewall-1-INPUT - [0:0]
-A INPUT -j RH-Firewall-1-INPUT
-A FORWARD -j RH-Firewall-1-INPUT
-A FORWARD -d 172.16.1.10 -i eth1 -p tcp -m tcp --dport 21 -m state --state NEW -j ACCEPT
-A FORWARD -d 172.16.1.10 -i eth1 -p tcp -m tcp --dport 20 -m state --state NEW -j ACCEPT
-A FORWARD -d 172.16.1.10 -i eth1 -o eth0 -p tcp -m tcp --dport 21 -m state --state NEW -j ACCEPT
-A FORWARD -d 172.16.1.10 -i eth1 -o eth0 -p tcp -m tcp --dport 20 -m state --state NEW -j ACCEPT
-A FORWARD -d 172.16.1.10 -i eth1 -o eth0 -p tcp -m tcp --sport 21 -j ACCEPT
-A FORWARD -d 172.16.1.10 -i eth1 -o eth0 -p tcp -m tcp --sport 1024:65535 --dport 1024:65535 -j ACCEPT
-A FORWARD -s 172.16.1.10 -i eth0 -o eth1 -p tcp -m tcp --sport 1024:65535 --dport 1024:65535 -j ACCEPT
-A FORWARD -s 172.16.1.10 -i eth1 -o eth0 -p tcp -m tcp --sport 21 -j ACCEPT
-A RH-Firewall-1-INPUT -i lo -j ACCEPT
-A RH-Firewall-1-INPUT -i eth0 -j ACCEPT
-A RH-Firewall-1-INPUT -i eth1 -j ACCEPT
-A RH-Firewall-1-INPUT -p icmp -m icmp --icmp-type any -j ACCEPT
-A RH-Firewall-1-INPUT -p esp -j ACCEPT
-A RH-Firewall-1-INPUT -p ah -j ACCEPT
-A RH-Firewall-1-INPUT -d 224.0.0.251 -p udp -m udp --dport 5353 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp -m udp --dport 631 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m tcp --dport 631 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 23 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 25 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 21 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 20 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT
-A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited
COMMIT
# Completed on Mon Apr 18 10:37:38 2011
# Generated by iptables-save v1.3.5 on Mon Apr 18 10:37:38 2011
*nat
:PREROUTING ACCEPT [28:3744]
:POSTROUTING ACCEPT [9:775]
:OUTPUT ACCEPT [9:775]
-A PREROUTING -d 192.168.1.150 -i eth1 -p tcp -m tcp --dport 80 -j DNAT --to-destination 172.16.1.10:80
-A PREROUTING -d 192.168.1.150 -i eth1 -p tcp -m tcp --dport 20 -j DNAT --to-destination 172.16.1.10:20
-A PREROUTING -d 192.168.1.150 -i eth1 -p tcp -m tcp --dport 21 -j DNAT --to-destination 172.16.1.10:21
-A PREROUTING -d 192.168.1.150 -i eth1 -p tcp -m tcp --dport 25 -j DNAT --to-destination 172.16.1.10:25
-A PREROUTING -d 192.168.1.150 -i eth1 -p tcp -m tcp --dport 110 -j DNAT --to-destination 172.16.1.10:110
-A PREROUTING -d 192.168.1.150 -i eth1 -p tcp -m tcp --dport 53 -j DNAT --to-destination 172.16.1.10:53
-A PREROUTING -i eth0 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8080
-A POSTROUTING -s 172.16.1.0/255.255.255.0 -o eth1 -j MASQUERADE
COMMIT
# Completed on Mon Apr 18 10:37:38 2011
i also configure modprobe ip_conntrack_ftp,ip_nat_ftp and echo 1 > /proc/sys/net/ipv4/ip_forwarding
i don't know why webserver-mail server external can access good but FTP not.i hope everybody can help me
 
Old 04-17-2011, 11:54 PM   #6
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Why didn't you add the LOG rule? It would show us what the firewall is filtering during the 425.

Anyhow, everything seems in order to me. I've put the relevant rules in red:
Quote:
Originally Posted by vonlz View Post
Code:
# Generated by iptables-save v1.3.5 on Mon Apr 18 10:37:38 2011
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [51:7768]
:RH-Firewall-1-INPUT - [0:0]
-A INPUT -j RH-Firewall-1-INPUT
-A FORWARD -j RH-Firewall-1-INPUT
-A FORWARD -d 172.16.1.10 -i eth1 -p tcp -m tcp --dport 21 -m state --state NEW -j ACCEPT
-A FORWARD -d 172.16.1.10 -i eth1 -p tcp -m tcp --dport 20 -m state --state NEW -j ACCEPT
-A FORWARD -d 172.16.1.10 -i eth1 -o eth0 -p tcp -m tcp --dport 21 -m state --state NEW -j ACCEPT
-A FORWARD -d 172.16.1.10 -i eth1 -o eth0 -p tcp -m tcp --dport 20 -m state --state NEW -j ACCEPT
-A FORWARD -d 172.16.1.10 -i eth1 -o eth0 -p tcp -m tcp --sport 21 -j ACCEPT
-A FORWARD -d 172.16.1.10 -i eth1 -o eth0 -p tcp -m tcp --sport 1024:65535 --dport 1024:65535 -j ACCEPT
-A FORWARD -s 172.16.1.10 -i eth0 -o eth1 -p tcp -m tcp --sport 1024:65535 --dport 1024:65535 -j ACCEPT
-A FORWARD -s 172.16.1.10 -i eth1 -o eth0 -p tcp -m tcp --sport 21 -j ACCEPT
-A RH-Firewall-1-INPUT -i lo -j ACCEPT
-A RH-Firewall-1-INPUT -i eth0 -j ACCEPT
-A RH-Firewall-1-INPUT -i eth1 -j ACCEPT
-A RH-Firewall-1-INPUT -p icmp -m icmp --icmp-type any -j ACCEPT
-A RH-Firewall-1-INPUT -p esp -j ACCEPT
-A RH-Firewall-1-INPUT -p ah -j ACCEPT
-A RH-Firewall-1-INPUT -d 224.0.0.251 -p udp -m udp --dport 5353 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp -m udp --dport 631 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m tcp --dport 631 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 23 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 25 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 21 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 20 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT
-A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited
COMMIT
# Completed on Mon Apr 18 10:37:38 2011
# Generated by iptables-save v1.3.5 on Mon Apr 18 10:37:38 2011
*nat
:PREROUTING ACCEPT [28:3744]
:POSTROUTING ACCEPT [9:775]
:OUTPUT ACCEPT [9:775]
-A PREROUTING -d 192.168.1.150 -i eth1 -p tcp -m tcp --dport 80 -j DNAT --to-destination 172.16.1.10:80
-A PREROUTING -d 192.168.1.150 -i eth1 -p tcp -m tcp --dport 20 -j DNAT --to-destination 172.16.1.10:20
-A PREROUTING -d 192.168.1.150 -i eth1 -p tcp -m tcp --dport 21 -j DNAT --to-destination 172.16.1.10:21
-A PREROUTING -d 192.168.1.150 -i eth1 -p tcp -m tcp --dport 25 -j DNAT --to-destination 172.16.1.10:25
-A PREROUTING -d 192.168.1.150 -i eth1 -p tcp -m tcp --dport 110 -j DNAT --to-destination 172.16.1.10:110
-A PREROUTING -d 192.168.1.150 -i eth1 -p tcp -m tcp --dport 53 -j DNAT --to-destination 172.16.1.10:53
-A PREROUTING -i eth0 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8080
-A POSTROUTING -s 172.16.1.0/255.255.255.0 -o eth1 -j MASQUERADE
COMMIT
# Completed on Mon Apr 18 10:37:38 2011
AFAICT, this setup should be working properly.

Are you sure the host-based firewall on the server isn't to blame?

Last edited by win32sux; 04-17-2011 at 11:57 PM.
 
Old 04-18-2011, 07:23 AM   #7
vonlz
LQ Newbie
 
Registered: Apr 2011
Posts: 13

Original Poster
Rep: Reputation: 0
thank you a lot and i'm very sorry because i'm a newbie so i don't know way to add LOG rule with iptables.
the host-based firewall on the server isn't blame because external client can access webserver and mailserver but only FTP not.you can help me add LOG rule with my iptables.
 
Old 04-18-2011, 04:53 PM   #8
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Quote:
Originally Posted by vonlz View Post
the host-based firewall on the server isn't blame because external client can access webserver and mailserver but only FTP not.
Well, technically, the host-based firewall could be configured to allow FTP only from the LAN (for example), while allowing WAN connections for everything else. That said, if you're sure the problem isn't on the server, then I'm out of ideas because the iptables setup on the router looks okay to me.

Quote:
you can help me add LOG rule with my iptables.
Typically you'd add a rule like this to the end of your FORWARD chain:
Code:
iptables -A FORWARD -j LOG --log-prefix "FORWARD DROP: "
...but since your FORWARD policy isn't set to DROP this wouldn't work. In fact, you aren't really using the FORWARD chain at all, as your first FORWARD rule sends all packets to another chain (RH-Firewall-1-INPUT), where they will get sent to REJECT if they don't match any of the rules. So I'd say stick the LOG rule right before the REJECT rule in that chain. Like:
Code:
iptables -A RH-Firewall-1-INPUT -j LOG --log-prefix "RH-Firewall-1-INPUT REJECT: "

Last edited by win32sux; 04-18-2011 at 04:55 PM.
 
Old 04-19-2011, 12:28 AM   #9
vonlz
LQ Newbie
 
Registered: Apr 2011
Posts: 13

Original Poster
Rep: Reputation: 0
thank you again.This's my vsftpd.conf.You can see.i'm not sure that i configure right or wrong.
i dont know detail to configure to external client can access My FTP server.
Quote:
# Example config file /etc/vsftpd/vsftpd.conf
#
# The default compiled in settings are fairly paranoid. This sample file
# loosens things up a bit, to make the ftp daemon more usable.
# Please see vsftpd.conf.5 for all compiled in defaults.
#
# READ THIS: This example file is NOT an exhaustive list of vsftpd options.
# Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
# capabilities.
#
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=NO
#
# Uncomment this to allow local users to log in.
local_enable=YES
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
local_umask=022
#
# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
anon_upload_enable=YES
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
anon_mkdir_write_enable=YES
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES
#
# Activate logging of uploads/downloads.
xferlog_enable=YES
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES
#
# If you want, you can arrange for uploaded anonymous files to be owned by
# a different user. Note! Using "root" for uploaded files is not
# recommended!
#chown_uploads=YES
#chown_username=whoever
#
# You may override where the log file goes if you like. The default is shown
# below.
xferlog_file=/var/log/vsftpd.log
#
# If you want, you can have your log file in standard ftpd xferlog format
xferlog_std_format=YES
#
# You may change the default value for timing out an idle session.
#idle_session_timeout=600
#
# You may change the default value for timing out a data connection.
#data_connection_timeout=120
#
# It is recommended that you define on your system a unique user which the
# ftp server can use as a totally isolated and unprivileged user.
#nopriv_user=ftpsecure
#
# Enable this and the server will recognise asynchronous ABOR requests. Not
# recommended for security (the code is non-trivial). Not enabling it,
# however, may confuse older FTP clients.
async_abor_enable=YES
#
# By default the server will pretend to allow ASCII mode but in fact ignore
# the request. Turn on the below options to have the server actually do ASCII
# mangling on files when in ASCII mode.
# Beware that on some FTP servers, ASCII support allows a denial of service
# attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
# predicted this attack and has always been safe, reporting the size of the
# raw file.
# ASCII mangling is a horrible feature of the protocol.
#ascii_upload_enable=YES
#ascii_download_enable=YES
#
# You may fully customise the login banner string:
ftpd_banner=FTP cua ftp.hmcuong.com
#
# You may specify a file of disallowed anonymous e-mail addresses. Apparently
# useful for combatting certain DoS attacks.
#deny_email_enable=YES
# (default follows)
#banned_email_file=/etc/vsftpd/banned_emails
#
# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
#chroot_list_enable=YES
# (default follows)
#chroot_list_file=/etc/vsftpd/chroot_list
#
# You may activate the "-R" option to the builtin ls. This is disabled by
# default to avoid remote users being able to cause excessive I/O on large
# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
# the presence of the "-R" option, so there is a strong case for enabling it.
#ls_recurse_enable=YES
#
# When "listen" directive is enabled, vsftpd runs in standalone mode and
# listens on IPv4 sockets. This directive cannot be used in conjunction
# with the listen_ipv6 directive.
listen=YES
#
# This directive enables listening on IPv6 sockets. To listen on IPv4 and IPv6
# sockets, you must run two copies of vsftpd whith two configuration files.
# Make sure, that one of the listen options is commented !!
#listen_ipv6=YES
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES
anon_root=/hmcuong
 
Old 04-19-2011, 01:39 AM   #10
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
I was referring to iptables rules (and TCP wrapper) on the server, not the FTP daemon configuration. Did you add the LOG rule on the router? What shows up when the 425 happens? Please post the relevant log file snippet. The reason I keep asking for this is because it's a way to know with decent certainty whether the problem is on the router or not. I recommend you see this through before looking at other things.

Last edited by win32sux; 04-19-2011 at 01:42 AM.
 
Old 04-19-2011, 02:18 AM   #11
vonlz
LQ Newbie
 
Registered: Apr 2011
Posts: 13

Original Poster
Rep: Reputation: 0
oh i don't know sorry.i have a idea.If you can,we can use Teamview so you can understand my problem clearly.Because my level of linux's not good.so there's a lot of knowdelge i can't understand what you teach me.if you don't bother can you help me?
i use Vmware build my network.This's my lab before i do an exam at university
my nick chat (Yahoo): hmcuongth06
thank for your help.
 
Old 04-19-2011, 07:43 AM   #12
vonlz
LQ Newbie
 
Registered: Apr 2011
Posts: 13

Original Poster
Rep: Reputation: 0
maybe i know my problem
you can talk to me way to turn FTP connections filter off with iptables
i think my porblem's here
 
  


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 Problem saran_sai Linux - Newbie 1 09-05-2008 04:25 AM
ftp server problem anh Linux - Software 5 03-16-2006 10:55 AM
ftp from LInux to Serv-U ftp server problem csross Linux - General 2 11-07-2005 04:35 PM
FTP Server problem AMMullan Linux - Networking 1 02-04-2004 04:26 AM
FTP Server Problem cli_man Linux - Software 1 06-02-2003 03:27 PM

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

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