[SOLVED] Proxy FTP behind linux firewall using iptables
Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I may just be Googling this wrong, but here goes: I have an ProFTPd server on a private network. I want to proxy it behind a linux firewall server that's connected to the Internet using iptables.
FTP Server (CentOS 5.4)
eth0: 10.0.0.10/24 (Private-facing if)
/etc/proftpd.conf
...
Port 21
PassivePorts 60000 65535
MasqueradeAddress 2.2.2.2
...
I can get Active FTP working using HAProxy, but Passive FTP is a no go. Here's what I've tried so far on the firewall server:
iptables -t nat -A POSTROUTING -s 10.0.0.10/32 -o bond1 -j SNAT --to-source 2.2.2.2
iptables -t nat -A PREROUTING -d 2.2.2.2/32 -i bond1 -p tcp -m tcp --dport 60000:65535 -j DNAT --to-destination 10.0.0.10
When I connect to 2.2.2.2 with ftp, I can log in, but I can't get data to transfer. Example output:
220 FTP Server ready.
331 Password required for crinis
Password:
230 User crinis logged in.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
229 Entering Extended Passive Mode (|||63627|)
ftp: Can't connect to `2.2.2.2': Connection refused
500 Illegal PORT command
421 Service not available, remote server has closed connection.
ftp>
I have seen some discussion on loading ip_nat_ftp and ip_conntrack_ip, but enabling those on either or both hosts has no effect.
If it's relevant, the following iptable rules are already in place for HAProxy
iptables -A FORWARD -i bond0 -j ACCEPT
iptables -A FORWARD -o bond0 -j ACCEPT
iptables -t nat -A POSTROUTING -o bond1 -j MASQUERADE
Also, Active FTP with iptables instead of HAProxy would be a plus. Thanks!
Well I have never attempted but I think your problem here is the way a passive data connection is established with passive ftp.
When working at a Web Hosting company we ran into a similar issue with a new network config and implemented the ip_conntrack and ip_conntrack_ftp modules. A nifty little article was written up about it here:
On a side note, we would quite commonly lose connections and would have to modprobe the ip_conntrack_ftp module from time to time and reload it. Not sure why but it would happen.
Ha ha! I solved it. I was googling the wrong problem. "FTP NAT IPTABLES" were the criteria I should have been using. For further information, here's the solution, all executed on the firewwall side. This solution also eliminates the need to use HAProxy for FTP Active.
I need to amend this solution to include two import things.
1) Don't forget to do this on the firewall (put it in /etc/rc.local so it's automatic)
modprobe ip_nat_ftp
2) save your iptables config
service iptables save
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.