大网数据广告活动
服务器运维问答

Nft list ruleset with ports

· 52CE 我爱测

Is there a way to list the actual ports when listing the rules? I mean: nft list ruleset table ip filter { chain INPUT { type filter hook input priority 0; policy drop; iifname "lo" counter packets 114 bytes 316154 accept ct stat…

问题原文

原帖链接 · Arany Péter · CC BY-SA 4.0

Is there a way to list the actual ports when listing the rules?

I mean:

nft list ruleset

table ip filter {
    chain INPUT {
        type filter hook input priority 0; policy drop;
        iifname "lo" counter packets 114 bytes 316154 accept
        ct state established,related counter packets 415 bytes 70571 accept
        tcp dport http counter packets 13 bytes 728 accept
        tcp dport http-alt counter packets 0 bytes 0 accept
        tcp dport tproxy counter packets 0 bytes 0 accept
        tcp dport https counter packets 0 bytes 0 accept

http is 80 I think https is 443 I think

Is there a way to list the ports not the names?

已采纳解答

原帖链接 · diya · CC BY-SA 4.0

@NikitaKipriyanov provided the answer to your question in the comment.

man nft

Ruleset list output formatting that modify the output of the list ruleset command:
...
-n, --numeric

Print fully numerical output.

The source of the port number <==> service name mapping is the file /etc/services which in turn based on the IANA port assignments list maintained here: http://www.iana.org/assignments/port-numbers

I really understand a preference to look at the actual port numbers:

Often (& especially the higher) port numbers can be in use by other applications/services than /etc/services service mapping suggests. And to add to the confusion: applications with an actual reserved port number are usually not prevented from using different port numbers (in addition to their own) as well.
For example I often see Squid web proxies listening on port 8080, http-alt rather than the reserved port for squid, 3128...

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2022-10-25)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。