IP 别名和辅助 IP 地址

概述

IP 别名(IP Alias),辅助ip地址(Secondary IP Address)

IP alias 是由 ifconfig 程序来创建和维护的,而 secondary IP address 则是由 ip 程序来创建和维护的。ip addr add 创建的 secondary IP address 不能在 ifconfig -a 中看到,反过来,ifconfig 创建的 ethX:Y 却能在 ip addr show 中看到。实际上 ifconfig 只是取到第一个匹配的 IP 地址,而 ip addr show 却是完全取。

multi-homing, IP aliasing, Primary address 与 Secondary address 概念辨析

host address: A unique address assigned to a communications device in a computer. If a computer has multiple communications devices (e.g., Ethernet cards or modems), each of these devices will have its own unique address. This means that a host (computer or router) can be multi-homed, i.e., have multiple IP addresses. This can also be artificially created by assigning different IP addresses to the same device (called IP aliasing).

Linux 中为同一个物理网卡增加多个 IP 地址,以前通过 ifconfig 命令来创建和维护 IP alias,而在新的 IPROUTE2 中通过 ip address 命令来创建和维护 Primary address 与 Secondary address。
* 在每一个接口上可以配置多个 Primary 地址和多个 Secondary 地址。
* 对一个特定的网络掩码(例子中的网络掩码为/24),只能有一个 Primary 地址。

在路由代码中对许多事件和条件作出响应依赖于 IP 地址为 Primary 地址还是 Secondary 地址。下面给一些例子:
* Primary addresses contribute to the entropy of the CPU that happens to run the code that applies the configuration.
* 当删除一个 Primary 地址时,所有相关的 Secondary 地址也被删除。但通过 /proc 可以配置一个选项(net.ipv4.conf.*.promote_secondaries),在当前 Primary 地址被删除时可以将 Secondary 地址提升为 Primary 地址。
* 当主机为本地生成的流量选择源 IP 地址时,只考虑 Primary 地址。

原理

在 Linux 中,一个网卡可以有多个 IP,那么这多个 IP 有什么关系呢?其实这些 IP 组成了一个吊链结构,所谓吊链结构就是一些节点链接 成一条链,然后每个节点带有自己的一条链,如下图所示:

  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值