查看使用 5432 端口的连接

通过 lsof 查看

-bash-4.2$ lsof -i:5432
COMMAND    PID     USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
postgres 31984 postgres    6u  IPv4 807290      0t0  TCP *:postgres (LISTEN)
postgres 31984 postgres    7u  IPv6 807291      0t0  TCP *:postgres (LISTEN)
-bash-4.2$ 

通过 ss 查看

有些环境 lsof 可能不生效, 可以使用 ss 来实现相同目标

-bash-4.2$ ss -tunlp |grep :5432
tcp    LISTEN     0      128       *:5432                  *:*                   users:(("postgres",pid=31984,fd=6))
tcp    LISTEN     0      128      :::5432                 :::*                   users:(("postgres",pid=31984,fd=7))

# 只看 ipv4 监听的 tcp 连接
-bash-4.2$ ss -tulnp -4 |grep :5432
tcp    LISTEN     0      128       *:5432                  *:*                   users:(("postgres",pid=31984,fd=6))

# 只看 ipv6 监听的 tcp 连接
-bash-4.2$ ss -tulnp -6 |grep :5432
tcp    LISTEN     0      128      :::5432                 :::*                   users:(("postgres",pid=31984,fd=7))

posted @ 2025-03-15 16:54  岳麓丹枫  阅读(65)  评论(0)    收藏  举报