0

I have a Kubuntu box (12.04) which usually gets its IP via DHCP. However, it also has a hosts file with some entries in case the DHCP+DNS server fails. Now, if there is no DHCP available, I want the machine to look itself up (by hostname) in the hosts file, and choose its IP based on that.

Now, if I wanted to use a fixed address, without a lookup into /etc/hosts, I could add a fallback lease with a pre-specified IP address to /etc/dhclient.conf; but that's not quite what I need.

I'm sure this can be done with complex dhclient hooks; but I'm also sure someone has thought about this and implemented it already...

2
  • What's the use of this? Jan 20, 2014 at 10:11
  • @MariusMatutiae: This will go into a clone image. I expect users deploying the cloned partitions to change the hostname, but not to start messing around with IPs. I know a better solution is to deploy something like puppet, but like I said - the assumption is that the server(s) are down.
    – einpoklum
    Jan 20, 2014 at 11:57

1 Answer 1

0

Probably you are looking for lease section on dhclient.conf.

For example in /etc/dhcp/dhclient.conf:

lease {
  interface "eth0";
  fixed-address 192.33.137.200;
  medium "link0 link1";
  host-name "andare.swiftmedia.com";
  option subnet-mask 255.255.255.0;
  option broadcast-address 192.33.137.255;
  option routers 192.33.137.250;
  option domain-name-servers 127.0.0.1;
  renew 2 2000/1/12 00:00:01;
  rebind 2 2000/1/12 00:00:01;
  expire 2 2000/1/12 00:00:01;
}
4
  • That doesn't solve my problem. That is, it will use an IP address I've manually written into dhclient.conf, it will not look up the hostname in /etc/hosts.
    – einpoklum
    Jan 20, 2014 at 11:58
  • cat /etc/hosts | grep `hostname -f` | egrep -v "^127" Jan 20, 2014 at 12:54
  • Yes, but I need to have dhclient run that script at some point.
    – einpoklum
    Jan 20, 2014 at 14:28
  • otherwise it is impossible, I can draft this sctipt Jan 21, 2014 at 7:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .