pipework给docker设置mac

继我上一篇文章pipework给docker设置ip,现在需求增加了还要设置mac,pipework也提供了这个功能。我们可以看看pipework的语法:

Syntax:
pipework hostinterface [-i containerinterface] [-l localinterfacename] [-a addressfamily] guest ipaddr/subnet[@default_gateway] [macaddr][@vlan]
pipework hostinterface [-i containerinterface] [-l localinterfacename] guest dhcp [macaddr][@vlan]
pipework route guest route_command
pipework rule guest rule_command
pipework tc guest tc_command
pipework --wait [-i containerinterface]

之前我们设置ip是用的第一条语法规则,省略了[macaddr][@vlan],由于linux的bridge不支持mac vlan,我们只单独设置mac地址就好了。举个例子:
pipework br0 -i eth0 test 178.20.2.153/[email protected] Fe:FF:B2:14:02:99
-i选项是指定docker使用的网卡使用eth0,不指定的话默认使用eth1
在这里我踩了一个坑,当时经常会出现分配的mac地址设置返回错误:RTNETLINK answers: Cannot assign requested address
百度了各种关键字都无果,心累,后来谷歌了一下马上找到答案了,原链接在这里
引用原文:In other words, if your MAC address is ?X:??:??:??:??:??, X should be 2, 6, a, or e. You can check Wikipedia if you want even more details.
mac地址的第二位必须是2,6,a,e否则设置mac地址就会返回上述错误,a和e也可以大写。

你可能感兴趣的:(docker)