LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian
User Name
Password
Debian This forum is for the discussion of Debian Linux.

Notices

Reply
 
Search this Thread
Old 06-01-2004, 01:36 AM   #1
alexfittyfives
LQ Newbie
 
Registered: May 2004
Distribution: Debian/Ubuntu
Posts: 15

Rep: Reputation: 0
startup script to set up iptables rules doesn't run


I have written a script to set up my iptables rules on my debian box but I can't seem to get it to run at boot. I've put it in /etc/init.d/ and have tried linking to it from various rc*.d (prefixing the name with S20 or some other number) but it doesn't seem to run. Which runlevel should I run this from? Am I missing a step? Where can I look in my logs for any further clues?

Cheers,

Alex
 
Old 06-01-2004, 06:07 AM   #2
Dead Parrot
Senior Member
 
Registered: Mar 2004
Distribution: Debian GNU/kFreeBSD
Posts: 1,597

Rep: Reputation: 46
Debian follows the common Linux runlevel usage -- runlevel 0 is used for halt, 1 for the single user mode, 6 for reboot and runlevels 2-5 for multiuser mode. Debian defaults to runlevel 2, defined at the beginning of /etc/inittab (id:2:initdefault).

In Debian init scripts are in /etc/init.d/ but the handling of these init scripts for different runlevels takes place in /etc/rc{1-6}.d/ directories that contain symlinks to the actual scripts in /etc/init.d/. For example, you may have symlink "S99xdm" in /etc/rc2.d/ to run xdm in runlevel 2. The "S" part stands for "start", the "99" part tells that the script is to be run in the very end of the init process, and the "xdm" part verifies that it is a symlink to the /etc/init.d/xdm script. Removing this symlink ensures that xdm will not be run when the computer boots into runlevel 2.

In Debian there's a nifty utility called "update-rc.d" that can be used to handle the various symlinks to init scripts. "man update-rc.d" will tell you about the syntax of the update-rc.d command.

When you place your own init scripts into /etc/init.d/, remember to make sure that they are executables (chmod 755 /etc/init.d/myscript). After you've placed your init script ("myscript") into /etc/init.d/ (and made it executable), you can create the necessary symlinks with update-rc.d. For example, if you want to start "myscript" with number 20 (to make sure it is started before other scripts that have number 21 or bigger), you can do

# update-rc.d myscript start 20 2 3 4 5 . stop 20 0 1 6 .

This will create a symlink "S20myscript" into /etc/rc{2-5}.d/ and symlink "K20myscript" into /etc/rc{0-1,6}.d/ so that the /etc/init.d/myscript is run every time the Debian system enters runlevels 2-5 and it is stopped/killed when system is halted or rebooted or enters the single user mode.

Of course, you can create or delete the symlinks without using update-rc.d, but it's easy to get confused with all these symlinks, so using update-rc.d is actually a pretty handy way to ensure that you don't have any unwanted (possibly conflicting) symlinks "hanging around" somewhere after you thought you removed them all.
 
Old 06-01-2004, 07:21 PM   #3
alexfittyfives
LQ Newbie
 
Registered: May 2004
Distribution: Debian/Ubuntu
Posts: 15

Original Poster
Rep: Reputation: 0
Thanks Dead Parrot, update-rc.d seems to be exactly what I need. As far as choosing where in the order that this script runs, will it suffice to have it run after the scripts that set up my networking? Is there somewhere I can go for a rundown of conventions/rules regarding startup script ordering?
 
  


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
'cannot stat' script in /etc/rc.d/, try to run script at startup quintan Linux - Software 1 11-21-2005 02:53 AM
how can i load iptables rules at startup synaptical Debian 6 07-15-2005 11:28 AM
RH8 - how to automatically run iptables rules shell script at boot time nu-B Linux - General 1 10-29-2003 08:38 PM
how do I set run level for startup? jdruin Linux - Newbie 3 09-23-2003 10:06 PM
how to get iptables to load rules on startup ? qwijibow Linux - Security 5 09-02-2003 09:48 AM


All times are GMT -5. The time now is 02:56 AM.

Main Menu
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