Centos配置iptables开放ftp服务

Posted 不鸣则已

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Centos配置iptables开放ftp服务相关的知识,希望对你有一定的参考价值。

安装完vsftpd后,默认情况下,CentOS的防火墙是不开放ftp服务的,需要添加模块和开放21端口才能提供ftp访问。
1.添加ip_conntrack_ftp 模块
[[email protected] ~] vi /etc/sysconfig/iptables-config
添加下面一行
IPTABLES_MODULES="ip_conntrack_ftp"

2.打开21端口
[[email protected] ~] vi /etc/sysconfig/iptables
CentOS 5.x版本添加如下规则
-A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 21 -j ACCEPT
CentOS 6.x版本添加如下规则
-A INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT

3.重启iptables使新的规则生效
[[email protected] ~] service iptables restart

4. 检查iptables 是否正常
[[email protected] ~]$service iptables status
num target prot opt source destination
1 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
2 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0 icmp type 255
3 ACCEPT esp -- 0.0.0.0/0 0.0.0.0/0
4 ACCEPT ah -- 0.0.0.0/0 0.0.0.0/0
8 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
9 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22
10 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:21

从结果上来看ftp的21号端口已打开,可以使用FTP软件登陆测试了。
另外说明一下,如果端口号20也没有打开的朋友,请使用命令:
[[email protected] ~]$iptables -A INPUT -p tcp --dport 20 -j ACCEPT
这时ftp连接已经可以,为了保险起见我们把被动模式连接的端口也打开:
[[email protected] ~]$iptables -A INPUT -p tcp --dport 1024: -m state --state ESTABLISHED,RELATED -j ACCEPT

以上是关于Centos配置iptables开放ftp服务的主要内容,如果未能解决你的问题,请参考以下文章

怎么在centos 7上配置ftp服务器

iptables开放被动模式FTP服务

centos 7的防火墙怎么开放端口

关于Centos7 firewalld防火墙开放端口后仍不能访问ftp和nginx的问题解决

linux 配置ftp服务

Ubuntu下iptables开放ftp端口的一个坑:227 Entering Passive Mode