Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5708744
  • 博文数量: 409
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 8273
  • 用 户 组: 普通用户
  • 注册时间: 2013-10-23 19:15
个人简介

qq:78080458 学习交流群:150633458

文章分类

全部博文(409)

文章存档

2019年(127)

2018年(130)

2016年(20)

2015年(60)

2014年(41)

2013年(31)

分类: LINUX

2018-12-07 08:52:18

限制IP

1、通过vsftpd的配置文件以及“hosts.deny”和“hosts.allow”文件设置允许某个ip地址访问

1)修改配置文件“/etc/vsftpd/vsftpd.conf”中的参数“tcp_wrapper”,确保这个参数是yes

[root@localhost wj]# gedit /etc/vsftpd/vsftpd.conf        //匿名登录

tcp_wrapper=YES

2)打开配置文件“/etc/hosts.deny“,在末尾追加一句话”vsftpd:all:Deny

[root@localhost wj]# gedit /etc/hosts.deny 

# hosts.deny  This file contains access rules which are used to

#      deny connections to network services that either use

#      the tcp_wrappers library or that have been

#      started through a tcp_wrappers-enabled xinetd.

#

#      The rules in this file can also be set up in

#      /etc/hosts.allow with a 'deny' option instead.

#

#      See 'man 5 hosts_options' and 'man 5 hosts_access'

#      for information on rule syntax.

#      See 'man tcpd' for information on tcp_wrappers

#

vsftpd:all:Deny       //所有的ip都不可以访问

3)打开配置文件“/etc/hosts.allow“,在末尾追加一句话”vsftpd:192.168.0.123:Allow“。当前的配置就是只允许“192.168.0.123”访问

[root@localhost wj]# gedit /etc/hosts.allow

 # hosts.allow This file contains access rules which are used to

#      allow or deny connections to network services that

#      either use the tcp_wrappers library or that have been

#      started through a tcp_wrappers-enabled xinetd.

#

#      See 'man 5 hosts_options' and 'man 5 hosts_access'

#      for information on rule syntax.

#      See 'man tcpd' for information on tcp_wrappers

#

vsftpd:192.168.0.123:Allow

4)测试是否可以访问,当前主机的ip并不是“192.168.0.123”,因此访问不会成功的

[root@localhost wj]# service vsftpd restart        //重启服务

关闭vsftpd                                             [确定]

 vsftpd 启动vsftpd                                    [确定]

 

[root@localhost wj]# lftp weijie:123456@192.168.0.113:8765     //本地用户登录

lftp weijie@192.168.0.113:~> ls

中断                                                                     //ls失败,并没有连接成功

lftp weijie@192.168.0.113:~> bye

 

[root@localhost wj]# lftp 192.168.0.113:8765                     //匿名登录

lftp 192.168.0.113:~> ls

中断                                                                     //ls失败,并没有连接成功

lftp 192.168.0.113:~> 

 

2、当一个ip地址对主机的连接太多时,就会降低服务器的效率。因此有必要设置一个IP的连接数,当连接超过一定的数量就不能再连了,这样就可以提高服务器的效率。Vsftpd默认没有连接设置,可以通过参数“max_clients“来设置。由于同一个局域网的ip是一样的,因此这个最大连接数要合理设置。

1)打开配置文件“/etc/vsftpd/vsftpd.conf“,在末尾追加一句话”max_clients=2

[root@localhost pub]# gedit /etc/vsftpd/vsftpd.conf 

 max_clients=2

2)重启服务,测试。一次打开三个连接,发现第三个连接不能访问

[root@localhost wj]# service vsftpd restart        //重启服务

关闭vsftpd                                             [确定]

 vsftpd 启动vsftpd                                    [确定]

 

[root@localhost wj]# lftp weijie:123456@192.168.0.113:8765        //登录weijie

lftp weijie@192.168.0.113:~> ls

-rwxrwxrwx    1 0        0        2375494044 Aug 14 07:13 1.zip

lftp weijie@192.168.0.113:~> 

 

[root@localhost wj]# lftp 192.168.0.113:8765                       //匿名登录

lftp 192.168.0.113:~> ls

drwxr-xr-x    2 0        0            4096 Aug 14 06:38 pub

lftp 192.168.0.113:/> 

 

[root@localhost pub]# lftp 192.168.0.113                          //匿名登录

lftp 192.168.0.113:~> ls

[0] ls &                                 

    `ls' at 0 [重新连接前延时: 22]                                  //不能再访问,ls失效

lftp 192.168.0.113:~> 

     


阅读(3124) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~