I'm updating the kernel for an appliance, and I've run into a change in how DHCP works. Near the end of my boot script, I check to see if I already have a DHCP-assigned address, and if not, I self-assign:

ifconfig eth0 up

Then, when DHCP finally gets me an address, it assigns it to eth0. And, in fact, this does seem to happen: if I can figure out the address of the appliance, I can talk to it on that DHCP-assigned address.

However, ifconfig continues to show the address.

This is a new behavior I'm seeing with dhcpcd 5.2.12 and linux 3.2.9.

How can I self-assign an address for the case where there is no DHCP server, let DHCP override that assignment when it shows up, and subsequently, how can I find out my DHCP-assigned address?

root@appliance:~# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:22:4D:4F:B3:69  
          inet addr:  Bcast:  Mask:
          inet6 addr: fe80::222:4dff:fe4f:b369/64 Scope:Link
          RX packets:2686 errors:0 dropped:1 overruns:0 frame:0
          TX packets:589 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:403995 (394.5 Kb)  TX bytes:73691 (71.9 Kb)
          Interrupt:20 Memory:fa200000-fa220000 

lo        Link encap:Local Loopback  
          inet addr:  Mask:
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:10 errors:0 dropped:0 overruns:0 frame:0
          TX packets:10 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:985 (985.0 b)  TX bytes:985 (985.0 b)

root@appliance:~# grep dhcp /var/log/messages
Jul 18 16:03:55 (none) dhcpcd[2330]: version 5.2.12 starting
Jul 18 16:03:56 (none) dhcpcd[2330]: eth0: waiting for carrier
Jul 18 16:03:57 (none) dhcpcd[2330]: eth0: carrier acquired
Jul 18 16:03:57 (none) dhcpcd[2330]: eth0: broadcasting for a lease
Jul 18 16:03:57 (none) dhcpcd[2330]: eth0: offered from
Jul 18 16:03:57 (none) dhcpcd[2330]: eth0: acknowledged from
Jul 18 16:03:57 (none) dhcpcd[2330]: eth0: checking for
Jul 18 16:04:02 (none) dhcpcd[2330]: eth0: leased for 86400 seconds
Jul 18 16:04:02 (none) dhcpcd[2330]: forked to background, child pid 2868
  • 1
    ifconfig is deprecated. Its ancient, lacking in significant functionality, and as such is discontinued. Use the iproute2 toolkit instead. I bet if you do ip addr show you'll see the IP show up just fine. – Patrick Jul 19 '12 at 15:17
  • Yes, I stumbled across this in my searches, but "ip" isn't in the distro I'm using as a starting point, and finding a solution within my current quiver is more desirable than going and getting a whole 'nother quiver. (BTW, I'm using Porteus which comes from Slackware 13) – Joshua Smith Jul 19 '12 at 17:15

The whole idea of RFC3927 is that the address should be stateless. As such, DHCP clients are supposed to randomly generate the last two octets of the address and subsequently verify that said address is unique via an ARP. Statically setting a value (i.e. defeats that purpose. Let dhcpcd (or whichever client you're using) do its job and it may address your issue.

| improve this answer | |
  • The appliance has two modes: if you put it on a network with a DHCP server, it should get its address that way; but if you put it on a network with no DHCP server (most likely a crossover cable computer-to-computer connection), it needs to self-assign an address. My Mac has similar behavior, but the way Apple does it is they wait 30-60 seconds and self assign if no DHCP address shows up. I'd rather not have to wait, and in the past, I haven't needed to. The crux of my problem is that ifconfig is not showing me the address that dhcpcd assigned, and I do not understand why not. – Joshua Smith Jul 19 '12 at 13:22
  • iproute2 is a pretty standard package for most distributions. Grab it and try "ip addr show dev ethx" to see if it shows up that way - this should list the mac address and any assigned IP / IPv6 addresses. – rnxrx Jul 20 '12 at 1:20

I found a decent work-around. Instead of setting up eth0 to have a fixed IP address, I created a virtual network interface to act as the fallback. Hence:

ifconfig eth0:0 up

If there is no DHCP server, I can talk to the device using the 169.254 address, and if there is a DHCP server, that gets assigned to eth0, and I can see it with ifconfig!

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.