天天看點

hosts.allow、hosts.deny配置不生效的解決方法

通過配置hosts.allow、hosts.deny,控制SSH限制固定IP登陸

按照以往的方法,分别在hosts.allow、hosts.deny加入以下配置

# more /etc/hosts.allow

sshd:192.168.x.x

# more /etc/hosts.deny

sshd:all

儲存後測試,發現配置無效,其他IP還是可以登陸成功。

解決方法如下:

hosts.allow和hosts.deny屬于tcp_Wrappers防火牆的配置檔案,而用tcp_Wrappers防火牆控制某一服務通路政策的前提是,該服務支援tcp_Wrappers防火牆,即該服務應用了libwrapped庫檔案。

檢視某服務(如ssh)是否應用了libwrapped庫檔案的方法是:

# ldd /usr/sbin/sshd |grep libwrap.so.0

沒有顯示,表示此伺服器上安裝的SSH沒有應用libwrapped庫檔案,也就不能用tcp_Wrappers防火牆控制通路政策。(一般情況下伺服器預設安裝的SSH都是支援libwrapped庫檔案,這台伺服器不清楚為什麼不支援)

最終解決方法是重新安裝SSH。

# yum -y remove openssh

# yum -y install openssh

# yum -y install openssh-server

安裝完成後再次檢視是否應用了libwrapped庫檔案,顯示支援。

繼續閱讀