LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat
User Name
Password
Red Hat This forum is for the discussion of Red Hat Linux.

Notices



Reply
 
Search this Thread
Old 07-01-2009, 01:31 PM   #1
dscholl
LQ Newbie
 
Registered: Jun 2009
Posts: 5

Rep: Reputation: 0
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!

Last edited by dscholl; 07-01-2009 at 01:32 PM. Reason: clarity
 
Old 07-02-2009, 06:51 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,679
Blog Entries: 54

Rep: Reputation: 2954Reputation: 2954Reputation: 2954Reputation: 2954Reputation: 2954Reputation: 2954Reputation: 2954Reputation: 2954Reputation: 2954Reputation: 2954Reputation: 2954
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.
 
Old 07-07-2009, 01:47 PM   #3
dscholl
LQ Newbie
 
Registered: Jun 2009
Posts: 5

Original Poster
Rep: Reputation: 0
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
allow-hotplug eth0:2
iface eth0:2 inet static
	address 172.18.202.2
	netmask 255.255.0.0
        up   /etc/network/scripts/static-nat up   172.18.202.2 129.193.148.44
        down /etc/network/scripts/static-nat down 172.18.202.2 129.193.148.44
Thanks again for the help.
 
Old 07-07-2009, 02:09 PM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,679
Blog Entries: 54

Rep: Reputation: 2954Reputation: 2954Reputation: 2954Reputation: 2954Reputation: 2954Reputation: 2954Reputation: 2954Reputation: 2954Reputation: 2954Reputation: 2954Reputation: 2954
Quote:
Originally Posted by dscholl View Post
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?
Sure. That's why I ended with "... or else check if modifying ifup/ifdown scripts is more your thing". That isn't advisable as 0) it isn't standard practice plus 1) scripts may jam if you don't script well and 2) scripts may be replaced on update but sure, other than that it's not impossible to add a line or so. I hope the "ifup-post" example made clear there's also an "ifdown-post" and that both are scripts you can read and tweak as you like.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the difference between 'networking restart' and 'ifup ethx' HolyJoe Linux - Networking 8 05-25-2009 03:46 AM
How to change x in ethx in Mandrake lumba Linux - General 1 11-21-2005 04:18 PM
finding out which ethX is using which module Menestrel Linux - Newbie 7 01-11-2005 12:32 AM
specifying ethX jedediah Linux - Networking 1 09-22-2004 11:00 PM
SUSE ethX-wlan amarchis Linux - Wireless Networking 3 08-27-2004 09:14 AM


All times are GMT -5. The time now is 07:19 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration