1

I have a piece of equipment I would like to default to a specific IP address when no dhcp servers are available.

I have set the following static lease in /etc/dhcp/dhclient.conf:

timeout 30;

lease {
  interface "eth0";
  fixed-address 192.168.1.254;
  option subnet-mask 255.255.255.0;
  option routers 127.0.0.1;
  expire never;
}

It works, but eth0 will only get this IP when dhclient.eth0.leases and dhclient.leases in /var/lib/dhcp/ are empty.

Unless you guys have a good reason to advise against it, I would prefer if the static lease from dhclient.conf was assigned when a dhcp server doesn't reply instead of using old leases. It would make the troubleshooting process easier and allow some way to reach the equipment which is only accessible via ssh and has no display to print out the current ip.

I read through the dhclient manual and a lot of google search results but couldn't find a built in way or any suggestions on how to do this.

Solutions I thought of:

1-Empty dhclient.leases and set permissions so it can't be modified
2-Link dhclient.leases to /dev/null and set permissions so it can't be modified
3-Same as #1 but instead of setting up the static lease in dhclient.conf, manually add it to dhclient.leases before setting permissions.

3
  • I tested option #1 and set attributes using {chattr -i} which caused dhclient to give out errors about being unable to write to the dhcp.eth0.leases file but it wrote to it anyways even though the wait it read it seemed it wouldnt!
    – TCZ8
    Commented Dec 15, 2015 at 17:55
  • Just tested option #2 but didn't change its attributes as dhclient doesn't seem to care about respecting these. The good thing is It works and doesn't give errors. My only concern is making sure the soft link doesn't get replaced when dhclient decides it's time to rotate the file. I couldn't find any info on what triggers the file to be replaced. So I have no clue what and when it will happen. How am I going to test this? Is waiting and hoping for the best my only option?
    – TCZ8
    Commented Dec 15, 2015 at 18:01
  • I meant, I gave no clue if and when it will happen. So far so good.
    – TCZ8
    Commented Dec 21, 2015 at 14:32

2 Answers 2

0

Then there is AVAHI whose primary purpose is to assign an IP address when all else fails.

AVAHI should hand out an impractical 169.254.x.x address.

RFC 5735 specifies 169.254.0.0/16 as the ""link local"" block as described in RFC3927. This is the address range to be used by hosts' auto-configuration, such as when a DHCP server cannot be found.

https://help.ubuntu.com/community/HowToZeroconf

0

I've created '/etc/sysconfig/network-scripts/ifcfg-eth0:0' :

DEVICE=eth0:0
BOOTPROTO=none
ONBOOT=yes
NETWORK=192.168.222.0
NETMASK=255.255.255.0
IPADDR=192.168.222.22
USERCTL=no

This just binds a 2nd static IP to the NIC, using an alias. Not really what I wanted, but will work until I figure out the dhclient.conf stuff.

Alternatively, you can hook up a second network interface card for that static purpose.

You must log in to answer this question.

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