在 Linux 中,ifconfig 本身不能直接“绑定多个 IP”到网卡长期生效,它只能临时添加/删除 IP。如果你说的是“给网卡绑定(添加)一个 IP”,做法如下:
ifconfig eth0 192.168.1.100 netmask 255.255.255.0 up
ifconfig eth0:0 192.168.1.101 netmask 255.255.255.0 up
ifconfig eth0:1 192.168.1.102 netmask 255.255.255.0 up
查看:
ifconfig
ifconfig eth0:0 down
编辑:
vi /etc/sysconfig/network-scripts/ifcfg-eth0:0
内容:
DEVICE=eth0:0
BOOTPROTO=static
IPADDR=192.168.1.101
NETMASK=255.255.255.0
ONBOOT=yes
重启网络:
service network restart
编辑:
vi /etc/network/interfaces
auto eth0:0
iface eth0:0 inet static
address 192.168.1.101
netmask 255.255.255.0
现代 Linux 已不推荐 ifconfig,建议用:
ip addr add 192.168.1.101/24 dev eth0
如果你能说明:
我可以给你精确配置文件示例。