Network eth0 DHCP, static ip and autonegotiation issues

36,711

As per discussion in the chat, turn off auto-negotiation on the server and fix the network speed to the highest level that the Network Interface Card (NIC) can sustain.

Start with 10Mbps, half duplex and work upwards to 10Mbps FD, 100Mbps HD, ... until the problem starts. Then go down one notch and leave it at that speed.

First, install ethtool (if already installed you will just get a warning that the latest version is already installed)

sudo apt-get install ethtool

Now:

  1. Type the following command (and test them one by one)

    sudo ethtool --change eth0 speed xxx duplex yyy autoneg off
    

    where xxx = 10, 100 or 1000 and yyy = half or full.

    So start with 10 half, 10 full, 100 half, ...

  2. Do an ifconfig to check whether you got an IP address.

  3. Go back to 1 until it stops working and use the previous values that still worked to:

  4. To make the change permanent, execute the following command:

    sudo nano /etc/network/interfaces
    

    and type at the pre-up section:

    pre-up /usr/sbin/ethtool --change eth0 speed xxx duplex yyy autoneg off 
    
Share:
36,711

Related videos on Youtube

Mic1780
Author by

Mic1780

Creator of Websockets in C I am a Programmer for Coolstuffinc I enjoy solving difficult programming problems while optimizing memory usage and speed.

Updated on September 18, 2022

Comments

  • Mic1780
    Mic1780 over 1 year

    Background

    I am running an Ubuntu Server on 14.04 which is currently up-to-date. I have only one network device connected to it. When I use my Ethernet cord and connect it from the wall to my laptop (running windows 7) the DHCP resolves without issue.

    Problem

    When I connect my Ethernet cord from the wall to my server (running Ubuntu) and power on my server, the DHCP server does not assign my server an IP address. However, when I connect the cord from my server to my laptop using the laptops' Ethernet connected to connect through my Wifi connection the server will get an IP address from DHCP via the laptop. Lastly, after I get an IP from the laptop connection I use the following commands and then DHCP works when the cord is connected from the wall to the server:

    sudo dhclient -r
    sudo dhclient -v eth0
    

    The next time I restart the server via sudo shutdown -r now the server will not be able to get an IP again from DHCP with the cord from the wall to the server.

    Note that when i assign a static address in /etc/network/interfaces file the network will not assign it the IP and the interface will be down.

    Question

    Is there a way to fix the problem I am having with my network not being able to discover the DHCP server when I power on the server?

    If you need more information please let me know.

    Additional Information

    dhclient before connecting to laptop

    DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 3 (xid=0x********)
    DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 3 (xid=0x********)
    DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 6 (xid=0x********)
    ...
    No DHCPOFFERS received
    No working leases in persistent database - sleeping.
    

    dhclient with server connected to laptop

    DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 3 (xid=0x*********)
    DHCPREQUEST of 192.168.137.233 on eth0 to 255.255.255.255 port 67 (xid=0x*********)
    DHCPOFFER of 192.168.137.233 from 192.168.137.1
    DHCPACK of 192.168.137.233 from 192.168.137.1
    bound to 192.168.137.233 -- renewal in 275 seconds.
    
    ifconfig eth0
    eth0      Link encap:Ethernet  HWaddr 00:22:64:23:7c:da  
              inet addr:192.168.137.233  Bcast:192.168.137.255  Mask:255.255.255.0
              inet6 addr: fe80::222:64ff:fe23:7cda/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:28265 errors:0 dropped:0 overruns:0 frame:0
              TX packets:2781 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:4655957 (4.6 MB)  TX bytes:415144 (415.1 KB)
    

    dhclient after laptop DHCP and cord reconnected from wall to server

    DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 3 (xid=0x********)
    DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 8 (xid=0x********)
    DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 15 (xid=0x********)
    DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 11 (xid=0x********)
    DHCPREQUEST of 192.168.1.126 on eth0 to 255.255.255.255 port 67 (xid=0x*******)
    DHCPOFFER of 192.168.1.126 from 192.168.1.254
    DHCPACK of 192.168.1.126 from 192.168.1.154
    bound to 192.168.1.126 -- renewal in 41950 second.
    
    ifconfig eth0
    eth0      Link encap:Ethernet  HWaddr 00:22:64:23:7c:da  
              inet addr:192.168.1.126  Bcast:192.168.1.255  Mask:255.255.255.0
              inet6 addr: fe80::222:64ff:fe23:7cda/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:33438 errors:0 dropped:0 overruns:0 frame:0
              TX packets:3391 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:5245215 (5.2 MB)  TX bytes:550462 (550.4 KB)
    

    network interface (lshw)

    sudo lshw -class network
    
      *-network
           description: Ethernet interface
           product: RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller
           vendor: Realtek Semiconductor Co., Ltd.
           physical id: 0
           bus info: pci@0000:02:00.0
           logical name: eth0
           version: 02
           serial: 00:22:64:23:7c:da
           size: 100Mbit/s
           capacity: 1Gbit/s
           width: 64 bits
           clock: 33MHz
           capabilities: pm msi pciexpress msix vpd bus_master cap_list rom ethernet physical tp mii 10bt 10bt-fd 100bt 100bt-fd 1000bt 1000bt-fd autonegotiation
           configuration: autonegotiation=on broadcast=yes driver=r8169 driverversion=2.3LK-NAPI duplex=full ip=192.168.1.82 latency=0 link=yes multicast=yes port=MII speed=100Mbit/s
           resources: irq:42 ioport:e800(size=256) memory:febff000-febfffff memory:fdff0000-fdffffff memory:febc0000-febdffff
    

    Update:

    My /etc/network/interfaces file is as such

    auto lo
    iface lo inet loopback
    
    auto eth0
    iface eth0 inet dhcp
    

    I found a temporary fix that seems to work but I would not like it to be my solution if we can solve this problem. I changed the interfaces file like so

    auto lo
    iface lo inet loopback
    
    auto eth0
    iface eth0 inet dhcp
        pre-up ifconfig $IFACE up
        pre-up mii-tool -R
    

    That would (i believe) tell the interface to reset and for some reason it allowed the DHCP to resolve like it should. Like I said there has to be an actual fix outside of this one.

    Solution:

    With the help of Fabbys' answer I was able to come up with a more viable solution that I can live with.

    Open /etc/network/interfaces and configure the ethernet interface one of these following ways:

    DHCP

    auto eth0
    iface eth0 inet dhcp
        pre-up ifconfig $IFACE up
        pre-up ethtool -s $IFACE speed 100 duplex full autoneg off
    

    Static

    auto eth0
    iface eth0 inet static
        post-up ethtool -s $IFACE speed 100 duplex full autoneg off
        address x.x.x.x #Internal IP
        netmask 255.255.255.0
        gateway x.x.x.y #Gateway IP
        dns-nameservers 8.8.8.8 #Google DNS
    

    I hope this helps someone else in the future.

    • Fabby
      Fabby over 9 years
      what happens if you do a sudo ufw disable? Have you wiresharked it yet?
    • Mic1780
      Mic1780 over 9 years
      Turning off the firewall has no effect (yes i did try it). I have wiresharked it and during the DHCPDISCOVER wireshark does not report any packets.
    • Fabby
      Fabby about 8 years
      Wow! Acceptance for a question&answer posted more then a year ago! You've broken my personal record! (Favour returned: q upvoted) ;-)
  • Mic1780
    Mic1780 about 9 years
    Just as a follow-up to this. I was messing with my eth0 interface and using ethtool I was able to config that it is in fact the autonegotiation that was preventing a successful link. I used ethtool -s eth0 autoneg off and it brought my link up.
  • Fabby
    Fabby about 9 years
    @Mic1780: Does ethtool -s eth0 autoneg off survive a cold boot? (my solution does, but if yours survives a cold boot, that's easier to implement) Oh, and thanks for the feed-back! ;-)
  • Mic1780
    Mic1780 about 9 years
    If you check out the solution section of my answer, that is how i have it set up now (I am using the static portion). And yes, when I run sudo shutdown -r now it will survive if you have ethtool -s eth0 autoneg off in the interfaces file.
  • Fabby
    Fabby about 9 years
    :-) That's why I asked: sudo shutdown -r now is a warm boot. sudo shutdown now, remove the power/battery/ups then plugging them back in and use the physical on/off switch is a cold boot. ;-) Don't try if you don't have physical access, but if you ever move that thing, remember! ;-)
  • Joseph
    Joseph over 2 years
    Any idea where /etc/network/interfaces lives these days? I have no such file on the ubuntu 20.04.
  • Fabby
    Fabby over 2 years
    No, because I migrated to Manjaro in the meantime, but if you ask a new question and refer to this answer and ask how to permanently fix this in 20.04 someone else will know...