在macvlan设备上重用IP地址

我试图为某些产品创build易于使用和可能的简单testing环境,并得到了一些macvlan的奇怪行为。

我试图达到的目的:为绑定到外部IP的Ixc容器(通过docker)的单线启动/停止创build一个工具集(我在主机上已经足够了)。

所以,我正在做这样的事情:

 docker run -d -name = container_name container_image
 pipework eth1 container_name ip / prefix_len @ gateway

和pipe道这里这样做:

 GUEST_IFNAME = $ pH值$ NSPID的eth1

 ip link add link eth1 dev $ GUEST_IFNAME type macvlan mode bridge
 ip link set eth1 up
 ip链接设置$ GUEST_IFNAME netns $ NSPID

 ip netns exec $ NSPID ip link set $ GUEST_IFNAME name eth1
 ip netns exec $ NSPID ip addr add $ IPADDR dev eth1
 ip netns exec $ NSPID ip route delete default 
 ip netns exec $ NSPID ip link set eth1 up
 ip netns exec $ NSPID ip route通过$ GATEWAYreplace默认值

 ip netns exec $ NSPID arping -c 1 -A -I eth1 $ IPADDR

而且它每IP的一次。 但是第二次和后来的包容器IP没有进入容器,而所有的configuration似乎很好。

所以看起来像这样:

外部机器

 ➤ping 212.76.131.212
 ....安静....

主机

 root @ ubuntu:〜#ip link show eth1
 2:eth1:mtu 1500 qdisc pfifo_fast状态UP qlen 1000
     link / ether 00:15:17:c9:e1:c9 brd ff:ff:ff:ff:ff:ff

 root @ ubuntu:〜#ip addr show eth1
 2:eth1:mtu 1500 qdisc pfifo_fast状态UP qlen 1000
     link / ether 00:15:17:c9:e1:c9 brd ff:ff:ff:ff:ff:ff

 root @ ubuntu:〜#tcpdump -v -i eth1 icmp
 tcpdump:警告:eth1:没有分配IPv4地址
 tcpdump:监听eth1,链接types为EN10MB(以太网),捕获大小为65535字节
 00:00:46.542042 IP(tos 0x0,ttl 60,id 9623,offset 0,flags [DF],proto ICMP(1),length 84)
     5.134.221.98> 212.76.131.212:ICMP回应请求,ID 6718,序列2345,长度64
 00:00:47.549969 IP(tos 0x0,ttl 60,id 9624,offset 0,flags [DF],proto ICMP(1),length 84)
     5.134.221.98> 212.76.131.212:ICMP回显请求,ID 6718,序号2346,长度64
 00:00:48.558143 IP(tos 0x0,ttl 60,id 9625,offset 0,flags [DF],proto ICMP(1),length 84)
     5.134.221.98> 212.76.131.212:ICMP回显请求,ID 6718,序列2347,长度64
 00:00:49.566319 IP(tos 0x0,ttl 60,id 9626,offset 0,flags [DF],proto ICMP(1),length 84)
     5.134.221.98> 212.76.131.212:ICMP回显请求,ID 6718,序号2348,长度64
 00:00:50.573999 IP(tos 0x0,ttl 60,id 9627,offset 0,flags [DF],proto ICMP(1),length 84)
     5.134.221.98> 212.76.131.212:ICMP回显请求,ID 6718,序列2349,长度64
 ^ C
捕获5个数据包
filter收到5个数据包
内核丢弃了0个数据包
 1个数据包由接口丢弃

主机,容器网

 root @ ubuntu:〜#ip netns exec 32053 ip link show eth1
 48:eth1 @ if2:mtu 1500 qdisc noqueue state UNKNOWN 
     link / ether b2:12:f7:cc:a1:9d brd ff:ff:ff:ff:ff:ff
 root @ ubuntu:〜#ip netns exec 32053 ip addr show eth1
 48:eth1 @ if2:mtu 1500 qdisc noqueue state UNKNOWN 
     link / ether b2:12:f7:cc:a1:9d brd ff:ff:ff:ff:ff:ff
     inet 212.76.131.212/29 scope global eth1
     inet6 fe80 :: b012:f7ff:fecc:a19d / 64范围链接 
       永远永远的preferred_lft永久valid_lft
 root @ ubuntu:〜#ip netns exec 32053 tcpdump -v -i eth1 icmp
 tcpdump:监听eth1,链接types为EN10MB(以太网),捕获大小为65535字节
 ....安静....
 ^ C
捕获0个数据包
filter收到的0个数据包
内核丢弃了0个数据包

那么,谁能说呢,会是什么呢? 这可能是由macvlan实现中的错误造成的吗? 有什么工具可以用来debuggingconfiguration吗?

这是一个ARPcaching问题。

网关上的ARPcaching保存了MAC已经死了的macvlan的IP地址,并没有被arping更新。

通过添加解决

 ip netns exec $ NSPID ping -c 1 -I eth1 $ GATEWAY

pipework脚本的末尾。 这个ping强制网关更新ARPcaching条目/