Linux的IP查看命令(ip / ss / netstat 新旧对照)

最后更新: 2026-05-30

经典的 ifconfignetstat 属于 net-tools,在许多发行版中已被弃用或未安装。现代标准是 iproute2ipss)。

对照表

目的 旧(net-tools) 新(iproute2)
查看地址 ifconfig ip addrip a
启用接口 ifconfig eth0 up ip link set eth0 up
查看路由 route -n ip routeip r
查看ARP/邻居 arp -a ip neigh
套接字/端口 netstat -tunlp ss -tunlp

常用示例

# 所有地址(IPv4/IPv6)
ip addr show

# 默认网关
ip route | grep default

# 监听中的TCP端口及进程
ss -tlnp

在命令行查看公网IP

curl -s https://show-ip-addr.com/api/myip
# 或
curl ifconfig.me

参考资料