Ejecutar script personalizado cuando se conecta una interfaz

Ejecutar script personalizado cuando se conecta una interfaz

Utilizo un dongle wifi USB para conectarme a Internet. Cuando la conexión inalámbrica se corta, también pierdo algunas reglas de iproute.

¿Cómo puedo restablecer estas reglas cuando la interfaz se conecte nuevamente?

Respuesta1

Si tiene ifupdown(muy probablemente si está usando Debian o una distribución basada en Debian), consulte 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.

Entonces /etc/network/interfacespuedes tener algo como

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

Reemplace eth0 por su interfaz real.

información relacionada