インターフェースが接続されたときにカスタムスクリプトを実行する

インターフェースが接続されたときにカスタムスクリプトを実行する

私はインターネットに接続するために USB Wi-Fi ドングルを使用しています。ワイヤレス接続が切断されると、一部の iproute ルールも失われます。

インターフェースが再度接続されたときにこれらのルールをリセットするにはどうすればよいですか?

答え1

もしそうなら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.

次の/etc/network/interfacesようなものが考えられます

auto eth0
    iface eth0 inet dhcp
    post-up /usr/local/sbin/my-custom-script

実際のインターフェースの eth0 を置き換えます。

関連情報