Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3017277
  • 博文数量: 535
  • 博客积分: 15788
  • 博客等级: 上将
  • 技术积分: 6507
  • 用 户 组: 普通用户
  • 注册时间: 2007-03-07 09:11
文章分类

全部博文(535)

文章存档

2016年(1)

2015年(1)

2014年(10)

2013年(26)

2012年(43)

2011年(86)

2010年(76)

2009年(136)

2008年(97)

2007年(59)

分类: LINUX

2009-02-12 10:45:37

孤陋寡闻了,以前一直以为ip别名(ip aliase)和辅助ip地址(secondary ip address)是一码事情。或者说是不知道还有secondary ip address一说。


今天偶然翻阅时,提到了这样一句话:


As of this writing, the Linux kernel supports both IP aliases and secondary IP addresses, though IP aliases are deprecated in favor of secondary IP addresses.



那也就意味着secondary ip address和ip aliase是不同的概念,首先问Google,Google没有给我好的答案。只好自己摸索了,于是目前只能得到下面的一些概念:

ip alias和secondary ip address是两种不同的实现方式,用来在Linux系统中给同一个物理网卡增加多个ip地址。

ip alias是由ifconfig程序来创建和维护的,而secondary ip address则是有ip程序来创建和维护的。ip addr add 创建的scondary ip address不能在ifconfig -a中看到,反过来,ifconfig创建的ethX:Y却能在ip addr show中看到。

ip alias大家比较熟悉,因此说说secondary ip address如何创建


[root@mlsx autostart]# ifconfig
eth1 Link encap:Ethernet HWaddr 00:13:77:00:7C:C6
inet addr:192.168.0.100 Bcast:192.168.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:163438 errors:2515 dropped:0 overruns:0 frame:2515
TX packets:165217 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:96792997 (92.3 MiB) TX bytes:16356841 (15.5 MiB)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:561 errors:0 dropped:0 overruns:0 frame:0
TX packets:561 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:119798 (116.9 KiB) TX bytes:119798 (116.9 KiB)

eth0被我用ifconfig eth0 down了。

[root@mlsx autostart]# ip addr sh
2: lo: mtu 16436 qdisc noqueue
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
4: eth0: mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 00:12:f0:1d:e8:c5 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.101/24 brd 192.168.1.255 scope global eth0
6: eth1: mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 00:13:77:00:7c:c6 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.100/24 brd 192.168.0.255 scope global eth1

down下去的eth0在这里还是能体现出来的。

[root@mlsx autostart]# ip addr add 192.168.0.102/24 dev eth1
[root@mlsx autostart]# ip addr sh eth1
6: eth1: mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 00:13:77:00:7c:c6 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.100/24 brd 192.168.0.255 scope global eth1
inet 192.168.0.102/24 scope global secondary eth1
[root@mlsx autostart]# ping 192.168.0.102
PING 192.168.0.102 (192.168.0.102) 56(84) bytes of data.
64 bytes from 192.168.0.102: icmp_seq=1 ttl=64 time=0.049 ms
64 bytes from 192.168.0.102: icmp_seq=2 ttl=64 time=0.043 ms

通过ip程序增加了一个secondar ip address,通过ip addr show也能看到,而且能ping通,但是ifconfig中却看不到。

[root@mlsx autostart]# ifconfig -a
eth1 Link encap:Ethernet HWaddr 00:13:77:00:7C:C6
inet addr:192.168.0.100 Bcast:192.168.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:163888 errors:2515 dropped:0 overruns:0 frame:2515
TX packets:165696 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:96837439 (92.3 MiB) TX bytes:16426734 (15.6 MiB)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:565 errors:0 dropped:0 overruns:0 frame:0
TX packets:565 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:120134 (117.3 KiB) TX bytes:120134 (117.3 KiB)


但是ip alias和secondary ip address在实际的使用过程中,会有什么差别呢?
大部分HA软件,包括开源的heartbeat都采用了ip alias的方式,为什么他们不采用secondary ip address方式呢?
或者说ip alias和secondary ip address比较起来,谁更优秀呢?

有人能告诉我吗?

阅读(2753) | 评论(2) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2009-03-19 14:15:46

最好的办法就是看看源代码

chinaunix网友2009-03-19 14:15:00

内部实现不同,但是含义差不多,实际上ifconfig只是取到第一个匹配的ip地址,而ip addr show 却是完全取