Skip to main content
Version: BSP 6.x.y

Ethernet/Network (Linux)

Introduction​

This article provides instructions on how to use utilities for network configuration provided in the Toradex BSP reference images. It contains information on how to use connman and/or systemd-networkd, or how to replace connman with NetworkManager using Yocto.

Yocto BSP Reference Images​

The Toradex BSP reference images currently provide two utilities for network configuration: connman and systemd-networkd. By default, the Ethernet port is managed by connman, and the USB RNDIS interface by systemd-networkd. Depending on the application, it might make sense to use one of those utilities over the other.

By default, connman will try to configure any available network interfaces and tries to keep only (the best) connection connected at any time. The design is targeted toward interactive, wireless devices such as tablets, etc. The systemd-provided utility systemd-networkd, on the other hand, emphasizes headless server systems with static configuration.

Torizon OS​

Torizon OS uses NetworkManager. Even though this article has some information about it, it's meant for people using the Yocto BSP reference images, not people using Torizon OS. If you are using Torizon OS, go directly to Networking with Torizon OS.

ConnMan​

Our latest V2.x images use connman as the overall connection management framework. The GUI management tool can be started with connman-properties or by starting the taskbar applet connman-applet.

The command-line interface tool connmanctl can be used in an interactive shell mode or as a single command using arguments.

# connmanctl services
*AO Wired { ethernet_00142d269dfd_cable }

# connmanctl services ethernet_00142d269dfd_cable
[ ethernet_00142d269dfd_cable ]

Type = ethernet
Security = [ ]
State = online
Favorite = True
Immutable = False
AutoConnect = True
Name = Wired
Ethernet = { Method=auto Interface=enp7s0 Address=00:14:2D:26:9D:FD MTU=1500 }
IPv4 = { Method=dhcp Address=192.168.10.162 Netmask=255.255.255.0 Gateway=192.168.10.1 }
IPv4.Configuration = { Method=dhcp }
IPv6 = { }
IPv6.Configuration = { Method=auto Privacy=disabled }
Nameservers = [ 8.8.8.8 ]
Nameservers.Configuration = [ ]
Timeservers = [ 192.168.10.1 ]
Timeservers.Configuration = [ ]
Domains = [ colibri.net ]
Domains.Configuration = [ ]
Proxy = { URL=http://wpad.colibri.net/wpad.dat Method=auto }
Proxy.Configuration = { }
Provider = { }

Using the interactive mode to configure a static Ethernet address:

# connmanctl
connmanctl> config ethernet_00142d259a48_cable --ipv4 manual 192.168.10.2 255.255.255.0 192.168.10.1
connmanctl> exit

Using the interactive mode to configure the nameservers (DNS):

# connmanctl config ethernet_00142d259a48_cable --nameservers 8.8.8.8

Using the interactive mode to get an IP automatically via DHCP:

# connmanctl
connmanctl> config ethernet_00142d259a48_cable --ipv4 dhcp
connmanctl> exit

Tethering​

ConnMan can be used for tethering which allows sharing a connection of a device for another locally connected device. The Toradex module running ConnMan would be the device sharing the connection.

Tethering puts some requirements on the kernel. The README in the ConnMan source tree holds more information on these requirements.

USB gadget tethering​

info

Since image V2.4 systemd-networkd has control over the USB gadget Ethernet interface (RNDIS). Remove the rndis.network file under /etc/systemd/networkd and make sure usb/rndis is not part of NetworkInterfaceBlacklist in /etc/connman/main.conf.

To enable tethering on the USB gadget interface make sure the USB gadget driver is loaded/enabled first (see USB Device Mode (Linux)). Then ConnMan can be used to enable tethering mode:

# connmanctl 
connmanctl> tether gadget on
connmanctl> [ 194.725436] device usb0 entered promiscuous mode
[ 194.737525] tether: port 1(usb0) entered forwarding state
[ 194.743077] tether: port 1(usb0) entered forwarding state
Enabled tethering for gadget

To preconfigure ConnMan to automatically start Gadget interfaces upon start-up two configuration files are needed:

The main.conf under /etc/connman/main.conf

/etc/connman/main.conf
[General]
PersistentTetheringMode=true
TetheringTechnologies=gadget

The service settings file under /var/lib/connman/settings

/var/lib/connman/settings
[global]
OfflineMode=false

[Wired]
Enable=true
Tethering=false

[Gadget]
Enable=true
Tethering=true

For other configuration options, the Python interface documentation has some useful configuration examples: https://pythonhosted.org/pyconnman/config.html

Multiple active connections​

By default, ConnMan is configured to only have one connected technology. This means it will connect only to one interface after boot, even if there are multiple available and configured to auto-connect. But sometimes one wants to have two or more interfaces to be auto connected, e.g. ethernet and WiFi. To achieve this, one can change the ConnMan configuration file at /etc/connman/main.conf, e.g. to enable auto-connect for both ethernet and WiFi, change the following entries accordingly in the configuration file:

/etc/connman/main.conf
PreferredTechnologies=wifi,ethernet
SingleConnectedTechnology=false

Check the man-page of the ConnMan configuration file for more details.

NetworkManager​

If you want to use NetworkManager, remove connman and add NetworkManager on a custom OpenEmbedded build. See an example below:

local.conf
# Remove connman
IMAGE_INSTALL:remove = " connman"
IMAGE_INSTALL:remove = " connman-client"
IMAGE_INSTALL:remove = " connman-gnome"
IMAGE_INSTALL:remove = " connman-plugin-wifi"
IMAGE_INSTALL:remove = " connman-plugin-ethernet"
IMAGE_INSTALL:remove = " connman-plugin-loopback"
# Add NetworkManager
IMAGE_INSTALL:append = " networkmanager"
IMAGE_INSTALL:append = " modemmanager"

Check out the OpenEmbedded (core) article to learn how to build and customize a sample Linux image with OpenEmbedded.

systemd-networkd​

If you plan to use systemd-networkd as the primary network configuration utility, you should remove connman first (when using a console-only image, you won't need to remove connman-gnome). You can use the package manager to remove the package from pre-built images by invoking

# opkg remove connman-gnome connman

To remove connman when building an image using OpenEmbedded remove CONMANPKGS from IMAGE_INSTALL in the image recipe recipes/images/angstrom-lxde-image.bb in the meta-toradex layer (see OpenEmbedded (core) how to build a complete image).

Manual Configuration for Wired Connections​

caution

If you are using Torizon OS, go directly to Networking with Torizon OS - Static Network Configuration.

Create a file named 'wired.network' under /etc/systemd/network/

# vi /etc/systemd/network/wired.network

For dynamic IP connection fill in the file with the following content:

/etc/systemd/network/wired.network
[Match]
Name=eth0

[Network]
DHCP=ipv4

For static IP connection:

/etc/systemd/network/wired.network
[Match]
Name=eth0

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

Bridge​

Using systemd-networkd one can easily setup a network bridge between two Ethernet interfaces:

/etc/systemd/network/eth.network
[Match]
Name=eth*

[Network]
Bridge=br0
/etc/systemd/network/bridged.network
[Match]
Name=br0

[Network]
DHCP=ipv4

VLAN​

This example configures a dynamic IP configuration on the ethernet device (untagged) and also creates a new Ethernet interface associated with VLAN 100 (tagged). The example uses a dynamic IP configuration on VLAN 100 too.

/etc/systemd/network/wired.network
[Match]
Name=eth0

[Network]
DHCP=ipv4
VLAN=eth0.100
/etc/systemd/network/eth0.100.netdev
[NetDev]
Name=eth0.100
Kind=vlan

[VLAN]
Id=100
/etc/systemd/network/vlan100.network
[Match]
Name=eth0.100

[Network]
DHCP=v4

Integrating Network Files Into an OpenEmbedded/Yocto Image​

The integration should be done similarly to the existing rndis.network file, see bbappend and files subdirectory of our systemd configuration:

Place the above file 'wired.network' inside systemd folder at your oe-core layer directory (at ${LAYERDIR}/meta-toradex/recipes-core/systemd) and edit the bbappend file adding the 'wired.network' file like bellow:

${LAYERDIR}/meta-toradex/recipes-core/systemd/systemd_%.bbappend
FILESEXTRAPATHS:prepend := "${THISDIR}/systemd:"

SRC_URI += " \
file://wired.network \
file://rndis.network \
file://0001-systemd-udevd.service.in-set-MountFlags-shared.patch \
"

PACKAGECONFIG:append = " networkd"

do_install:append() {
# The network files need to be in /usr/lib/systemd, not ${systemd_unitdir}...
install -d ${D}${prefix}/lib/systemd/network/
install -d ${D}/etc/systemd/network/
install -m 0644 ${WORKDIR}/rndis.network ${D}${prefix}/lib/systemd/network/
install -m 0644 ${WORKDIR}/wired.network ${D}/etc/systemd/network/
}

FILES_${PN} += " \
${nonarch_base_libdir}/systemd/network \
"

Manual Network Configuration​

For testing and debugging purposes, you can use iproute2 utilities to manually set up a static IP and BusyBox's udhcpc utility to explicitly request an IP address using DHCP.

info

This configuration will not be persistent across reboots.

Make sure to disable the networking management daemons to avoid interference:

# systemctl stop connman.service
# systemctl stop systemd-networkd.socket
# systemctl stop systemd-networkd.service

Get a list of interfaces using ip link:

# ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,DYNAMIC> mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT group default qlen 1000
link/ether 00:14:2d:59:ca:81 brd ff:ff:ff:ff:ff:ff
3: sit0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN mode DEFAULT group default
link/sit 0.0.0.0 brd 0.0.0.0
4: can0: <NOARP,ECHO> mtu 16 qdisc noop state DOWN mode DEFAULT group default qlen 10
link/can

For the BSP, Ethernet interfaces are named eth<x>, which <x> represents the number of the interface, as we can see in the example above.

info

For Torizon OS the ethernet interfaces are named ethernet<x>. To read more about the Torizon standard, refer to Networking with Torizon OS

Static Network Configuration​

Enable the network interface (e.g. eth0):

# ip link set <interface> up

Assign a static IP address:

# ip addr add <IP_address>/<subnet_mask> broadcast <broadcast_address> dev <interface>

Then add your gateway IP address:

# ip route add default via <default_gateway>

For example:

# ip link set eth0 up
# ip addr add 192.168.10.2/24 broadcast 192.168.10.255 dev eth0
# ip route add default via 192.168.10.1

To undo these configurations (e.g. before switching to a dynamic IP), first remove any assigned IP address:

# ip addr flush dev <interface>

Then remove any assigned gateway:

# ip route flush dev <interface>

And finally disable the interface:

# ip link set <interface> down

Dynamic Network Configuration​

The utility udhcpc can be used to get a one time lease for an IP address from the DHCP server serving the local network:

# udhcpc -i eth0
udhcpc (v1.23.2) started
...
Sending discover...
Sending select for 192.168.10.108...
Lease of 192.168.10.108 obtained, lease time 86400
...

Ethernet/Network interfaces​

Second Ethernet ports​

For information on using the second Ethernet port some SoMs provide, check the Network on Toradex Computer on Modules article.

Ethernet Benchmark (iperf3)​

Details about Ethernet benchmarking on SoMs are described in the Network on Toradex Computer on Modules article.



Send Feedback!