To run a script when a network interface is brought up on CentOS 7 using Network Manager, you can use the ifup-local
script.
The ifup-local
script is a hook that is run by Network Manager when a network interface is brought up. You can use this script to execute any commands or scripts that you want to run when the interface is brought up.
To use the ifup-local
script, follow these steps:
myscript.sh
in the /etc/sysconfig/network-scripts
directory with the following contents:#!/bin/bash echo "Network interface is up!" >> /var/log/myscript.log
chmod +x /etc/sysconfig/network-scripts/myscript.sh
ifup-local
hook. Run the following command:ln -s /etc/sysconfig/network-scripts/myscript.sh /etc/sysconfig/network-scripts/ifup-local
systemctl restart NetworkManager
Now, when the network interface is brought up, the myscript.sh
script will be executed. You can check the /var/log/myscript.log
file to see if the script was run.
For more information on using the ifup-local
script and working with Network Manager on CentOS 7, you can consult the documentation or seek guidance from the CentOS community.