Ethernet


This chapter describes common information and instructions of Ethernet on IoT Yocto, such as command to configure DHCP or static IP and so on.

But Ethernet on different platforms may have some platform-specific instructions or test results. For example, you will get different throughputs on different platforms.


Change the MAC Address

Note

Current IoT Yocto does not support changing permanent MAC address with ethtool.

IoT Yocto v21.3 and later release uses systemd to manage network settings in Linux OS, including MAC addresses.

By default, systemd generates a temporary MAC address for the ethernet interface with following steps:

  • First, systemd generates a unique machine-id and store it in /etc/machine-id during boot up after whole image has been flashed.

  • Then, systemd uses this machine-id to calculate a unique MAC address.

  • After that, the unique MAC address will be applied to Ethernet driver. This is a kind of temporary MAC address which is calculated each time during system boot up.

To change the temporary MAC address and store it in the file system, please follow these steps:

  • Create a file /etc/systemd/network/20-eth0.network. Systemd will use the setting in this file to override the generated address.

  • Edit the configuration file and insert the following configurations:

    [Match]
    Name=eth0
    
    [Link]
    MACAddress=16:55:61:43:11:22
    

Please replace the example MAC address 16:55:61:43:11:22 to the MAC address that you needed.

systemd-networkd vs NetworkManager

A Linux system with both systemd-networkd and NetworkManager installed would have two different network management services. NetworkManager is a more widely used and user-friendly service for managing network connections. On the other hand, systemd-networkd is a system daemon that manages network connections in the background and is typically used in headless servers or devices without a graphical user interface.

However, it is recommended to only use one service at a time to avoid conflicts and ensure proper network configuration.

  • The “rity-bringup-image” meta layer only has systemd-networkd.

  • The “rity-demo-image” meta layer has both systemd-networkd and NetworkManager installed.

systemd-networkd

Enable or Disable systemd-networkd

If you want to use another network management service, it’s good to know how to enable and disable the systemd-networkd service. You need to stop systemd-networkd prior to disable it.

systemctl stop systemd-networkd
systemctl disable systemd-networkd

If you want to switch back systemd-networkd, simply enable and then start the service.

systemctl enable systemd-networkd
systemctl start systemd-networkd

Configure Static IP with systemd-networkd

DHCP is enabled by default with systemd-networkd. If static IP is required, use /etc/systemd/network/20-eth0.network to modify connection setting. For example, set IP 192.168.0.1 and netmask 255.255.255.0 with default gateway 192.168.0.254 to iface eth0. After that, reload systemd-networkd via systemctl.

[Match]
Name=eth0

[Network]
Address=192.168.0.1/24
Gateway=192.168.0.254
DNS=8.8.8.8

NetworkManager

Enable or Disable NetworkManager

If you want to use another network management service, it’s good to know how to enable and disable the NetworkManager service. You need to stop NetworkManager prior to disable it.

systemctl stop NetworkManager
systemctl disable NetworkManager

If you want to switch back NetworkManager, simply enable and then start the service.

systemctl enable NetworkManager
systemctl start NetworkManager

Check the Status of NetworkManager

Use systemctl to check if the NetworkManager is still running.

systemctl status NetworkManager

Check the output line which contains Active: for the status of NetworkManager. For example, the output shows NetworkManager is running.

active (running)

The other output show the service has been stopped.

inactive (dead)

The configuration of NetworkManager service is stored in file /etc/systemd/system/multi-user.target.wants/NetworkManager.service. You can check this file if any customization is required for this service.

Control Network Settings via NetworkManager

Note

We will usually suggest customer to disable systemd-networkd before configuring NetworkManager. Other service like avahi-daemon or dhcpcd will also affect network configurations.

NetworkManager is enable by default. This service is registered as NetworkManager.service (also known as NetworkManager) to systemd. nmcli is the interactive tool for controlling the NetworkManager. User could use nmcli to check connections managed by NetworkManager.

nmcli -p connection show

You should see the following output if you’ve never touched network setting.

======================================
  NetworkManager connection profiles
======================================
NAME                UUID                                  TYPE      DEVICE
------------------------------------------------------------------------------->
Wired connection 1  4080d986-b3c7-3601-a837-3ca6ee6b2ab2  ethernet  eth0

Control Network Settings via Tool NMCLI

nmcli is the tool for configuring and controlling each network interface managed by NetworkManager. nmcli can enable or disable the network while keeps NetworkManager alive. You can set the following commands to enable or disable networking controlled by NetworkManager. All interfaces managed by NetworkManager are deactivated when networking is disabled. For more detail, you can check the online manual of nmcli: https://developer-old.gnome.org/NetworkManager/stable/nmcli.html

nmcli networking off
nmcli networking on

Configure Static IP with NetworkManager

DHCP is enabled by default with NetworkManager. If static IP is required, use nmcli to modify connection setting. For example, set IP 192.168.0.1 and netmask 255.255.255.0 with default gateway 192.168.0.254 to "Wired connection 1" (eth0). After that, reload NetworkManager via systemctl.

nmcli con mod "Wired connection 1" ip4 "192.168.0.1/24" gw4 192.168.0.254
systemctl reload NetworkManager

Use ip a to check if the static IP has been applied.

ip a
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 92:b2:7c:21:08:2d brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.1/24 brd 192.168.0.255 scope global noprefixroute eth0
        valid_lft forever preferred_lft forever
    inet6 fe80::3154:c53:c5e5:6d6f/64 scope link noprefixroute
        valid_lft forever preferred_lft forever

Check the new configuration has been stored in file /etc/NetworkManager/system-connections/Wired connection 1.nmconnection

cat /etc/NetworkManager/system-connections/Wired\ connection\ 1.nmconnection

It should show the new IP value is assigned to variable address1.

[ipv4]
    address1=192.168.0.1/24,192.168.0.1

Avoiding wrong network settings affected by other modules

Note

If dhcpcd is activate on the system, for example, the board is configured as an wireless router, configure static IP of eth0 in /etc/dhcpcd.conf. Please run systemctl restart dhcpcd after new configuration has been applied.

interface eth0
static ip_address = 192.168.0.1/24
static router = 192.168.0.254
static domain_name_server = 8.8.8.8

Note

If avahi-daemon is activate on the system, disable eth0 from avahi-daemon. Add the following line in /etc/avahi/avahi-daemon.conf

deny-interfaces=eth0

Please run systemctl reload avahi-daemon after new configuration has been applied.

Reference Boards

Ethernet on different platforms may have some platform-specific instructions or test results. For example, you will get different benchmark results on different platforms. Please find more details about difference of Ethernet on each platform: