當前位置: 首頁>>技術教程>>正文


firewall – 您如何為 ufw 創建應用配置文件?

, ,

問題描述

Ufw 有一個列出配置文件的命令,您可以在其中進一步探索其配置文件定義

$ ufw app list

$ ufw app PROFILE {app profile title}

我想知道如何為一個未定義的程序創建一個配置文件,比如虛擬框,並讓該配置文件運行我為我的 Ubuntu 發行版提供的 iptables 相同的定義。


我不僅在嘗試使用 Ubuntu 的防火牆來為我的虛擬機提供服務。我也真誠地好奇如何為沒有附帶的應用程序創建配置文件。

最佳思路

要回答真正的問題,關於如何創建您自己的應用程序文件,您隻需要知道它使用的是 Windows INI 文件格式。

[appname]
title=1-liner here
description=a longer line here
ports=1,2,3,4,5,6,7,8,9,10,30/tcp|50/udp|53

ports 行可以指定多個端口,用/udp 或/tcp 來限製協議,否則默認為兩者。您必須使用 | 將協議部分分開。

因此,對於我製作的一組 real-life 示例:

[puppet]
title=puppet configuration manager
description=Puppet Open Source from http://www.puppetlabs.com/
ports=80,443,8140/tcp

[AMANDA]
title=AMANDA Backup
description=AMANDA the Advanced Maryland Automatic Network Disk Archiver
ports=10080

您可以在單個文件中列出該應用程序的多個版本,例如來自 apache 的這個文件:

===start of apache2.2-common file===
[Apache]
title=Web Server
description=Apache v2 is the next generation of the omnipresent Apache web server.
ports=80/tcp

[Apache Secure]
title=Web Server (HTTPS)
description=Apache v2 is the next generation of the omnipresent Apache web server.
ports=443/tcp

[Apache Full]
title=Web Server (HTTP,HTTPS)
description=Apache v2 is the next generation of the omnipresent Apache web server.
ports=80,443/tcp

===end of file===

定義應用程序文件後,將其放入 /etc/ufw/applications.d ,然後告訴 ufw 重新加載應用程序定義

ufw app update appname
ufw app info appname

將它與類似的東西一起使用:

ufw allow from 192.168.1.10 to any app amanda
ufw allow amanda

假設 192.168.1.10 是您的 Amanda 服務器的 IP。

次佳思路

它實際上都在 “Application Integration” 部分下的聯機幫助頁中。

基本語法是:

ufw allow <app_name>

或者您可以使用擴展語法更具體:

ufw allow from <some_address> to any app <app_name>

聯機幫助頁明確表示不要指定端口號:

\\n

You should not specify the protocol with either syntax, and with the\\nextended syntax, use app in place of the port clause.

\\n

這可能意味著它會讓 <app_name> 使用它想要的任何端口。

其他有用的命令:

ufw app info <app_name>

其中列出了有關 <app_name> 的個人資料的信息。

ufw app update <app_name>  

這會更新 <app_name> 的個人資料。您可以使用 all 更新所有應用程序配置文件。

您可以使用:

ufw app update --add-new <app_name>  

命令為 <app_name> 添加新的配置文件並更新它,遵循您為 ufw app default <policy> 設置的規則。

應用配置文件存儲在 /etc/ufw/applications.d 中,有時存儲在 /etc/services 中。

有關詳細信息,請參閱 man ufw

參考資料

本文由Ubuntu問答整理, 博文地址: https://ubuntuqa.com/zh-tw/article/13465.html,未經允許,請勿轉載。