如何查看當(dāng)前防火墻的狀態(tài)?
執(zhí)行以下命令:
sudo ufw status verbose
示例輸出:
在 Ubuntu 上檢查 UFW 防火墻的狀態(tài),通過 ufw 命令顯示開放的端口及其狀態(tài):
To Action From -- ------ ---- 22/tcp ALLOW 139.xxx.yy.zzz # Open TCP SSH PORT for SG_OFFICE 22/tcp ALLOW 35.yyy.zzz.ttt # Open TCP SSH PORT for BACKUP_SERVICE 22/tcp ALLOW 172.aaa.bb.ccc # Open TCP SSH PORT for MUM_OFFICE_VPN 192.168.206.142 642/tcp ALLOW 192.168.113.184 # Open tinc TCP port pmdb1:642 for pmdb2 host 192.168.206.142 642/udp ALLOW 192.168.113.187 # Open tinc UDP port pmdb1:642 for pmdb2 host 192.168.206.142 642/tcp ALLOW 192.168.171.219 # Open tinc TCP port pmdb1:642 for pmdb3 host 192.168.206.142 642/udp ALLOW 192.168.171.218 # Open tinc UDP port pmdb1:642 for pmdb3 host 10.100.28.1 ALLOW 10.100.28.0/24 # Allow full communication 10.101.28.2 ALLOW 10.101.28.0/24 # Allow full communication 10.102.28.3 ALLOW 10.102.28.0/24 # Allow full communication
如何打開 tcp 22 端口
要允許 22 端口上的傳入 tcp 數(shù)據(jù)包,請執(zhí)行:
sudo ufw allow 22/tcp
驗證它的狀態(tài):
sudo ufw status verbose
如何打開 tcp 80 和 443 端口
打開 http 和 https 端口命令:
sudo ufw allow http sudo ufw allow https
或
sudo ufw allow 80/tcp sudo ufw allow 443/tcp
如何打開 tcp 和 udp 端口 #53
要允許在端口 53 上傳入 tcp 和 udp 數(shù)據(jù)包,請輸入:
sudo ufw allow 53
驗證它的狀態(tài):
sudo ufw status verbose
打開 TCP 和 UDP 端口的高級示例
要允許 IP 地址 192.168.1.10 訪問端口 22:
sudo ufw allow from 192.168.1.10 to any port 22
打開端口 74.86.26.69:443(nginx/apache/lighttpd 服務(wù)器 443 端口),請輸入:
sudo ufw allow from any to 74.86.26.69 port 443 proto tcp
要允許子網(wǎng) 192.168.1.0/24 訪問 Sabma 服務(wù),請輸入:
ufw allow from 192.168.1.0/24 to any app Samba
查看服務(wù)信息:
sudo ufw app list
示例輸出:
Available applications: Nginx Full Nginx HTTP Nginx HTTPS Squid
要獲取有關(guān) Squid 配置文件/應(yīng)用程序的信息,請運行:
ufw app info Squid
示例輸出:
Profile: Squid Title: Squid proxy cache Description: Internet object cache (WWW proxy cache) Ports: 2048,3128,3130,3401,4827/tcp
拒絕/阻止端口訪問
我們可以添加如下拒絕規(guī)則來阻止對端口 25 的所有訪問:
sudo ufw deny 25 sudo ufw deny 25/tcp comment 'Block access to smptd by default'
如何刪除 ufw 規(guī)則
我們可以在 Ubuntu 上使用以下語法列出防火墻規(guī)則:
sudo ufw status
sudo ufw numbered
一旦發(fā)現(xiàn)防火墻規(guī)則編號可按該編號刪除:
sudo ufw delete {num}
sudo ufw delete 5
另外一種選擇是輸入:
ufw delete deny 25/tcp comment 'Block access to smptd by default'
結(jié)論
在本頁中,我們介紹了如何使用 UFW 打開 TCP 和 UDP 端口,UFW 是 Ubuntu 上的默認(rèn)防火墻管理工具。
(責(zé)任編輯:admin)本文地址:http://m.bmm520.net/info/LinuxServer/2023/0616/23982.html