Arch Linux: eth0 no carrier - network fails at boot

4

The problem

My computer is connected to a network where dhcp is required. So my network configuration in /etc/rc.conf looks like

interface=eth0
address=
netmask=
broadcast=
gateway=

My deamons are

DAEMONS=(!hwclock syslog-ng network netfs crond ntpd)

With this configuration, Arch hangs at boot a long time at "Network" (Still it says "[done]", but after boot I have no connection). I found out two workaround:

Workaround 1

  • remove network from deamons
  • run mii-tool --reset eth0 and dhcpcd eth0 after boot (somehow it does not work when placing these commands in /etc/rc.local.

Then dhcp work very quickly (because of the reset!). Before executing the first command, ip link show eth0 has "NO CARRIER" in output. Afterwards, it doesn´t. (Also, mii-tool first shows "no link", afterwards eth0: 10 Mbit, half duplex, link ok.

Workaround 2

  • Change network configuration to

    interface=eth0
    address=x.y.z.21
    netmask=255.255.255.0
    broadcast=xxx.y.z.255
    gateway=x.y.z.254
    

    whereas x, y, z build the specific adresses of the network (Though dhcp is used, I get a static ip).

  • Add the commands mii-tool --reset eth0 and dhcpcd eth0 to /etc/rc.local

Now network starts quickly at boot (though I don´t know if successfully), the commands in /etc/rc.local are executed and the connection is fine after login.

What to do?

So the problem seems to be that dhcpcd stucks at "wating for carrier" or sth.

I do not like the workaround, because some deamons need network (though they seem to start). What can I do to have eth0 ready for dhcp at boot? Or is there another problem?

user905686

Posted 2012-02-23T11:25:20.287

Reputation: 425

Which Linux network driver is it using? "lsmod" should probably tell you. I also suspect you have either a dodgy network cable or some other negotiation issue on the physical network, as 10mbit half-duplex is very low for current hardware. – pjc50 – 2012-02-23T13:20:44.490

I am using the r8169 driver, this seems to be ok. Thanks for noticing the 10mbit... Indeed, I should have a much faster connection here (testing with downloads showed that is doesn´t get over 1MB/s so there must be a problem). I do not think there is a physical problem, unter Windows it works. – user905686 – 2012-02-23T14:22:14.337

Answers

1

You can't have eth0 ready before DHCP is complete, assuming you want DHCP. I suspect what you really want is to have the machine complete the boot process without waiting for it, and having the network configuration proceed in the background. For example, this will allow you to login quickly, and usually, the network config will be done by the time you need it. To do that, instead of having the init scripts attempt DHCP themselves, you have to make them start a daemon that takes care of the network configuration dynamically, including DHCP.

Concerning your observation of network services depending on the network, they usually don't need more than the loopback interface to be set up, assuming you have them bind to 0.0.0.0 instead of any specific local address. (daemons usually do that by default, so it should work unless you made them bind to some specific address)

For the purpose of background network configuration I recommend my NCD programming language, which allows you to program the network config in a special language. Here's a simple NCD script (/etc/ncd.conf) that will perform DHCP on eth0:

process lan {
    # Set device.
    var("eth0") dev;

    # Wait for device, set it up, and wait for network cable.
    net.backend.waitdevice(dev);
    net.up(dev);
    net.backend.waitlink(dev);

    # DHCP configuration.
    # net.ipv4.dhcp() will block here until it obtaines an IP address.
    # Note that it will only obtain the IP address, and *not* assign it;
    # we do that with a separate command below.
    net.ipv4.dhcp(dev) dhcp;

    # Check IP address - make sure it's not local.
    # If you have other reserved subnets around, check for those too.
    ip_in_network(dhcp.addr, "127.0.0.0", "8") test_local;
    ifnot(test_local);

    # Assign IP address, as obtained by DHCP.
    net.ipv4.addr(dev, dhcp.addr, dhcp.prefix);

    # Add default route, as obtained by DHCP.
    net.ipv4.route("0.0.0.0", "0", dhcp.gateway, "20", dev);

    # Configure DNS servers, as obtained by DHCP.
    net.dns(dhcp.dns_servers, "20");
}

To use this, disable the network daemon and instead use the badvpn-ncd daemon. When started, the NCD daemon will be taking care of your network config in the background. Alternatively, you can test it from the terminal directly using the badvpn-ncd program. You can install NCD from the AUR.

If your daemons do in fact depend on the network interfaces being up, you can start the daemons at appropriate time from NCD using the daemon() command, without using their init scripts (not available in stable version).

Some alternatives to NCD are netcfg and ifplugd. While they may be able to use the Arch network config files, they are extremely limited compared to NCD.

EDIT: I seem to have missed that your system is having a problem with link detection. To check, try booting without any automatic interface configuration, keeping eth0 down. Then login and try:

ip link set dev eth0 up

Assuming the network cable is plugged in, the link should quickly establish, making the NO CARRIER flag disappear. If it does not, it's likely problem with your hardware (or drivers).

Ambroz Bizjak

Posted 2012-02-23T11:25:20.287

Reputation: 4 265

Did you get that with doing mii-tool --reset eth0 and then dhcp manually after boot the connection establishes very quickly? It only hangs when starting network in deamons with a usual dhcp configuration. But with setting a static IP configuration "network" is (sure) very fast at boot. So do you mean there is no problem for my other deamons if network is not really working? Can I then also disable "network" in deamons? – user905686 – 2012-02-23T14:29:54.327

Have you verified that the mii-tool command it in fact changes anything? Try booting with no automatic config, waiting some time, then running dhcpcd manually. I'm suspecting that what makes it work is really just waiting some time after boot, and this may be the reason why putting the mii-tool command in /etc/rc.local didn't help. If it turns out that waiting does indeed solve it, you can have whatever configures the interface wait some time before bringing it up. (which, by the way, is trivial if you use NCD; just do a sleep("5000", "0"); before net.up() ) – Ambroz Bizjak – 2012-02-24T02:05:44.170

Yes, look at Workaround 2. Just after boot (before login) the commands (including mii-tool --reset) are executed and network works immediately! – user905686 – 2012-02-24T16:03:50.103

Conclusion: somewhere between the drivers and the card there is a bug, and mii-tool kicks them into working properly. – pjc50 – 2012-02-28T10:44:15.513