Is there any way to force my Linux box to always boot up with a self-assigned IP address?
This is perhaps an unusual request: I'm trying to get a Debian Linux box to always give itself a self-assigned IP address (i.e. 169.254.x.y) on boot. In particular, I want it to do that even when there is a DHCP server present on the LAN. That is, it should not request an IP address from the DHCP server.
From what I can see in the "man interfaces" text, there is an option for "manual", and an option for "dhcp". Manual assignment won't do, since I need multiple boxes to work on the same LAN without requiring any manual configuration... and "dhcp" does what I want, but only if there is no DHCP server on the LAN. (A requirement is that the functionality of these boxes should not be affected by the presence or absence of a DHCP server).
Is there a trick that I can use to get this behavior?
EDIT: By "no manual configuration", I mean that I should be able to take this box (headless) to any LAN anywhere, plug in the Ethernet cable, and have it do its thing. I shouldn't have to ssh to the box and edit files to get it working each time it is moved to a different LAN.
If you install the avahi-autoipd
package, and run it with the --force-bind
option in a custom init or if-up.d script, you will always get a link-local address.
You can then use iface eth0 inet manual
in your interfaces(5) file, although you will need to edit /etc/network/if-up.d/avahi-autoipd
to add manual
to the method lines.
There is more information about avahi-autoipd on the Avahi wiki.
Personally, I would edit /etc/network/if-up.d/avahi-autoipd
to with something like:
--- avahi-autoipd 2010-08-04 04:26:49.000000000 +0800
+++ avahi-autoipd.1 2010-11-11 09:57:54.000000000 +0800
@@ -13,10 +13,13 @@
esac
case "$METHOD" in
- static|dhcp|NetworkManager) ;;
+ static|dhcp|NetworkManager|linklocal) ;;
*) exit 0
esac
+if [ "$METHOD" == "linklocal" ]; then
+ /usr/sbin/avahi-autoipd --force-bind --daemonize --wait $IFACE 2> /dev/null
+fi
if [ -x /bin/ip ]; then
# route already present?
You can then list interfaces as iface eth0 inet linklocal
. The edits to be made to the if-down.d
script are left as an exercise to the reader.
You may have missed this in man interfaces
:
The ipv4ll Method
This method uses avahi-autoipd to configure an interface with an IPv4 Link-Layer address
(169.254.0.0/16 family). This method is also known as "APIPA" or "IPAC", and often col‐
loquially referred to as "Zeroconf address".
Options
(No options)
So, you would have an interfaces
section as such:
auto eth0
iface eth0 inet ipv4ll
Install avahi-autoipd
, and that should do it.
I think what you are looking for is zeroconf.