Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have Linux 5.3 redhat I want to add the script add_dhcp.ksh to my Linux machine in order to update ifcfg-eth1 automatically after reboot ( this script enable dhcp and startup eth1 )

my question: please advice the steps that needed in order to activate automatically the add_dhcp.ksh script after Linux reboot ,

    add_dhcp.ksh script


    perl -i -pe "s/none/dhcp/"  /etc/sysconfig/network-scripts/ifcfg-eth1 
    perl -i -pe "s/no/yes/"  /etc/sysconfig/network-scripts/ifcfg-eth1 
    ifdown eth1
    ifup   eth1
share|improve this question
Is eth1's config not saved after rebooting? Moreover, why did you edit eth1 and restart eth0? – quanta Nov 8 '11 at 10:09
sorry my mistake see update – Diana Nov 8 '11 at 10:48
What is your final goal? Why did you need to change it at boot? – quanta Nov 8 '11 at 10:49
actually this script is example of change some conf in Linux after reboot , my final script will be different with allot of configuration include network configuration , so I dont want to show here complicated script , – Diana Nov 8 '11 at 10:57
up vote 1 down vote accepted

run this script by adding it to /etc/rc.local file. whatever is present in rc.local file, it is run by linux at every startup.the order is fine, its just that you can use "service network restart" instead of ifup ifdown. . also, what is the need to do this manually at every reboot? why not permantally enable DHCP on this interface once?

share|improve this answer
hi Frank , I prefer to add the script under directory and not to edit any file , did you have other solution – Diana Nov 8 '11 at 10:53
There is no directory in linux, which is confugred this way to run commands atr startup, but just files. – Farhan Nov 8 '11 at 10:56
Adding a file in /etc/cron.d with an appropriate entry would do this – Iain Nov 8 '11 at 11:35
lain: Cron only runs scripts at specific time, it does not recognized startup, shutodwn or reboots. – Farhan Nov 8 '11 at 11:51
@Frank: I suggest you go look at the man page for a modern cron/crontab(5) @reboot : Run once, at startup. – Iain Nov 8 '11 at 22:44

You can do this using cron and the @reboot 'time' in /etc/crontab e.g.

@reboot root /path/to/add_dhcp.ksh 

This will run your command once at startup.


If you don't want to edit any existing system files then you can create a file in /etc/cron.d. This directory is like an extension to the /etc/crontab file and the files use the same format. Note that files in this directory should be writeable only by root.

Create file (/etc/cron.d/rebootfixup for example) and add a line like this

@reboot root /path/to/add_dhcp.ksh

Now when your system boot the file will be added to the list of cron jobs and actioned appropriately.

share|improve this answer
crontab -l no crontab for root ( I cant use crontab -:( ) – Diana Nov 8 '11 at 11:16
@Diana See the edit to my answer. – Iain Nov 8 '11 at 11:35

I think the usual way to do this is to drop it into rc.local, but if you don't want to change files and want a pure directory approach, you can put your script into the /etc/init.d directory. Configure it to accept an argument of 'start' or 'stop' (the stop arg may not be relevant to this particular use case though). Then add a symlink in /etc/rc3.d/ to point to your script with a name of, for example, S99adddhcp.

These 'rc' directories are read as part of the startup process, and you can modify startup behaviors here if you like this method over rc.local for some reason.

Here are a couple of many, many references to this type of configuration - well worth reading:


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.