日期:2014-05-16  浏览次数:20696 次

服务器添加小ip时遇见了疑问,请各位大大帮忙看看,在线等
问题是这样的:
原来的网卡eth0我用ip addr add给它分配了一个地址(假如是192.168.1.2),然而我想在给它分配一个小ip:
ip addr add 192.168.1.3/24 dev eth0
出现如下信息
RTNETLINK answers: Invalid argument
然后 ip a 查看没有新添加的ip。
eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000
  link/ether 00:0c:29:ec:7b:12 brd ff:ff:ff:ff:ff:ff
  inet 192.168.1.2/24 brd 192.168.1.254 scope 3 eth0
  inet6 fe80::20c:29ff:feec:7b12/64 scope link
  valid_lft forever preferred_lft forever
如果我添加的ip是192.168.2.1能够添加成功
eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000
  link/ether 00:0c:29:ec:7b:12 brd ff:ff:ff:ff:ff:ff
  inet 192.168.1.2/24 brd 192.168.1.254 scope 3 eth0
  inet 192.168.2.1/24 brd 192.168.2.254 scope 3 eth0
  inet6 fe80::20c:29ff:feec:7b12/64 scope link
  valid_lft forever preferred_lft forever
然后我将eth0 down掉 再重新启动 然后就能够添加了
eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000
  link/ether 00:0c:29:ec:7b:12 brd ff:ff:ff:ff:ff:ff
  inet 192.168.1.2/24 brd 192.168.1.254 scope global eth0
  inet 192.168.1.3/24 brd 192.168.1.254 scope global secondary eth0
  inet6 fe80::20c:29ff:feec:7b12/64 scope link
  valid_lft forever preferred_lft forever

注意:颜色标注出来的地方down前后不一样,问题就在这儿了,我也在其他网卡上做过实验,就是为什么scope 3 eth0这种情况不能够添加同网段的ip而能够添加其他ip,而scope global eth0这种情况能够添加ip。

scope 3 eth0是什么意思?scope global eth0又是什么意思?

------解决方案--------------------
小IP不懂。

设置网卡的ip别名
#ifconfig eth0:0 192.168.6.100 netmask 255.255.255.0 up
#ifconfig eth0:1 173.173.173.173 netmask 255.255.255.0 up
#ifconfig eth0:2 119.110.120.1 netmask 255.255.255.0 up
------解决方案--------------------
探讨

小IP不懂。

设置网卡的ip别名
#ifconfig eth0:0 192.168.6.100 netmask 255.255.255.0 up
#ifconfig eth0:1 173.173.173.173 netmask 255.255.255.0 up
#ifconfig eth0:2 119.110.120.1 netmask 255.255.255.0 up

------解决方案--------------------
试试
ip address add 192.168.1.3/24 brd + dev eth0
------解决方案--------------------
ip address del 192.168.2.3/24 brd + dev eth0
ip address add 192.168.1.3/24 brd + dev eth0 label eth0:0