⬆️ ⬇️

interface post-up on CentOS

Half a day I was tormented on how to make CentOS run a script after raising the interface. After the first unsuccessful googling, the appearance of the first difficulties forced myself, however, not to act according to the principle “A dirty hack is better than a long haemorrhoid”: refrained from sticking a crutch into /etc/sysconfig/network-scripts/ifup-eth

In order to keep my colleagues from this, I am writing here the result of my research.



1. In its pure form, there is no analogue of the debian post-up on CentOS. Do not even try to look for him.

2. All that is is a certain feature described in Red Hat Knowledgebase DOC-8695



If at a Glance: it is proposed to create a certain / sbin / ifup-local. In which you then put your useful (or useless) code. For example:

#Set the MTU for eth0 only using the ip command

if [ "$1" = "eth0" ]; then

exec /sbin/ip link set dev ${1} mtu 1200

fi


But this is not our method. I consider storing something related to the configuration in /sbin/ unobvious, and even criminal with respect to other admins. Which may have to work with this system in the future.



3. Described in the article Network configuration in Linux through config files, Part 1 , the ifup.d and ifdown.d simply did not ifdown.d . There is not even a mention of /etc/sysconfig/network-scripts/*

')

Based on 1,2,3, the only correct solution is to place the following in /sbin/ ifup-local script:

#!/bin/bash



POSTUPNAME="/etc/sysconfig/network-scripts/post-up-$1"

if [ -x $POSTUPNAME ]; then

exec $POSTUPNAME

fi




Accordingly, post-up-eth0 files are then placed in /etc/sysconfig/network-scripts/ . with useful code inside.



And finally, the situation is similar with the launch of the code before raising the interface ( /sbin/ifup-pre-local ), before disabling it ( /sbin/ifdown-pre-local ) and after disabling it ( /sbin/ifdown-local ).



PS Work was carried out on CentOS release 5.4 (Final). Not a single server was damaged as a result of the autopsy.

Source: https://habr.com/ru/post/82525/



All Articles