CentOS 7 Run Script When Network Interface is Up (Network Manager)

ww‮al.w‬utturi.com
CentOS 7 Run Script When Network Interface is Up (Network Manager)

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:

  1. Create a script that you want to run when the network interface is brought up. For example, create a script called myscript.sh in the /etc/sysconfig/network-scripts directory with the following contents:
#!/bin/bash
echo "Network interface is up!" >> /var/log/myscript.log
  1. Make the script executable by running the following command:
chmod +x /etc/sysconfig/network-scripts/myscript.sh
  1. Create a symbolic link to the script from the ifup-local hook. Run the following command:
ln -s /etc/sysconfig/network-scripts/myscript.sh /etc/sysconfig/network-scripts/ifup-local
  1. Restart Network Manager to apply the changes. Run the following command:
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.

Created Time:2017-10-16 14:38:39  Author:lautturi