在 Ubuntu 系统中查看 IP 地址有多种方法,以下是常用的几种方式:
ip
命令(推荐)ip a
或
ip addr show
输出示例:
找到 inet
开头的行(IPv4 地址),通常位于 eth0
(有线网卡)、wlan0
(无线网卡)或 ens33
(新版网络接口名)下。
ifconfig
(需安装 net-tools)如果命令未找到,先安装:
sudo apt install net-tools
然后运行:
ifconfig
输出示例:
查看 eth0
或 wlan0
下方的 inet addr
。
nmcli
(NetworkManager 工具)nmcli device show
或查看特定接口:
nmcli device show <接口名> | grep IP4.ADDRESS
hostname
命令仅显示主机的 IP 地址:
hostname -I
(输出为空格分隔的所有 IPv4 地址)
bash
curl ifconfig.me
/etc/netplan/
或 NetworkManager 中配置。根据你的 Ubuntu 版本和网络配置,选择合适的方法即可快速获取 IP 地址!