centos 开启vsftpd服务

来源:互联网 发布:our song知乎 编辑:程序博客网 时间:2024/05/08 14:40

一般服务器启动,习惯必须安装一个ftp server,方便传输文件。看看网络,一致公认vsftpd比较强劲给力,就打算安装一个。

1、安装vsftp

机器联网情况下,还是选择网络安装吧。vsftpd不大,很方便。

执行 

 yum install vsftpd


现在可以运行 service vsftpd start 启动vsftpd,检查看看是否已经启动 fuser 21/tcp正常情况会返回一个监听进度。本来希望在终端用ftp 192.168.2.4进行测试,无奈Centos最小安装居然没有ftp。


赶快拿win7 ftp工具测试看看。无法连接。。。。


2、设置防火墙

无法连接,看来是centos的防火墙把我们拦截了,那先来设置防火墙。centos默认使用iptables作为防火墙,默认是不开启ftp端口。

很多教程这里就提到关闭防火墙,不过如果作为一个server运行,那这么可以,还得要找方法搞定它。

iptable设置文件在/etc/sysconfig/iptables文件内,那我们就来编辑这个文件:


cd /etc/sysconfig/

vi iptables

原文:红色部分为增加

# Firewall configuration written by system-config-firewall

# Manual customization of this file is not recommended.

*filter

:INPUT ACCEPT [0:0]

:FORWARD ACCEPT [0:0]

:OUTPUT ACCEPT [0:0]

-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

-A INPUT -p icmp -j ACCEPT

-A INPUT -i lo -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT

-A INPUT -p tcp --dport 21 -j ACCEPT

-A INPUT -p tcp --dport 20 -j ACCEPT

-A INPUT -j REJECT --reject-with icmp-host-prohibited

-A FORWARD -j REJECT --reject-with icmp-host-prohibited

COMMIT



加两条规则,即tcp 20端口和21端口

-A INPUT -p tcp --dport 21 -j ACCEPT

-A INPUT -p tcp --dport 20 -j ACCEPT


输入wq保存,重新启动防火墙看看。

执行  service iptables restart

再用win7 客户端登录,有了回应了。不过这个时候你用匿名用户登录,发现ftp握手很慢,上传文件还会碰到无法创建文件等错误。


这里需要注意,开启ftp server还需要对iptable-config文件进行设置,开启ftp nat模块


vi /etc/sysconfig/iptabales-config


在文件开头部分IPTABLES_MODULES键值设置成"ip_nat_ftp"

# Load additional iptables modules (nat helpers)

#   Default: -none-

# Space separated list of nat helpers (e.g. 'ip_nat_ftp ip_nat_irc'), which

# are loaded after the firewall rules are applied. Options for the helpers are

# stored in /etc/modprobe.conf.

IPTABLES_MODULES="ip_nat_ftp"


保存文件后,退出重新启动iptable  

执行:service iptables restart

0 0