在 Linux 中,可以使用 ifconfig 查看网络接口的 IP 地址。常见用法如下:
ifconfig
输出示例(部分):
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.100 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::20c:29ff:fe12:3456 prefixlen 64 scopeid 0x20<link>
...
192.168.1.100)ifconfig eth0
ifconfig | grep inet
或只看 IPv4:
ifconfig | grep 'inet '
ifconfigip 命令(更现代、官方推荐)ip 命令查看 IP(推荐)ip addr
或简写:
ip a
查看指定网卡:
ip addr show eth0
ifconfig 不存在安装方式:
sudo apt install net-tools
sudo yum install net-tools
如果你愿意,可以告诉我你的 Linux 发行版,我可以给你最适合的命令示例。