zoukankan      html  css  js  c++  java
  • Linux服务器配置---ftp限制ip

    ftp限制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:~> 

    做了一个Linux学习的平台,目前出来一个雏形,各位可以参考使用
    链接:https://pan.baidu.com/s/1GOLVU2CbpBNGtunztVpaCQ  密码:n7bk

       

  • 相关阅读:
    教你用photoshop cs5或者cs6做IPad,背景随意换,gif制作,高清教程,原创
    ASP.NET MVC4 IN ACTION学习笔记第一波
    潜移默化学会C#不常用语法《1》动态类型绑定dynamic
    SubSnoic 框架入门到提高(1)全程记录
    杨洋疯狂C# 刊号:201208 第1期ASPNET验证(一)
    杨洋疯狂C# 刊号:201207 第1期
    ASP.NET MVC4 IN ACTION学习笔记第二波
    JavaScript深入【表达式和运算符(上集)】你能过我8关js运算符的题目吗?
    清新空气我的.net(C#)生涯知识总结 跨CSS,JS,JAVA,AJAX,WPF,WCF,LINQ,ASP.NET,Winform,Sqlserver,Mysql,EF,OOP,开发工具等
    潜移默化学会WPF(Treeview异步加载节点)
  • 原文地址:https://www.cnblogs.com/wj78080458/p/10030061.html
Copyright © 2011-2022 走看看