Linux服务器---ftp限制ip

限制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





来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29270124/viewspace-2221898/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/29270124/viewspace-2221898/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值