在 Linux 中,使用 ifconfig 查看子网掩码的方法如下:
ifconfig
或指定网卡(如 eth0、ens33):
ifconfig eth0
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>
...
netmask 字段netmask 255.255.255.0prefixlenprefixlen 64ifconfig: command not found,说明未安装 net-tools:# Ubuntu / Debian
sudo apt install net-tools
# CentOS / RHEL
sudo yum install net-tools
ip 命令:ip addr show eth0
子网掩码会以 CIDR 形式显示,如 192.168.1.100/24(/24 即 255.255.255.0)如果你愿意,我也可以帮你把 ifconfig 的输出逐行解释一遍。