今天在51cto论坛Linux区看到的问题,比较感兴趣,就测试一下。
问题来源:http://bbs.51cto.com/thread-919310-1.html
需求:将ftp服务 设置为只允许 早上8点 到 晚上 10 点 访问,其余时间不能访问。
以下测试基本CentOS 5.5,vsftpd-2.0.5.关闭iptables、selinux.
方法一:通过xinetd启动vsftpd,控制访问时间段
1)安装vsftp软件和xinetd守护进程
- [root@server ~]# yum -y install vsftpd xinetd
如果不能使用yum,那就挂载光盘进行安装
- [root@server ~]# chkconfig vsftpd on
- [root@server ~]# chkconfig xinetd on
2)修改/etc/vsftpd/vsftpd.conf使vsftpd不用独立运行方式启动
- [root@server ~]# vim /etc/vsftpd/vsftpd.conf
- listen=YES
- 改为:
- listen=NO
3)配置使用vsftp通过xinetd启动
- [root@server ~]# cp /usr/share/doc/vsftpd-2.0.5/vsftpd.xinetd /etc/xinetd.d/vsftpd
- [root@server ~]# vim /etc/xinetd.d/vsftpd
- service ftp
- {
- socket_type = stream
- wait = no
- user = root
- server = /usr/sbin/vsftpd
- server_args = /etc/vsftpd/vsftpd.conf
- nice = 10
- disable = no
- access_times = 09:00-22:00
- flags = IPv4
- }
将disable的值改成no,允许vsftpd启动,access_times定义可以访问的时间
4)重启服务测试登录
- [root@server ~]# /etc/init.d/xinetd restart
- [root@client ~]# lftp 192.168.209.128
- lftp 192.168.209.128:~> ls
- drwxr-xr-x 2 0 0 4096 Dec 16 2009 pub
- drwxrwxrwx 10 0 0 4096 Feb 28 02:13 upload
当前时间为19:00,属于ftp允许访问的时间范围内,现在访问时间段修改为09:00-18:00
- service ftp
- {
- socket_type = stream
- wait = no
- user = root
- server = /usr/sbin/vsftpd
- server_args = /etc/vsftpd/vsftpd.conf
- nice = 10
- disable = no
- access_times = 09:00-18:00
- flags = IPv4
- }
- [root@server ~]# /etc/init.d/xinetd restart
- [root@client ~]# lftp 192.168.209.128
- lftp 192.168.209.128:~> ls
- `ls' at 0 [Delaying before reconnect: 20]
无法访问了,看看访问的日记会不会有提示:
- [root@server ~]# tail -2 /var/log/messages
- Feb 29 19:24:17 server xinetd[8851]: FAIL: ftp time from=192.168.209.129
- Feb 29 19:24:53 server xinetd[8851]: FAIL: ftp time from=192.168.209.129
PS:通过xinetd启动的进程,还可以使用only_from控制访问来源IP。
方法二:通过crontab来根据ftp开放时间控制进程启动
- 00 8 * * * /etc/init.d/vsftpd start
- 00 22 * * * /etc/init.d/vsftpd stop
这种方法使用的是vsftpd独立运行方式。
所要求的目的达到了。。。。
以上内容,纯属个人测试笔记,如有不错,多多指教。。。。
转载于:https://blog.51cto.com/liyaoyi/807023