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

   


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM