[wplug] if dhcp fails..

Alexandros Papadopoulos apapadop at cmu.edu
Mon Dec 8 20:26:49 EST 2003


On Monday 08 December 2003 19:07, John Harrold wrote:
> so my advisor has a laptop with matlab installed. in order for the
> license server to start, the network device 'eth0' needs to be up.
> this would seem ok, we can just configure the device to have a static
> ip address and go. the problem is that at home, hes on the private
> network 192.168.1.*, and at school he's on 192.168.0.*. so he really
> needs to use dhcp to get his ip address, and if he's not connected to
> a network, the device needs to default to something. so is there a
> way to make the computer default to an ip address if dhcp fails?

The manual page of dhclient(8) says:

"The  -e  flag will cause dhclient to exit with an error if the 
interface cannot be configured after a certain amount of time. This is 
useful when  dhclient  is used  in  scripts  or  other  systems  when  
a  failed dhcp attempt needs to be reported."

So you could use something like

#!/bin/bash
/sbin/dhclient -e eth0
if [$? != 0]; then
 /sbin/ifconfig eth0 192.168.0.100 up
fi

Of course, you need to fix the syntax :-)

-A




More information about the wplug mailing list