LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 11-03-2004, 07:45 PM   #1
nazdrowie
Member
 
Registered: Oct 2004
Distribution: Debian
Posts: 39

Rep: Reputation: 15
How do I run a script when network's brought up in Debian?


I'm basically trying to get iptables/firewalling set up in debian. I've verified that the iptables module is loaded, and I've put my firewall script in /etc/network/if-up.d but it doesn't seem to be getting executed (it does have its execute bits set by the way). I know the script isn't getting run, because it's supposed to echo "firewall started", but grepping output from dmesg returns nothing.

Is /etc/network/if-up.d the place to put scripts that you'd like started when the network is brought up?

Or do I need to follow a different approach?
 
Old 11-03-2004, 09:09 PM   #2
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
If it's in if-up.d, then it should run for every interface that comes up. Rather than grep through dmesg, what happens if you just do:
ifdown eth0; ifup eth0
?

If you are connecting via SSH, try bouncing lo instead of eth0 for testing.

To make the script work on one specific interface, add "up /path/to/script" to the /etc/network/interfaces file instead.
 
Old 11-04-2004, 04:17 AM   #3
urzumph
Member
 
Registered: Jan 2004
Location: Australia
Distribution: Debian
Posts: 168

Rep: Reputation: 30
As I recall, dmesg only prints kernel boot messages. Bringing interfaces up is, as I recall, handled by init (or a service called by init, I forget which). init is the first program loaded after the kernel has finished booting, thus you will not find any interface loading information in dmesg, regardless of weather it's working or not.

perhaps you would be better off putting something like :
echo "Firewall brought up successfully at $(date)" > /root/firewalllog

into your firewall script... thus you will be able to tell if it loaded successfully or not.
 
Old 11-04-2004, 11:39 AM   #4
TigerOC
Senior Member
 
Registered: Jan 2003
Location: Devon, UK
Distribution: Debian Etc/kernel 2.6.18-4K7
Posts: 2,380

Rep: Reputation: 49
You need to configure it to initiate during boot sequence. Lets call the script firewall.
Put the sciript in /etc/init.d then do the following;
ln -s /etc/init.d/firewall /rc2.d/S89firewall then
ln -s /etc/init.d/firewall /rc3.d/S89firewall then
ln -s /etc/init.d/firewall /rc4.d/S89firewall then
ln -s /etc/init.d/firewall /rc5.d/S89firewall

to get it running do /etc/init.d/firewall start
When you boot the system the script will be run and if you have ouput it will notify you of the fact.

Last edited by TigerOC; 11-04-2004 at 11:41 AM.
 
Old 11-04-2004, 12:09 PM   #5
nazdrowie
Member
 
Registered: Oct 2004
Distribution: Debian
Posts: 39

Original Poster
Rep: Reputation: 15
All replies are very helpful. Thank you.

I ran 'ifdown eth0; ifup eth0' and apparently my script wasn't being started, so I tried your approach (added 'up ...' to /etc/network/interfaces), CroMagnon, and it worked great:
Code:
iface eth0 inet dhcp
        up /etc/network/if-up.d/start_firewall.sh
        post-down /etc/network/if-post-down.d/stop_firewall.sh
I also have a script for flushing all the tables and deleting the user created ones after the interface is brought down, as you can see above. Is that script necessary?

urzumph <- Thanks for the clarification about dmesg. I didn't know it's only for kernel messages, of which bringing interfaces up isn't a part of.

TigerOC, which approach do you think is better? The one you suggested, which involves creating sym links for all the run-levels in which you anticipate the firewall to be useful, or using CroMagnon's solution, which, I hope, ensures that the firewall is started everytime the eth0 interface is brought up? (I'm sort of biased towards the latter, but it's just my intuition, because I'm a fairly new Linux user.)
Also, you said
Quote:
to get it running do /etc/init.d/firewall start
. In what file in Debian would I place that line?
 
Old 11-04-2004, 02:09 PM   #6
TigerOC
Senior Member
 
Registered: Jan 2003
Location: Devon, UK
Distribution: Debian Etc/kernel 2.6.18-4K7
Posts: 2,380

Rep: Reputation: 49
Quote:
Originally posted by nazdrowie
TigerOC, which approach do you think is better? The one you suggested, which involves creating sym links for all the run-levels in which you anticipate the firewall to be useful, or using CroMagnon's solution, which, I hope, ensures that the firewall is started everytime the eth0 interface is brought up? (I'm sort of biased towards the latter, but it's just my intuition, because I'm a fairly new Linux user.)
Also, you said . In what file in Debian would I place that line?
I'm ultra cautious because I run an "always on ADSL" connection so I want the firewall active when the networking starts. The /etc/init.d/firewall start is a cli command. This means start it without reboot /etc/init.d/firewall stop will bring it down and /etc/init.d/firewall restart will obviously restart if you tweaked the parameters and wanted to start it again.
 
Old 11-04-2004, 03:16 PM   #7
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
If you want to make sure the firewall script is run before the interface starts, change the "up (script)" line to "pre-up (script)" instead The four commands possible are up, pre-up, down, and post-down.
 
  


Reply



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
'cannot stat' script in /etc/rc.d/, try to run script at startup quintan Linux - Software 1 11-21-2005 02:53 AM
finding out network's topology vrikers Programming 4 04-24-2005 12:22 PM
[Iptables] Debian sarge, can't run script wesleywest Debian 7 01-25-2005 03:03 PM
on Network Up Script run? On Battery power run script? v2-ncl Linux - General 0 12-08-2003 09:34 AM
What are a network's capabilites Travis86 Linux - Networking 4 03-03-2003 10:44 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 04:30 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
Open Source Consulting | Domain Registration