方法1:使用 ip
命令
ip a 或 ip addr show / ip addr (CentOS)
这会显示所有网络接口的详细信息,包括IPv4和IPv6地址。
方法2:使用 ifconfig
(需要安装)
ifconfig
如果提示未找到命令,先安装 net-tools
:
1.Ubuntu安装
sudo apt update
sudo apt install net-tools -y
2.CentOS安装
sudo yum install net-tools -y
然后再次运行 ifconfig
,IP地址会显示在对应接口的 inet
后面。
方法3:使用 hostname
命令
hostname -I