How to set Ethernet link speed & duplex

8,508

Agreed with Celada comment, you have also some pre-up, post-up, pre-down, post-down that you can specify in your /etc/network/interfaces to tune your network interface. See https://wiki.debian.org/NetworkConfiguration for reference. Edit, adding a short example, in your case, assuming you would like to use dhcp to configure your interface the following would do the job:

auto eth0
iface eth0 inet dhcp
   pre-up ethtool -s eth0 speed 100 duplex half autoneg off
Share:
8,508

Related videos on Youtube

user5071535
Author by

user5071535

Embedded software developer

Updated on September 18, 2022

Comments

  • user5071535
    user5071535 over 1 year

    How can I configure my Ethernet (eth0) link speed and duplex on my systemd & connman based system?

    I've previously used a script in /etc/network/if-up.d, in which I could make a call like:

    ethtool -s eth0 speed 100 duplex half autoneg off
    

    However, I'm now using a distribution (Angstrom) that uses systemd rather than SysV, so I need to know how to get equivalent functionality there. Is there a way to do this using udev or some other preferred method?

    [EDIT1]

    My distribution is Angstrom (on an embedded ARM board). I'm using Connection Manager to manage networking.

    [EDIT2]

    I was under the assumption that since I have systemd and connman, the old ways of doing things (sysv, sysv init, /etc/network/interfaces, pre-up, post-up, pre-down, etc.) were unavailable to me, or at least superseded.

    Trying my best to write this question well, but I'm afraid my unfamiliarity with some of these things and some of my invalid assumptions may be making it hard to answer. I'll try to refine the question as new information makes things more clear.

    • Tom Hunt
      Tom Hunt over 8 years
      This probably needs doing through whatever you've got managing your networks. It might be NetworkManager, or systemd-networkd, or dhcpcd, or another such thing. Find out what you're running and search for that.
    • Celada
      Celada over 8 years
      This probably doesn't have anything to do with systemd, and more to do with how to configure networking in your distribution. For example, if it's Debian, check /etc/network/interfaces: you would put an up line in that file with your ethtool command — and that's true whether or not you are using systemd.
    • user5071535
      user5071535 over 8 years
      @TomHunt I'm currently using Connection Manager (connman). According to this conversation comments.gmane.org/gmane.linux.network.connman/15736 connman isn't the correct place to do this.
    • Tom Hunt
      Tom Hunt over 8 years
      Looks like udev is probably the place for it, then. You'd want to find your old script, then write a udev rule that identifies the specific network device and runs it when the device is identified.
    • user5071535
      user5071535 over 8 years
      @TomHunt Got any advice on how to do such a thing? I've never written a udev rule, nor do I know how to make it trigger on device identification. Also unless it's bad form, I think I'll replace the 'systemd' with 'udev' in the title of my question since you've helped to correct my presumption.
    • Celada
      Celada over 8 years
      @user5071535 You could do this with udev, but virtually all Linux distributions provide a more comprehensive and better-supported way of managing and configuring network interfaces. Please edit your question to tell us what distribution you are using.
    • Celada
      Celada over 8 years
      That having been said, a udev rule would be something like SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="xx:xx:xx:xx:xx:xx", ATTR{type}=="1", RUN+="/usr/local/bin/your-script-here" where xx:xx:xx:xx:xx:xx is the MAC address of your interface and /usr/local/bin/your-script-here is a script that configures your device including ethtool and ip addr and such to set the IP address. But be careful about interfering with some of the builtin udev rules that control interface renaming (naming of interfaces according to firmware device names). NOT RECOMMENDED!
    • user5071535
      user5071535 over 8 years
      @Celada Distro is Angstrom, edited the question as requested
    • user5071535
      user5071535 over 8 years
      @Celada Thanks for the example! I'm unfamiliar with udev rules, but it seems the basic idea is to run the specified script when the target interface is added (whatever added means). If I can determine that the interface renaming hazard doesn't affect me, maybe I can use this approach.
  • user5071535
    user5071535 over 8 years
    I was under the assumption that since I have systemd and connman, the old ways of doing things (sysv, sysv init, /etc/network/interfaces, pre-up, post-up, pre-down, etc.) were unavailable to me, or at least superseded.
  • user5071535
    user5071535 over 8 years
    I didn't have an /etc/network/interfaces, but I created it and added the commands as you provided, but no dice. I'm guessing that using /etc/network/interfaces is not an option, or at least not the standard way of doing this sort of thing under the configuration I'm using.