
ip 命令是查看网络信息的主要工具,使用 ip addr show 命令可以查看网络接口的 IP 地址信息。例如:
$ ip addr show
1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
2: enp0s3: mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 08:00:27:ce:29:53 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.100/24 brd 192.168.1.255 scope global dynamic noprefixroute enp0s3
valid_lft 3477sec preferred_lft 3477sec
ifconfig 命令是旧式的网络配置工具,使用 ifconfig 命令也可以查看网络接口的 IP 地址信息。例如:
$ ifconfig
enp0s3: flags=4163 mtu 1500
inet 192.168.1.100 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::a00:27ff:fece:2953 prefixlen 64 scopeid 0x20
ether 08:00:27:ce:29:53 txqueuelen 1000 (Ethernet)
RX packets 1140 bytes 126589 (123.6 KiB)
TX packets 622 bytes 72553 (70.8 KiB)
lo: flags=73 mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10
loop txqueuelen 1000 (Local Loopback)
RX packets 12 bytes 960 (960.0 B)
TX packets 12 bytes 960 (960.0 B)
nmcli 是 NetworkManager 命令行界面工具,使用 nmcli device show 命令可以查看网络接口的 IP 地址信息。例如:
$ nmcli device show
GENERAL.DEVICE: enp0s3
GENERAL.TYPE: ethernet
GENERAL.HWADDR: 08:00:27:CE:29:53
GENERAL.MTU: 1500
GENERAL.STATE: 100 (connected)
GENERAL.CONNECTION: enp0s3
GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/1
WIRED-PROPERTIES.CARRIER: on
IP4.ADDRESS[1]: 192.168.1.100/24
IP4.GATEWAY: 192.168.1.1
IP4.ROUTE[1]: dst = 0.0.0.0/0, nh = 192.168.1.1, mt = 100
IP4.ROUTE[2]: dst = 192.168.1.0/24, nh = 0.0.0.0, mt = 100
IP4.DNS[1]: 192.168.1.1
IP6.ADDRESS[1]: fe80::a00:27ff:fece:2953/64
IP6.GATEWAY: --
IP6.ROUTE[1]: dst = fe80::/64, nh = ::, mt = 100
hostnamectl 命令可以查看主机的基本信息,包括 IP 地址信息。例如:
$ hostnamectl
Static hostname: centos8
Icon name: computer-vm
Chassis: vm
Machine ID: 9dab8e6f7f8d40859b6a5532f5f104fe
Boot ID: 16416a068243424ab02d44c5077a7678
Virtualization: oracle
Operating System: CentOS Linux 8 (Core)
CPE OS Name: cpe:/o:centos:centos:8
Kernel: Linux 4.18.0-193.el8.x86_64
Architecture: x86-64
IP Address: 192.168.1.100