nftablesを使用して1行で特定のポートのUDPとTCPを一致させる方法

nftablesを使用して1行で特定のポートのUDPとTCPを一致させる方法

一行でどうすればいいですか?

tcp dport 53 counter accept comment "accept DNS"
udp dport 53 counter accept comment "accept DNS"

ベストアンサー1

十分に新しい場合は、次のようにnftables書くことができます。

meta l4proto {tcp, udp} th dport 53 counter accept comment "accept DNS"

実際、次のようにすればもっとうまくいくことができます。

set okports {
  type inet_proto . inet_service
  counter
  elements = {
    tcp . 22,  # SSH
    tcp . 53,  # DNS (TCP)
    udp . 53   # DNS (UDP)
}

それから:

meta l4proto . th dport @okports accept

ポート/サービス名を使用する場合は、代わりdomainに作成することもできます。53/etc/services

おすすめ記事