Overclockers Australia Forums
OCAU News - Wiki - QuickLinks - Pix - Sponsors  

Go Back   Overclockers Australia Forums > Software Topics > Other Operating Systems

Notices


Sign up for a free OCAU account and this ad will go away!
Search our forums with Google:
Reply
 
Thread Tools
Old 1st July 2009, 11:13 AM   #1
oh_noes Thread Starter
Member
 
oh_noes's Avatar
 
Join Date: Oct 2006
Location: Australia
Posts: 857
Default Debian: Try DHCP but set specific IP if it fails

When networking comes online for a specific group of servers, I need them to try to DHCP, but if that fails I need to set a specific IP address (private net).

How can I do this? Everyone is saying it's not possible, but it's FOSS right, so anything is possible.

I'm thinking I might have to write a udev or if-up script?
oh_noes is offline   Reply With Quote

Join OCAU to remove this ad!
Old 1st July 2009, 11:26 AM   #2
HyRax1
48656C6C6F20576F726C6421
 
HyRax1's Avatar
 
Join Date: Jun 2001
Location: At a desk. Distro:Ubuntu
Posts: 7,120
Default

...why would you expect DHCP to fail?
__________________
If practice makes perfect, and nobody's perfect, why practice?
HyRax1 is offline   Reply With Quote
Old 1st July 2009, 11:47 AM   #3
f3n1x
Member
 
f3n1x's Avatar
 
Join Date: Mar 2003
Location: Armadale, Melbourne
Posts: 1,663
Default

No need. (edit: Whoever told you wasn't possible is talking out their backside).

Here's the way i'd do that.

Edit your /etc/network/interfaces file and create a static ip entry for the desired interface with the private network ip address you wish the machine to use assuming a DHCP lease is not obtained like this:

Code:
auto eth0
iface eth0 inet static
address 10.0.94.254
netmask 255.0.0.0
broadcast 10.255.255.255
network 10.0.0.0
post-up /sbin/dhclient eth0 || true
The last line will run dhclient on the eth0 interface and then ensure that even if it fails ifup will continue to consider the interface configured.

Obviously change the details to match your network and system configuration.

Last edited by f3n1x; 1st July 2009 at 11:52 AM.
f3n1x is offline   Reply With Quote
Old 1st July 2009, 11:48 AM   #4
f3n1x
Member
 
f3n1x's Avatar
 
Join Date: Mar 2003
Location: Armadale, Melbourne
Posts: 1,663
Default

Quote:
Originally Posted by HyRax1 View Post
...why would you expect DHCP to fail?
Laptop moving between networks where one has a dhcp server and the other has machines configured statically? Some people hate NetworkManager that much.

Last edited by f3n1x; 1st July 2009 at 11:51 AM.
f3n1x is offline   Reply With Quote
Old 1st July 2009, 3:12 PM   #5
cleary
Mental in the Face
 
cleary's Avatar
 
Join Date: Apr 2003
Location: Griffith NSW
Posts: 3,933
Default

You could also try using something like guessnet:
Code:
Package: guessnet                                                                                       
Priority: optional                                                                                      
Section: net                                                                                            
Installed-Size: 492                                                                                     
Maintainer: Enrico Zini <enrico@debian.org>                                                             
Architecture: amd64                                                                                     
Version: 0.49-1                                                                                         
Depends: libc6 (>= 2.7-1), libgcc1 (>= 1:4.1.1-21), libiw29 (>= 28+29pre7), libnet1 (>= 1.1.2-1), libpcap0.8 (>= 0.9.3-1), libstdc++6 (>= 4.2.1-4)
Suggests: pppoe, waproamd, ifplugd                                                                                                                
Filename: pool/main/g/guessnet/guessnet_0.49-1_amd64.deb                                                                                          
Size: 186516                                                                                                                                      
MD5sum: 51f7c7f1a32c3f0c5ac6910302799496                                                                                                          
SHA1: 5f9bcd01ca092f2d642aa6eff8e0e7ebe111ee8e                                                                                                    
SHA256: e3b074bea69d359d9d5c9487d58e6675df85f2394fb1b53ac6fc8efb53620c03                                                                          
Description: Guess which LAN a network device is connected to                                                                                     
 Guessnet is a non-aggressive network detection tool to use when moving                                                                           
 a machine among networks which don't necessarily provide DHCP.                                                                                   
 .                                                                                                                                                
 Guessnet takes in input a list of candidate network profiles,
 each of which includes a test description; then it runs all
 the tests in parallel and prints the name of the profile whose
 test was the first one to succeed.
 .
 Available tests are:
  * ARP probes to check for known hosts in the network
  * link beat check, to check if the interface is connected to anything
  * Wireless lan checks, to look for access points found by waproamd
  * PPPOE check to see if there is a concentrator accessible via PPPOE
  * Checks provided by custom arbitrary scripts.
 .
 Guessnet can be used in either native mode or "ifupdown mode".
 In the latter case guessnet integrates nicely with ifupdown
 as a "mapping script".
Enhances: ifupdown
Tag: hardware::laptop, implemented-in::c++, interface::commandline, network::scanner, role::program, scope::utility, use::scanning
__________________
SmugMug
cleary is offline   Reply With Quote
Old 17th July 2009, 4:35 PM   #6
oh_noes Thread Starter
Member
 
oh_noes's Avatar
 
Join Date: Oct 2006
Location: Australia
Posts: 857
Default

Quote:
Originally Posted by f3n1x View Post
No need. (edit: Whoever told you wasn't possible is talking out their backside).

Here's the way i'd do that.

Edit your /etc/network/interfaces file and create a static ip entry for the desired interface with the private network ip address you wish the machine to use assuming a DHCP lease is not obtained like this:

Code:
auto eth0
iface eth0 inet static
address 10.0.94.254
netmask 255.0.0.0
broadcast 10.255.255.255
network 10.0.0.0
post-up /sbin/dhclient eth0 || true
The last line will run dhclient on the eth0 interface and then ensure that even if it fails ifup will continue to consider the interface configured.

Obviously change the details to match your network and system configuration.


Sorry, major bump as I finally got time to implement this.

Firstly, I like your thinking process. I didn't think of doing it that way.

However, when I tried to implement it I found it didn't work. Once dhclient tried to bind to an interface, it immediately reset that static IP to 'nothing' and once it failed the DHCP, it assigned 'nothing' to that interface.

Any ideas?
oh_noes is offline   Reply With Quote
Old 17th July 2009, 4:40 PM   #7
cleary
Mental in the Face
 
cleary's Avatar
 
Join Date: Apr 2003
Location: Griffith NSW
Posts: 3,933
Default

you probably want to run the dhclient command as a pre-up command

man interfaces:
Code:
pre-up command
              Run  command  before  bringing  the  interface  up.  If this command fails then ifup aborts, refraining from marking the interface as configured, prints an error
              message, and exits with status 0.  This behavior may change in the future.
you need to catch it if it fails though, I'd begin with the OR (||) syntax f3nix used above, but I have no idea how to group/apply the static settings after that
__________________
SmugMug
cleary is offline   Reply With Quote
Old 17th July 2009, 7:14 PM   #8
Crinos
Member
 
Crinos's Avatar
 
Join Date: Jul 2002
Location: Tasmania
Posts: 4,019
Default

You're looking in the wrong config file.

Leave /etc/network/interfaces set to 'dhcp', and let dhclient's logic determine how to configure your interface.

Add the following(or similar) block to /etc/dhcp3/dhclient.conf(modified for your network obviously):
Code:
timeout 10;
initial-interval 1;
backoff-cutoff 3;

lease {
  interface "eth0";
  fixed-address 192.168.1.2;
  option subnet-mask 255.255.255.0;
  option broadcast-address 192.168.1.255;
  option routers 192.168.1.154;
}
It will try the DHCP server for a lease, then try to use this "local lease" if it fails. I tweaked the timeout options so you don't sit there waiting for over a minute twiddling your thumbs waiting for DHCP to fail.. these settings cause it to give up after about 15 seconds on my home network, but on a congested network(or one where you can't send DHCP requests quite as aggressively as this, every couple of seconds), where DHCP might take longer, you might want to up the times a bit.

As far as "everyone saying it's not possible"... uh, who's everyone? They should be sacked for a lack of thoroughness when it comes to finding solutions to pretty trivial problems
__________________
OCAU MetaL Club Member #666 | last.fm
2005: Megadeth | 2006: Opeth | 2007: Blind Guardian, Sodom | 2008: Iron Maiden | 2009: Pain of Salvation, Dream Theater
2010: Ensiferum, Sonata Arctica, Wolves in the Throne Room
Crinos is offline   Reply With Quote
Reply

Bookmarks

Sign up for a free OCAU account and this ad will go away!

Thread Tools

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

Forum Jump


All times are GMT +10. The time now is 5:54 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd. -
OCAU is not responsible for the content of individual messages posted by others.
Other content copyright Overclockers Australia.
OCAU is hosted by Internode!