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.

Jeremy Friesner
  • 1,311
  • 1
  • 14
  • 25
  • 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 Nov 11 '10 at 01: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 Nov 11 '10 at 01: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 Nov 11 '10 at 01:41
  • I'm assuming that "without requiring any manual configuration" means you can't configure the server and you can't install any packages? If that's the case, then I see no possible solution. If that's *not* the case, please elaborate. – Cypher Nov 11 '10 at 01:57
  • 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](http://wiki.debian.org/ZeroConf). – Steven Monday Nov 11 '10 at 02:34
  • I'm curious: why are you trying to do this? – Jed Daniels Nov 11 '10 at 02:59
  • 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) – Jeremy Friesner Nov 11 '10 at 05:10

5 Answers5

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.

Zanchey
  • 3,041
  • 20
  • 28
  • 1
    Question requirement: "without requiring any manual configuration" – Chris S Nov 11 '10 at 04:01
  • Question requirement: "without requiring any manual configuration" – Arenstar Nov 11 '10 at 04:44
  • 1
    I think you mean "without requiring manual assignment", which is not the same. – Zanchey Nov 11 '10 at 05: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 Nov 11 '10 at 05:12
  • 1
    Tell you what, champ, how about you check out the updated question. – Zanchey Nov 11 '10 at 05:27
  • The box would be basically useless if it's headless. You'd have no idea what the IP is, no DNS, no record on a DHCP server, it's not a routable IP, no keyboard/screen to login to the computer. Also your answer did not satisfy the question that was asked at the time you answered. – Chris S Nov 12 '10 at 02:55
  • 1
    Not completely. The boxes can broadcast, and can discover each other by receiving broadcasts. – Fahad Sadah Nov 13 '10 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.

Sam Halicke
  • 6,122
  • 1
  • 24
  • 35
  • 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? – Jeremy Friesner Nov 11 '10 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. – Sam Halicke Nov 12 '10 at 14:29
2

I think what you are looking for is zeroconf.

NeilF
  • 21
  • 2
  • 1
    Question requirement: "without requiring any manual configuration" – Chris S Nov 11 '10 at 04:00
  • Question requirement: "without requiring any manual configuration" – Arenstar Nov 11 '10 at 04: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? – Jeremy Friesner Nov 11 '10 at 05: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 Nov 11 '10 at 05: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).

crb3
  • 1
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.

mtbkrdave
  • 101