Okay so I use the simple linux ftp client to download/upload files off ftp servers. I have an iptables firewall which blocks most of the ports and I have to close the firewall for it to work. Although port 21 is open but I guess that explains why the download works and not the upload. The following command works perfectly with the firewall on:
wget ftp://user:[email protected]
I just have problems when I actually connect to the server and try to "put"/upload a file to the server. Here is an example netstat output of the port used at that time but it's always different.
netstat -a | grep ServerIP
tcp 0 197520 myIP.:59622 ServerIP:ftp-data ESTABLISHED
tcp 0 0 myIP.:40341 ServerIP:ftp ESTABLISHED
Both the ports on myIP range are blocked and I'm failing to guess what ports do I have to open. Google search fails as well. Secondly, if I try something like this on iptables, it gives me an error:
-A INPUT -p tcp --match multiport --dport 40000:40500 -j ACCEPT
iptables-restore v1.4.8: too many ports specified
Secondly, why would I need to open the ports when I have the following line before the ports were blocked in the configuration file:
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
A possible cause is that you use active FTP.
FTP has an active and a passive mode.
Active:
Passive:
-- Active FTP vs. Passive FTP, a Definitive Explanation
This means that you have two options:
I'd choose option 1
To accomplish option 2 from Christopher Perrin's answer, you can use the
recent
match extension. It adds source IP address to a list that you can check against in subsequent rules. For these rules, I've assumedeth0
is your WAN interface.I haven't tested this, but I think it should work.