HowTo Run a script on ifup ethX and a different one for ifdown ethX
I'm running RHEL 5.2 and would like to run an iptables command when an ethernet device goes up, and a different iptables command when it goes down. I want this to happen automatically after the device goes up or down.
For instance... eth1:2 I tried just adding a line to to /etc/sysconfig/network-scripts/ifcfg-eth1:2 like so: touch /tmp/cant-touch-this This ends up getting run on both ifdown eth1:2, and ifup eth1:2 - which helps but isn't quite what I want. Thanks for any help in advance! |
Network device status is managed with /etc/rc.d/init.d/network. This SysV initscript changes dirs to /etc/sysconfig/network-scripts and runs 'ifup' on found devices. Looking in 'ifup-eth' you will find the last thing it execs is 'ifup-post'. About the last thing 'ifup-post' exececutes is the do_netreport shell function. This function is sourced from network-functions and runs 'netreport'. See if reading 'man netreport' gives you ideas or else check if modifying ifup/ifdown scripts is more your thing.
|
Thanks for the info!
So if if I understand netreport... I'd have to have a background process for each eth interface in question which calls 'netreport -r' and then waits for a SIGIO signal meaning that the interface's state has changed. I guess that seems a bit complicated, but doable. This is really easy on Debian/Ubuntu. You can just add one-liners to /etc/network/interfaces that get run when an specific interface goes up or down. Here's an example. Is there anything simple like that I can do on RHEL? Code:
auto eth0:2 |
Quote:
|
All times are GMT -5. The time now is 07:32 PM. |