On Debian, all methods to start and stop network connections run scripts under
/etc/network. This is documented in the
interfaces(5) man page. It is part of the ifupdown package, but the scripts are executed even if the interface is brought up or down by frameworks such as NetworkManager rather than by the
So put your script in
/etc/network/if-up.d. Make sure that it includes a check that the interface you wanted is up — in particular, you don't want your script to be executed as soon as the loopback interface goes up. You can check the name of the interface with the
IFACE environment variable, either directly or by calling commands like
ip to check its characteristics (IP address, gateway, …). Alternatively, you might check something independently of the interface, e.g. test that some host is reachable.
Note that scripts are executed in lexicographic order. If your script requires some other functionality (e.g. DNS) to be available, make sure that it comes later than the script that sets up this functionality.