How to run a script automatically when ethernet interface is up/down

Hi toradex,
I want to run a script file automatically when Ethernet interface is down/up.
I tried to kept a script file in if-up.d/if-down.d in directory with executable permissions but it is failed ti execute.

My apalis imx6 board have “connection manager”.

M Narayana Swamy

Hi M Narayana Swamy,

Can you please provide more detail how you are writing the script and how you have tested for this.

Alternatively you can check below location for checking the interface status and based on the output do stuff in same script.

cat /sys/class/net/eth0/operstate

Best Regards


Hi ritesh,

Thank you for your reponse.

I have written a simple shell script to run a executable based on the status of Ethernet interface up or down.
I have placed a script file in "/etc/network/if-down.d/’ directory and another script file in “/etc/network/if-up.d/” with a executable permissions.But these script files are not running automatically in our iMX borad.
I have tried same thing in Ubuntu PC but it is working fine,My Ubuntu PC has NetwokManager and iMX board has connMan.

Instead of periodically checking “/sys/class/net/eth0/operstate” file is there any other ways to run a script file automatically when interface is up/down.

M Narayana Swamy

Hi M Narayana Swamy,

Another option could if using ifup and ifdown with /etc/network/interface

root@apalis-imx6:/# cat /etc/network/interfaces 

auto eth0

iface eth0 inet dhcp

	post-up /etc/network/if-post-up/post-up

	post-down /etc/network/if-down.d/post-down

Here post-up and post-down is custom script which gets called after ifup and ifdown.

Also if you need network manager then you can remove conman and compile linux with networkmanger as shown below

in local.conf

# Remove connman
IMAGE_INSTALL_remove = " connman"
IMAGE_INSTALL_remove = " connman-client connman-plugin-ethernet connman-plugin-loopback connman-plugin-wifi"
IMAGE_INSTALL_remove = " connman-gnome"
# Add NetworkManager
IMAGE_INSTALL_append = " networkmanager"
IMAGE_INSTALL_append = " modemmanager"

For specific network configuration manager please check their documentation for detailed information.

We quickly checked ifup and ifdown and it is working fine.

Best Regards

Ritesh Kumar