设为首页 收藏本站
查看: 836|回复: 0

[经验分享] Iptables开放FTP(主/被)模式端口

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-8-19 09:42:08 | 显示全部楼层 |阅读模式
FTP是File Transfer Protocol(文件传输协议),它有两种工作模式,分别是主动模式(post)和被动模式(passive)

PORT主动模式
FTP客户端连接到FTP服务器的21端口,发送用户名和密码登录,登录成功后要list列表或者读取数据时,客户端随机开放一个端口(1024以上),发送 PORT命令到FTP服务器,告诉服务器客户端采用主动模式并开放端口;FTP服务器收到PORT主动模式命令和端口号后,通过服务器的20端口和客户端开放的端口连接,发送数据。


PASV被动模式
FTP客户端连接到FTP服务器的21端口,发送用户名和密码登录,登录成功后要list列表或者读取数据时,发送PASV命令到FTP服务器, 服务器在本地随机开放一个端口(1024以上),然后把开放的端口告诉客户端, 客户端再连接到服务器开放的端口进行数据传输。

  • 工作在主动模式下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[iyunv@localhost mnt]# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED
ACCEPT     icmp --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:ssh
REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT)
target     prot opt source               destination
REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited
[iyunv@localhost mnt]# iptables -I OUTPUT -p tcp --sport 22 -j ACCEPT
[iyunv@localhost mnt]# iptables -P OUTPUT DROP
[iyunv@localhost ~]# iptables -I INPUT -p tcp --dport 21 -j ACCEPT
[iyunv@localhost ~]# iptables -I OUTPUT -p tcp --sport 20:21 -j ACCEPT
[iyunv@localhost ftp]# netstat -anpt | grep vsftp
tcp        0      0 0.0.0.0:21                  0.0.0.0:*                   LISTEN      1895/vsftpd
tcp        0      0 192.168.60.20:21            192.168.60.10:13153         ESTABLISHED 2066/vsftpd



wKioL1e1dISDLRYaAAHI1lMELPA662.jpg
2. 工作在被动模式下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
[iyunv@localhost ftp]# vi /etc/vsftpd/vsftpd.conf
pasv_enable=yes         //开放FTP PASV模式;
pasv_min_port=24500    //开放数据连接端口号24500—24600之间;
pasv_max_port=24600
[iyunv@localhost ftp]# service vsftpd restart
关闭 vsftpd:                                              [确定]
为 vsftpd 启动 vsftpd:                                    [确定]
[iyunv@localhost ftp]# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED
ACCEPT     icmp --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:ssh
REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT)
target     prot opt source               destination
REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited
Chain OUTPUT (policy DROP)
target     prot opt source               destination
ACCEPT     tcp  --  anywhere             anywhere            tcp spt:ssh
[iyunv@localhost ftp]# iptables -I INPUT -p tcp --dport 20:21 -j ACCEPT
[iyunv@localhost ftp]# iptables -I INPUT -p tcp --dport 24500:24600 -j ACCEPT
[iyunv@localhost ftp]# iptables -I OUTPUT -p tcp --sport 21 -j ACCEPT
[iyunv@localhost ftp]# iptables -I OUTPUT -p tcp --sport 24500:24600 -j ACCEPT
[iyunv@localhost ftp]# netstat -anpt | grep vsftp
tcp        0      0 0.0.0.0:21                  0.0.0.0:*                   LISTEN      2543/vsftpd
tcp        0      0 192.168.60.20:24537         0.0.0.0:*                   LISTEN      2618/vsftpd
tcp        0  23400 192.168.60.20:24537         192.168.60.10:13417         ESTABLISHED 2620/vsftpd
tcp        0      0 192.168.60.20:21            192.168.60.10:13415         ESTABLISHED 2618/vsftpd



wKioL1e1dXyjRZQ4AAHUxRxyYC0096.jpg
注意:FTP的工作模式是基于客户端而定,网上有很多这种更改模式的客户端软件(我这里使用的是CuteFtp)



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-259891-1-1.html 上篇帖子: xshell virt-manager "RuntimeError: could not open display" 下篇帖子: head和tail命令详解
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

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