1. 程式人生 > >Linux伺服器配置---ftp限制ip

Linux伺服器配置---ftp限制ip

ftp限制IP

1、通過vsftpd的配置檔案以及“hosts.deny”和“hosts.allow”檔案設定允許某個ip地址訪問

      1)修改配置檔案“/etc/vsftpd/vsftpd.conf”中的引數“tcp_wrapper”,確保這個引數是yes

[[email protected] wj]# gedit /etc/vsftpd/vsftpd.conf        //匿名登入

tcp_wrapper=YES

      2)開啟配置檔案“/etc/hosts.deny“,在末尾追加一句話”vsftpd:all:Deny

[[email protected] 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”訪問

[[email protected] 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”,因此訪問不會成功的

[[email protected] wj]# service vsftpd restart        //重啟服務

關閉vsftpd                                             [確定]

 vsftpd 啟動vsftpd                                    [確定]

 

[[email protected] wj]# lftp weijie:[email protected]:8765     //本地使用者登入

lftp [email protected]:~> ls

中斷                                                                     //ls失敗,並沒有連線成功

lftp [email protected]:~> bye

 

[[email protected] 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“

[[email protected] pub]# gedit /etc/vsftpd/vsftpd.conf 

 max_clients=2

      2)重啟服務,測試。一次開啟三個連線,發現第三個連線不能訪問

[[email protected] wj]# service vsftpd restart        //重啟服務

關閉vsftpd                                             [確定]

 vsftpd 啟動vsftpd                                    [確定]

 

[[email protected] wj]# lftp weijie:[email protected]:8765        //登入weijie

lftp [email protected]:~> ls

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

lftp [email protected]:~> 

 

[[email protected] 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:/> 

 

[[email protected] 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