LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Linux From Scratch
User Name
Password
Linux From Scratch This Forum is for the discussion of LFS.
LFS is a project that provides you with the steps necessary to build your own custom Linux system.

Notices


Reply
  Search this Thread
Old 02-08-2002, 03:18 AM   #1
DavidPhillips
LQ Guru
 
Registered: Jun 2001
Location: South Alabama
Distribution: Fedora / RedHat / SuSE
Posts: 7,163

Rep: Reputation: 58
startup script ethnet ---- dhcpcd


Hey!

I am really liking this LFS system, it seems so much faster than the other distros.


I had a situation with dhcp so I added some stuff to the /etc/init.d/ethnet to take care of it

I saw someones hint for it but it was really not going to work because I have more than one nic, some of them dhcp, some static

anyway I am posting the file so anybody that don't have theirs fixed might like it.


ALL changes are clearly marked..

the timeout for dhcpcd can be up to 60 seconds, set it to what works best for you.

you will need to add one thing to the nics ifcfg file that you want to use dhcp on, like this

/etc/sysconfig/nic-config/ifcfg-eth0

BOOTPROTO=dhcp


make sure that dhcpcd is in the path or add the path to the scripts

There is a dhcpcd issue not pertaining to LFS but you need to be aware of it.

The files created by the dhcpcd daemon go into the /etc/dhcpc folder.

The install of dhcpcd will not create the folder so you will need to.



and here's the complete /etc/init.d/ethnet




#!/bin/sh
# Begin /etc/init.d/ethnet
#
# Main script by Gerard Beekmans - gerard@linuxfromscratch.org
# GATEWAY check by Jean-François Le Ray - jfleray@club-internet.fr
# "Specify which IF to use to reach default GATEWAY" by
# Graham Cantin - gcantin@pacbell.net
# DHCPCD handled by
# David Phillips -
# doodlebuggerr@hotmail.com
#
#------------------------------------------------------------
## Begin added code for dhcpcd
#___________________________________________
#
DHCP_TIMEOUT="10" #max 60 seconds
PROTOCOL="dhcp"
PID_DIR="/etc/dhcpc"
IF_CFG_DIR="/etc/sysconfig/nic-config"
#------------------------------------------------------------
# End added code for dhcpcd
#___________________________________________
#
# Include the functions declared in the /etc/init.d/functions file
# and the variables from the /etc/sysconfig/network file.
#

source /etc/init.d/functions
source /etc/sysconfig/network

case "$1" in
start)

#
# Obtain all the network card configuration files
#

for interface in $(/bin/ls /etc/sysconfig/nic-config/ifcfg* | \
grep -v ifcfg-lo)
do
#
# Load the variables from that file
#

source $interface
#-----------------------------------------------------------
## Begin added code for dhcpcd
#-----------------------------------------------------------

if [ "$BOOTPROTO" != "$PROTOCOL" ]
then
#-----------------------------------------------------------
## End added code for dhcpcd
#-----------------------------------------------------------


# If the ONBOOT variable is set to yes, process this file and bring the
# interface up.
#

if [ "$ONBOOT" == yes ]
then
echo -n "Bringing up the $DEVICE interface..."
/sbin/ifconfig $DEVICE $IP broadcast $BROADCAST \
netmask $NETMASK
evaluate_retval
fi
#-----------------------------------------------------------
## Begin added code for dhcpcd
#-----------------------------------------------------------
else
if [ "$BOOTPROTO" != "" ]
then
if ls $PID_DIR/dhcpcd-$DEVICE.pid 2>/dev/null
then
echo -n "file was found, if $DEVICE is down then try restart."
evaluate_retval
else
echo -n "Contacting a DHCP server for the $DEVICE interface..."
if dhcpcd -t $DHCP_TIMEOUT $DEVICE
then
evaluate_retval
else
evaluate_retval
fi
fi
fi
fi
BOOTPROTO=""
#-----------------------------------------------------------
# End added code for dhcpcd
#-----------------------------------------------------------
done


#
# If the /etc/sysconfig/network file contains a GATEWAY variable, set
# the default gateway and the interface through which the default
# gateway can be reached.
#

if [ "$GATEWAY" != "" ]; then
echo -n "Setting up routing for $GATEWAY_IF interface..."
/sbin/route add default gateway $GATEWAY \
metric 1 dev $GATEWAY_IF
evaluate_retval
fi

;;

stop)

#
# Obtain all the network card configuration files
#

for interface in $(/bin/ls /etc/sysconfig/nic-config/ifcfg* | \
grep -v ifcfg-lo)
do
#
# Load the variables from that file
#

source $interface
#
# If the ONBOOT variable is set, process the file and bring the
# interface down
#

if [ $ONBOOT == yes ]
then
echo -n "Bringing down the $DEVICE interface..."
/sbin/ifconfig $DEVICE down
#---------------------------------------------------------------
# Begin added code for dhcpcd
#---------------------------------------------------------------
if [ "$BOOTPROTO" = "$PROTOCOL" ]
then
if [ $BOOTPROTO != "" ]
then
dhcpcd -k $DEVICE 2>/dev/null
fi
fi
BOOTPROTO=""
#---------------------------------------------------------------
# End sdded code for dhcpcd
#_____________________________________________


evaluate_retval
fi
done
;;

restart)
$0 stop
sleep 1
$0 start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
;;
esac

# End /etc/init.d/ethnet

Last edited by DavidPhillips; 02-08-2002 at 03:41 AM.
 
Old 02-08-2002, 08:12 AM   #2
Mik
Senior Member
 
Registered: Dec 2001
Location: The Netherlands
Distribution: Ubuntu
Posts: 1,316

Rep: Reputation: 47
Thanks, I'm gonna need that soon for the lfs system I'm building now since it's got three nics in it and only one uses dhcp.

Just a few suggestions which might make it a bit neater. When starting you don't check if the variable ONBOOT is set for interfaces with BOOTPROTO==dhcp. I moved the check inside the ONBOOT check in my script. Also when you stopping you first check if BOOTPROTO==PROTOCOL and then check again to make sure that BOOTPROTO!="". If you make sure PROTOCOL is always set then you shouldn't have to do a double check.
I also modified the stop part and had it echo an extra line saying it was killing the dhcpcd and then an extra evaluate_retval. It's not really necessary, but it could be possible that bringing down the interface fails and killing the process succeeds. In that case it would mention success which isn't totally accurate.
Just another thing which has to do with personal preference. I noticed you reset the variable BOOTPROTO. I left it out and added BOOTPROTO=static for all the other nics. But you could also reset it but then you might as well reset the other variables since they are also optional. It could also be an option to add something like:

unset ONBOOT DEVICE BOOTPROTO IP NETMASK BROADCAST
 
Old 02-08-2002, 06:00 PM   #3
DavidPhillips
LQ Guru
 
Registered: Jun 2001
Location: South Alabama
Distribution: Fedora / RedHat / SuSE
Posts: 7,163

Original Poster
Rep: Reputation: 58
I see what you mean about the ONBOOT

it needs to go inside of it.

I am changing mine from this....
-----------------------------------------------
source $interface

if [ "$BOOTPROTO" != "$PROTOCOL" ]
then
------------------------------------------------

to this ...

------------------------------------------------
if [ "$ONBOOT" == yes ]
then

if [ "$BOOTPROTO" != "$PROTOCOL" ]
then

echo -n "Bringing up the $DEVICE interface..."
/sbin/ifconfig $DEVICE $IP broadcast $BROADCAST \
netmask $NETMASK
evaluate_retval
fi
------------------------------------------------

I guess that will do it.


I see what you mean about the variables

I put the BOOTPROTO="" in there in case they did not have it to keep it from going down to the next loop

good idea about unset

I did not know that one

I have very little knowledge of the scripting



so at the bottom of the loop??

I would put ...

unset ONBOOT DEVICE BOOTPROTO IP NETMASK BROADCAST

where I have ....

BOOTPROTO=""


and then at the end set BOOTPROTO=static

and then do

if BOOTPROTO != dhcp
then

else

dhcp


and this would I guess eliminate the need to double check or whatever??
 
Old 02-09-2002, 02:27 PM   #4
Mik
Senior Member
 
Registered: Dec 2001
Location: The Netherlands
Distribution: Ubuntu
Posts: 1,316

Rep: Reputation: 47
Yes you could replace the line BOOTPROTO="" with the unset to make sure all the variables are unset before starting to use the next script.
If you have the unset then it's not necessary to ever set the BOOTPROTO=static. I just added that in the ifcfg-ethX scripts that don't use dhcp. It's not necessary but just a personal preference.

The reason why the double check is unnecessary is because you set PROTOCOL to be dhcp, which is basically a constant in the script. Then you do a check if BOOTPROTO = dhcp and then later a check to make sure it's not empty. If BOOTPROTO has the value dhcp then it could never be empty so it's just a check which will always come up with the same result, so you might as well leave it out.
 
Old 02-10-2002, 10:24 PM   #5
DavidPhillips
LQ Guru
 
Registered: Jun 2001
Location: South Alabama
Distribution: Fedora / RedHat / SuSE
Posts: 7,163

Original Poster
Rep: Reputation: 58
yea, that's exactly what I can't figure out. It didn't make since to me either...


but I tried without it and the interfaces that did not have the BOOTPROTO= line in them would cause a problem.

But I think like you said. they need to be set and unset

The top of the script should set all of the variables. this would avoid a problem with them not in the file.

Then they need to be unset inside to loop at the bottom.
 
  


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
k(g)dm won't start when dhcpcd happens during startup ricalicious Linux - Software 0 01-27-2005 11:02 PM
Adding dhcpcd to startup? drache777 Linux - Newbie 6 01-18-2005 08:44 PM
NIC - dhcpcd trouble on startup tw001_tw Slackware 7 07-30-2004 06:01 PM
What startup script is dhcpcd supposed to be in? murray_linux Slackware 8 06-29-2004 05:27 PM
Dhcpcd at startup dr_van_nostrand Linux - Networking 4 04-15-2003 10:40 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Linux From Scratch

All times are GMT -5. The time now is 11:10 AM.

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