linux – 添加新的veth接口时运行脚本

前端之家收集整理的这篇文章主要介绍了linux – 添加新的veth接口时运行脚本前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Docker为它创建的每个容器创建一个连接到桥(docker0)的veth接口.

http://docs.docker.io/use/networking/

我想限制这些新veth接口的带宽.我找到了一种方法来做奇迹.但是我想自动化这个.

有没有办法在每次附加新的veth接口时都有一个运行脚本的钩子?

我已经考虑在/etc/network/if-up.d/中添加脚本,但是只在引导期间添加了一个veth时它们才会运行.

以下是我试图收到通知的一些系统日志.我知道我可以拖尾这些日志,但这种方法看起来有点hacky,必须有办法通过操作系统获得有关此事件的通知.

May  2 23:28:41 ip-10-171-7-2 kernel: [22170163.565812] netlink: 1 bytes leftover after parsing attributes.
May  2 23:28:42 ip-10-171-7-2 kernel: [22170163.720571] IPv6: ADDRCONF(NETDEV_UP): veth5964: link is not ready
May  2 23:28:42 ip-10-171-7-2 kernel: [22170163.720587] device veth5964 entered promiscuous mode
May  2 23:28:42 ip-10-171-7-2 avahi-daemon[1006]: Withdrawing workstation service for vethdc8c.
May  2 23:28:42 ip-10-171-7-2 kernel: [22170163.743283] IPv6: ADDRCONF(NETDEV_CHANGE): veth5964: link becomes ready
May  2 23:28:42 ip-10-171-7-2 kernel: [22170163.743344] docker0: port 27(veth5964) entered forwarding state
May  2 23:28:42 ip-10-171-7-2 kernel: [22170163.743358] docker0: port 27(veth5964) entered forwarding state
May  2 23:28:48 ip-10-171-7-2 kernel: [22170170.518670] docker0: port 26(vethb06a) entered forwarding state
May  2 23:28:57 ip-10-171-7-2 kernel: [22170178.774676] docker0: port 27(veth5964) entered forwarding state
最佳答案
每次添加新界面时,您都应该编写一个自定义udev规则来运行您的脚本.这就是Debian处理界面“hotplug”所做的事情.

/etc/udev/rules.d/90-my-networking.rules:

SUBSYSTEM=="net",RUN+="/usr/local/bin/my-networking-agent.sh"

/usr/local/bin/my-networking-agent.sh:

#!/bin/sh
logger "hey I just got interface ${INTERFACE} with action ${ACTION}"

编辑

以下是测试方法

# modprobe dummy0
# ifconfig dummy0 up
# tail -n1 /var/log/syslog
May  3 01:48:06 ernst logger: hey I just got interface dummy0 with action add

猜你在找的Docker相关文章