在 Linux 中,ifconfig 设置子网掩码(netmask)的方式如下:
ifconfig <网卡名> <IP地址> netmask <子网掩码>
假设网卡是 eth0,要设置:
192.168.1.10255.255.255.0命令:
ifconfig eth0 192.168.1.10 netmask 255.255.255.0
ifconfig eth0 192.168.1.10 netmask 255.255.255.0 broadcast 192.168.1.255
ifconfig 修改是临时生效,重启网络或系统后失效/etc/network/interfaces 或网卡配置文件,取决于发行版)现代 Linux 更推荐使用 ip 命令:
ip addr add 192.168.1.10/24 dev eth0
其中 /24 就相当于 255.255.255.0
如果你告诉我具体的 Linux 发行版(如 CentOS、Ubuntu),我可以给你永久配置的方法。