9

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.

7
  • 1
    Seriously, there's millions of sites all over the world that work very nicely on DHCP or Static assignments. Pick one and use it, you'll spend way more time trying to come up with some novel new idea than it will ever be worth. Additionally auto assigned IPs have no router, no DNS setting, and will not route to other networks.
    – Chris S
    Commented Nov 11, 2010 at 1:35
  • By design, there is no way to pick which DHCP server assigns an IP to your computer (even if it is itself). When you turn on your computer, the DHCP client sends a packet on the broadcase interface (essentially all 1's on the host) and the first DHCP server to receive the offer assigns the IP to the computer. Your computer is the last server contacted (because the port has to bounce all the way through the network first) thus why it only works when no other DHCP server exist.
    – Theo
    Commented Nov 11, 2010 at 1:40
  • Your best bet is to make manual work, or have your DHCP server set up reservations. Put your question in context: what is the need for a self-assigned IP and how does it know which IP to use?
    – Theo
    Commented Nov 11, 2010 at 1:41
  • 3
    Look into the avahi-* packages. Zanchey's answer regarding avahi-autoipd is a place to start. There is also a Debian ZeroConf Wiki page. Commented Nov 11, 2010 at 2:34
  • 2
    Jed: I need a box that can be plugged in "headless" to any LAN and communicate with other boxes on that LAN. It does not need to communicate outside the LAN, ever. Its behavior needs to be the same whether a DHCP server is available or not (i.e. it can't stop working or work differently if the DHCP server later goes away, or a new one shows up) Commented Nov 11, 2010 at 5:10

5 Answers 5

8

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.

7
  • 1
    Question requirement: "without requiring any manual configuration"
    – Chris S
    Commented Nov 11, 2010 at 4:01
  • 1
    I think you mean "without requiring manual assignment", which is not the same.
    – Zanchey
    Commented Nov 11, 2010 at 5:04
  • 1
    You probably should have first read the question properly.. "Manual assignment won't do, since I need multiple boxes to work on the same LAN without requiring any manual configuration"
    – Arenstar
    Commented Nov 11, 2010 at 5:12
  • 1
    Tell you what, champ, how about you check out the updated question.
    – Zanchey
    Commented Nov 11, 2010 at 5:27
  • 1
    Not completely. The boxes can broadcast, and can discover each other by receiving broadcasts. Commented Nov 13, 2010 at 20:26
4

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.

2
  • This solution sounds good, but I can't get it to work. :( Changing the interfaces file to specify "iface eth0 inet ipv4ll" just causes an "unknown mode" error to be printed out during the boot sequence, and the interface is not configured. avahi-autoipd is installed, perhaps it is a too-old version? Commented Nov 11, 2010 at 22:23
  • Perhaps? I am using Ubuntu 10.10 in my case, I assume you are using Lenny? If so, you might want to grab the deb-src from squeeze and give it a whirl. Commented Nov 12, 2010 at 14:29
2

I think what you are looking for is zeroconf.

4
  • 1
    Question requirement: "without requiring any manual configuration"
    – Chris S
    Commented Nov 11, 2010 at 4:00
  • Question requirement: "without requiring any manual configuration"
    – Arenstar
    Commented Nov 11, 2010 at 4:45
  • Yes, zeroconf is what I'm looking for... specifically, I'd like to enable zeroconf without also enabling DHCP. Is there a way to do that? Commented Nov 11, 2010 at 5:08
  • You will have to write a custom script to run zeroconf, and then set your interfaces(5) file to iface eth0 inet manual, or do something like the script below.
    – Zanchey
    Commented Nov 11, 2010 at 5:18
0

Nobody's mentioned it yet, so I'll just point out that, if you have control of how the machine boots, you can edit the default entry in GRUB's menu.lst (or whatever it's called this week) to add a "nodhcp" cheatcode to the arguments given the kernel at boot. That should at least keep the machine from sending out an initial IP request, though for how long I couldn't say as I've only really needed it when testing live-CDs (it's all static RFC1918 IP's on my LAN).

1
  • "without requiring any manual configuration" is going to make this tough.
    – Chris S
    Commented Nov 11, 2010 at 3:59
0

Posting for the sake of others Googling for this:

If you are using NetworkManager, As of July 2008 it includes support for avahi-autoipd. Just set BOOTPROTO=autoip in the interface's /etc/sysconfig/network-scripts/ifcfg-* file. NetworkManager will skip DHCP configuration of the interface and go straight to link-local IPv4LL addressing via autoipd.

You must log in to answer this question.

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