Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

Linux 禁止特定 IP 存取:/etc/hosts.allow 與 hosts.deny 設定教學

編輯:Linux 教學

機制說明

/etc/hosts.allow 為允許清單,/etc/hosts.deny 為拒絕清單。tcpd 先檢查 allow,符合即允許;否則檢查 deny,符合即拒絕;兩者皆無則預設允許。

語法格式

daemon_list : client_list [: option]
  • daemon_list:服務程序名(如 in.telnetd、vsftpd、sshd)。
  • client_list:客戶端清單,支援網域、主機名、網段(如 .vpser.net、192.168.0.、192.168.0.0/255.255.255.0)。
  • option:可選,指定命令或日誌檔。

設定範例

/etc/hosts.allow

in.telnetd: .vpser.net
vsftpd: 192.168.0.
sshd: 192.168.0.0/255.255.255.0
  • 第一行:僅允許 vpser.net 網域主機存取 Telnet(注意開頭的點)。
  • 第二行:僅允許 192.168.0.x 網段存取 FTP(注意尾端的點)。
  • 第三行:僅允許同網段存取 SSH(CIDR 寫法,不可寫 /24)。

/etc/hosts.deny

sshd: 62.75.214.93
sshd: 203.215.252.189
sshd: 219.143.200.169
sshd: 60.12.193.134
sshd: 201.83.220.44
sshd: c953dc2c.virtua.com.br
sshd: gera125.server4you.de

將上列 IP/主機名的 SSH 存取全部拒絕,構建簡易防火牆。

Copyright © Windows教程網 All Rights Reserved