Hotplug Question

I am looking to use hotplugs to run certain functionality when an ethernet is connected/disconnected to a router.

I have tried both net and iface hotplugs with the same result.

I have two really simple scripts that log the interface names.

Script name - 99-ethernet-link

logger "net"

Script name - 99-ethernet-mon

logger "iface"
logger "Interface $INTERFACE"

My issue is that these only seem to fire when the ethernet is disconnected, never when connected? Is there a reason for this or something I am doing wrong here?

ubus call system board

        "kernel": "5.10.176",
        "hostname": "OpenWrt",
        "system": "MediaTek MT7628AN ver:1 eco:2",
        "model": "TP-Link TL-WR902AC v3",
        "board_name": "tplink,tl-wr902ac-v3",
        "rootfs_type": "squashfs",
        "release": {
                "distribution": "OpenWrt",
                "version": "22.03.5",
                "revision": "r20134-5f15225c1e",
                "target": "ramips/mt76x8",
                "description": "OpenWrt 22.03.5 r20134-5f15225c1e"

cat /etc/config/network

config interface 'loopback'
        option device 'lo'
        option proto 'static'

        option ipaddr ''
        option netmask ''

config globals 'globals'
        option ula_prefix 'fd2d:3f65:7e7c::/48'

config device
        option name 'br-lan'
        option type 'bridge'
        list ports 'eth0.1'

config interface 'lan'
        option proto 'static'
        option netmask ''
        option ip6assign '60'
        option device 'wlan0'
        option ipaddr ''
        option force_link '0'

config switch
        option name 'switch0'
        option reset '1'
        option enable_vlan '1'

config switch_vlan
        option device 'switch0'
        option vlan '1'
        option ports '4 6t'

config interface 'wan'
        option proto 'dhcp'
        option device 'eth0.1'
        option broadcast '1'

freely drawn from:

For scripts in iface directory, these are the (relevant) environmental variables

Variable name Description
ACTION ifdown, ifup, ifup-failed, ifupdate, free, reload, iflink, create
INTERFACE Name of the logical interface which went up or down (e.g. wan or lan)
DEVICE Name of the physical device which went up or down (e.g. eth0 or br-lan or pppoe-wan), when applicabl

cat << "EOF" > /etc/hotplug.d/iface/99-my-action
[ "${ACTION}" = "ifup" ] && {
    logger -t hotplug "Device: ${DEVICE} / Action: ${ACTION}"
[ "${ACTION}" = "ifdown" ] && {
    logger -t hotplug "Device: ${DEVICE} / Action: ${ACTION}"
#Others options
logger -t hotplug "Device: ${DEVICE} / Action: ${ACTION}"

@ncompact - thank you for coming back.

I had already tried that script from the documentation, but this has the same issue - I only get the ifdown actions when disconnecting the ethernet. Never the ifup action when connecting.

This is the same with net and iface.


I'm sorry I only realized now that you have a device with only one ethernet port,
I can't give you a solution to your problem.

Maybe someone more knowledgeable than me will know how to help you

Does it work for wired interface in default configuration /etc/config/network?

@ulmwind - as in factory reset the device?

Little update - I get up and down events when the WAN interface is set to a static address but when a DHCP client I only get down events.

I also had to uncheck the Force Link option when setting a static IP for this to function.

Is there specific settings to get an up event to function on a dhcp client?

In wiki there is directory dhcp DHCP-related events, but I do not know, whether it is server, or client.

Make similar script, and check:

cat << "EOF" > /etc/hotplug.d/dhcp/00-logger
logger -t hotplug $(env)
1 Like