CentOS: Start custom script automatically after network startup

Find the ifup-post under /etc/sysconfig/network-scripts. This scipt is called right after any network interface is brought up online. In this script, you will find the following code snippet toward the end.
if [ -x /sbin/ifup-local ]; then
    /sbin/ifup-local ${DEVICE}

In the code snippet above, if ifup-local script exists in /sbin location, then script gets executed with an interface name in argument. Usually no such ecript like ifup-local exists so in order to run a startup script automatically after a network interface is up. Create an executable script called ifup-local in /sbin and put in there any command or script you wish to run.

Here is an example:

if [[ "$1" == "eth0" ]]
  echo "this part will be executed right after eth0 is up."
  echo "so you can put any startup command for eth0 here"

when script is done, use command to get the script executable.

$ sudo chmod +x /sbin/ifup-local
  • 6 Users Found This Useful
Was this answer helpful?

Related Articles

Initial Steps to securing your CentOS server

Securing your CentOS server is a big step in the right direction and most importantly it will...

How to disable SSH Password Authentication and Root Login for CentOS

When you've decided to connect to your server via SSH key rather than the password, you would...

How to set hostname on Centos 6?

In order to permanently set hostname on Centos 6 VPS you neew to run # nano...

How to change hostname on CentOS permanently

If you are installing LAMP on a new server and ran into the following issue with httpd during the...

How to Create a Firewall on CentOS

Start by saving your current iptables rules if there are any. If you are using CentOS 6.2 or 6.5,...