Networking Forums

Networking Forums > Computer Networking > Linux Networking > DHCP fallback to fixed IP

Reply
Thread Tools Display Modes

DHCP fallback to fixed IP

 
 
Gernot Butschek
Guest
Posts: n/a

 
      11-02-2005, 06:50 PM
Hi everybody,
Can anybody give me a hint how to configure the DHCP client properly.
This is my expected behaviour:
I want to have the DHCP client check if there is a DHCP server available.
If yes the IP address submitted by the DHCP server should be used.
If no DHCP server is found in the network my computer should fall
back to a fixed IP address rather than not assigning any IP address at all.

A config file snippet to put me on the right track is highly appreciated.

Thanks in advance.
Gernot
 
Reply With Quote
 
 
 
 
Bit Twister
Guest
Posts: n/a

 
      11-02-2005, 08:21 PM
On Wed, 02 Nov 2005 20:50:29 +0100, Gernot Butschek wrote:
> Hi everybody,
> Can anybody give me a hint how to configure the DHCP client properly.
> This is my expected behaviour:
> I want to have the DHCP client check if there is a DHCP server available.
> If yes the IP address submitted by the DHCP server should be used.
> If no DHCP server is found in the network my computer should fall
> back to a fixed IP address rather than not assigning any IP address at all.


Hmmm, kind of a chicken or the egg problem. You cannot ping the dhcp
server until you get the lease and route connection.

My suggestion is to set the nic config for dhcp and let the system try
to bring it up. You script would run next and ping wherever you want
and if fails, swap out nic config file and try again.

> A config file snippet to put me on the right track is highly appreciated.


You can use
http://groups.google.com/advanced_group_search
network_ck in the first box and
bit twister in the Author box might find you a starter script.


Does not do exactly as you asked because different distributions have
nic config files in different places. Other people's Free advice:
http://www.catb.org/~esr/faqs/smart-questions.html

For extra points:
! bash script introduction documentation
http://tldp.org/LDP/intro-linux/html/index.html
! bash script advanced documentation
http://tldp.org/LDP/abs/html/index.html
 
Reply With Quote
 
James Knott
Guest
Posts: n/a

 
      11-03-2005, 12:17 AM
Bit Twister wrote:

> My suggestion is to set the nic config for dhcp and let the system try
> to bring it up. You script would run next and ping wherever you want
> and if fails, swap out nic config file and try again.


No DHCP, no IP, no ping.

He can use ifconfig, to check for an address or there may be some error
message somewhere? Or a timeout on dhcpcd?

 
Reply With Quote
 
Bit Twister
Guest
Posts: n/a

 
      11-03-2005, 12:38 AM
On Wed, 02 Nov 2005 20:17:27 -0500, James Knott wrote:
>
> No DHCP, no IP, no ping.


You got it right, nice and straight forward test agains $? for not
equal zero indicating a ping failure.

> He can use ifconfig, to check for an address


Testing on a variable which may not exist is a pain. No lease, no
ip address to parse for.

> or there may be some error message somewhere?


Maybe not if logs are being rotated out during a network restart or
lease renewal. Also, maybe need different test for different messages
depending if running dhcp/static.

> Or a timeout on dhcpcd?


I do not recommend modifying system boot scripts or rolling your own
network startup scripts.

 
Reply With Quote
 
Gernot Butschek
Guest
Posts: n/a

 
      11-03-2005, 04:09 AM
Thanks everybody for the valuable hints and links!
Gernot

Bit Twister schrieb:
> On Wed, 02 Nov 2005 20:17:27 -0500, James Knott wrote:
>
>>No DHCP, no IP, no ping.

>
>
> You got it right, nice and straight forward test agains $? for not
> equal zero indicating a ping failure.
>
>
>>He can use ifconfig, to check for an address

>
>
> Testing on a variable which may not exist is a pain. No lease, no
> ip address to parse for.
>
>
>>or there may be some error message somewhere?

>
>
> Maybe not if logs are being rotated out during a network restart or
> lease renewal. Also, maybe need different test for different messages
> depending if running dhcp/static.
>
>
>>Or a timeout on dhcpcd?

>
>
> I do not recommend modifying system boot scripts or rolling your own
> network startup scripts.
>

 
Reply With Quote
 
James Knott
Guest
Posts: n/a

 
      11-03-2005, 11:00 AM
Bit Twister wrote:

>> He can use ifconfig, to check for an address

>
> Testing on a variable which may not exist is a pain. No lease, no
> ip address to parse for.


Actually, with bash scripts, parsing is easy.

> > Or a timeout on dhcpcd?

>
> I do not recommend modifying system boot scripts or rolling your own
> network startup scripts.


The dhcpcd script has a hook to an external script, that might be suitable.
I've used that to send an e-mail, when the DHCP address has changed.

 
Reply With Quote
 
Bit Twister
Guest
Posts: n/a

 
      11-03-2005, 12:03 PM
On Thu, 03 Nov 2005 07:00:21 -0500, James Knott wrote:
> Bit Twister wrote:
>
>>> He can use ifconfig, to check for an address

>>
>> Testing on a variable which may not exist is a pain. No lease, no
>> ip address to parse for.

>
> Actually, with bash scripts, parsing is easy.


Yes, but it is an extra test to verify null value before using it.

>
> The dhcpcd script has a hook to an external script, that might be suitable.


Then again if OP is using pump, he won't win.

> I've used that to send an e-mail, when the DHCP address has changed.


Me too. I use it to touch up my shorewall params, email me about
DNS value changes and short lease times.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DHCP and Fixed IP Mr User Wireless Internet 15 01-22-2007 09:52 PM
Help Please - Router using Fixed WAN IP and DHCP Lan JR Tolkin Wireless Internet 4 01-28-2006 12:22 AM
Fixed IPs or DHCP...? Jun Keller Wireless Internet 3 01-24-2004 10:46 PM
Mixed DHCP & Fixed IP's on Same Network Wil Wireless Internet 4 11-08-2003 06:10 PM
DHCP & Win/98 fixed addresses David Linux Networking 0 07-18-2003 07:03 PM



1 2 3 4 5 6 7 8 9 10 11