当接口连接时执行自定义脚本

pyl*_*ver 10 networking ubuntu debian

我使用 USB wifi 加密狗连接到互联网。当无线连接中断时,我也会丢失一些 iproute 规则。

当接口再次连接时,如何重置这些规则?

小智 16

如果您有ifupdown(最有可能的是,如果您使用的是 Debian 或基于 Debian 的发行版),请查看man interfaces

   post-up command
          Run command after bringing the interface up.  If this command fails then ifup aborts, refraining from marking the interface as  con?
          figured  (even though it has really been configured), prints an error message, and exits with status 0.  This behavior may change in
          the future.
Run Code Online (Sandbox Code Playgroud)

所以在/etc/network/interfaces你可以有类似的东西

auto eth0
    iface eth0 inet dhcp
    post-up /usr/local/sbin/my-custom-script
Run Code Online (Sandbox Code Playgroud)

将 eth0 替换为您的实际接口。