LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1593|回复: 12

安装iptables后,不能使用ftp了

[复制链接]
发表于 2004-4-12 12:09:05 | 显示全部楼层 |阅读模式
我是第一次用iptables,我的规则为:
/sbin/iptables -A INPUT -p tcp --syn --destination-port ftp -j ACCEPT
/sbin/iptables -A INPUT -p tcp --syn --destination-port 22 -j ACCEPT
/sbin/iptables -A INPUT -p tcp --syn -j DROP

之后可以登陆到ftp,但是却不能进行其他操作:

francis@Valas francis $ ftp localhost
Connected to localhost.
220 Valas FTP server ready
Name (localhost:francis): fanwei
500 AUTH not understood
SSL not available
331 Password required for fanwei.
Password:
230 User fanwei logged in.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
200 PORT command successful
421 Service not available, remote server has closed connection
ftp>
而且等待时间很长,不知道怎么回事。请帮忙。
谢谢
发表于 2004-4-12 12:32:44 | 显示全部楼层
ftp不是使用两个端口吗?
21 20
 楼主| 发表于 2004-4-12 14:37:00 | 显示全部楼层
我在网上查的是这么写的
我改成20和21端口后还是不行
 楼主| 发表于 2004-4-12 21:13:27 | 显示全部楼层
我改成:
/sbin/iptables -A INPUT -p tcp  --sport 20 -j ACCEPT
/sbin/iptables -A INPUT -p tcp  --dport 21 -j ACCEPT
/sbin/iptables -A INPUT -p tcp --syn --destination-port 22 -j ACCEPT
/sbin/iptables -A INPUT -p tcp --syn -j DROP
就可以了。为什么20端口要社为源端口啊?
发表于 2004-4-14 04:09:40 | 显示全部楼层
changing the first rule to the following is much safer:
/sbin/iptables -A INPUT -p tcp --sport 20 --dport 1024: -j ACCEPT

Ftp protocol differs from many other protocols that it has two channels. The first channel is established when you connect to the server's port 21. In this channel you can issue the commands to the server. However, the server's response is not sent back to you through this channel. Instead, the server (from its port 20) then tries to connect back to your machine, this establishes the second channel (ftp-data). If the second channel is established successfully, the ftp server then sends the data back to you through it.
 楼主| 发表于 2004-4-14 08:43:40 | 显示全部楼层
I see.
Thanks very much.
发表于 2004-4-17 11:12:21 | 显示全部楼层
ftp server有两种工作方式:主动式和被动式,从你最后的改动我判断你的server采用的是后者,这也是大多数ftp server的流行选择,而针对这两种工作方式iptable所采用的策略是不同的,所以才有了你最开始时的问题,我建议这位兄弟多找找这方面的资料来看看参考(用google很容易找到),真正了解这两种方式的工作原理(重点是ftp-data通信建立的差异),才能明白那几条规则的含义,如果还有什么不明白的再来问,我尽我所能解答

另外楼上的 terminator兄:
/sbin/iptables -A INPUT -p tcp --sport 20 --dport 1024: -j ACCEPT
你那条规则的大概意思是说通讯目的端口在1024以上才可放行,对吧?据我理解目的端口是由server随机给出的,那是不是真会出现随机选中1024以下端口的情况出现?那么在加了这条规则的前提下会不会造成此次用户的数据传输不正常(ftp-data通信无法建立,即用户无法传输数据)?你所说的much safer是不是体现在这点上?麻烦解答一下
发表于 2004-4-17 16:20:39 | 显示全部楼层
发表于 2004-4-17 23:49:06 | 显示全部楼层
proftp里可以设置被动端口范围
发表于 2004-4-20 02:40:41 | 显示全部楼层
/sbin/modprobe ip_conntrack_ftp
all ok
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表