ufw禁止IP訪問ubuntu服務器

 

 
有臺ubuntu服務器須要禁止一些IP來訪問,本想使用/etc/hosts.allow和/etc/hosts.deny來作限制,後來仍是使用utw搞定了
 
vi /etc/hosts.allow
ALL:10.0.0.163,10.0.0.162,10.0.0.161
 
vi /etc/hosts.deny
ALL:ALL
 
設置好後
/etc/init.d/networking restart
 
使用一臺10.0.0.151來作測試,telnet ubuntu 22 連不上,telnet ubuntu 80也連不上,使用瀏覽器ubuntu服務器竟然能夠訪問,各類檢查,沒解決,後來想解決這個需求也有其餘辦法,使用utw搞定了
 
安裝ufw
sudo apt-get install ufw
 
啓用ufw
sudo ufw enable
 
阻止全部外部對本機的訪問
sudo ufw default deny
 
容許全部的外部IP訪問本機的22/tcp (ssh)端口
sudo ufw allow 22/tcp
 
容許此IP訪問全部的本機端口
sudo ufw allow from 10.0.0.163
 
sudo ufw allow from 10.0.0.162
 
sudo ufw allow from 10.0.0.161
 
查看防火牆狀態
sudo ufw status
 
刪除上面創建的某條規則
sudo ufw delete allow smtp 
 
防火牆規則文件路徑
/lib/ufw/user.rules
 
關閉防火牆 
sudo ufw disable
相關文章
相關標籤/搜索