Networking with Torizon OS
Networking with Torizon OS can refer to different topics:
- Configuration of the host network, not directly related to containers.
- Configuration of networking on a container, and the relationship between the container and the host networks.
- Configuration of inter-container networking, often with the purpose of multi-process communication using the network stack (e.g. REST API).
The first part of this article explains about host network configuration: the Torizon OS image currently provides NetworkManager, a program that provides detection and configuration for the system to automatically connect to networks.
The second part of this article explains about container network configuration and how to share a network between containers using docker-compose.
Ethernet Interface Naming on Torizon OS
Torizon OS Ethernet interfaces are always named
ethernetX, being X a number starting from 0, for instance,
ethernet1 and so on.
This article complies with the Typographic Conventions for Torizon Documentation.
In order to take full advantage of networking with Torizon OS, see the articles:
- Configure Build Environment for Torizon Containers
- Operating Toradex Wi-Fi/BT Capable Modules Using Dual and Single Antenna Configuration (to set the antenna and use Wi-Fi properly)
Host Configuration: NetworkManager
The nmcli is a command-line client for NetworkManager. You can show the status of your network devices, detected by NetworkManager:
# nmcli device
Show our available connections and devices, on which the active connection is applied to:
# nmcli connection show
To disconnect from a network:
# nmcli con down id '<Connection_name>'
To delete a connection:
# nmcli con delete '<Connection_name>'
Static Network Configuration
If you looking for a way to configure a Static Network Configuration, nmcli provides the following commands:
# nmcli con mod '<Connection_name>' ipv4.addresses "<desired IP/mask>"
# nmcli con mod '<Connection_name>' ipv4.gateway "<desired gateway>"
# nmcli con mod '<Connection_name>' ipv4.dns "<DNS server 1>,<DNS server 2>"
# nmcli con mod '<Connection_name>' ipv4.method "manual"
After running the commands above, you can visualize your entire network configuration by opening the
# cd /etc/NetworkManager/system-connections/
# sudo cat <connection-name>.nmconnection
Expected file output:
After the changes were made, do not forget to reload the configuration file:
# sudo nmcli connection reload
Dynamic Network Configuration
Along with Static Network Configuration, ncmli provides a way to configure a dynamic connection:
# nmcli con mod '<Connection_name>' ipv4.method "auto"
Other nmcli Commands
You must read the nmcli man page, either running
man nmcli on a computer with nmcli installed or Googling after it. For quick reference,
man --help is also useful.
Torizon OS supports two Wi-Fi modes: client mode and access point (AP) mode.
Wi-Fi client mode
This mode is used when you want a Torizon OS Device to connect to a Wi-Fi access point.
To see a list of available Wi-Fi access points:
# nmcli device wifi list
To connect to a Wi-Fi access point:
# nmcli -a device wifi connect <WIFI_NAME>
Wi-Fi access point mode
This mode is used when you want a Torizon OS Device to act as a Wi-Fi access point.
Method 1: NetworkManager
The Network Manager method for upstream version presents some compatibility issues reported on NetworkManager >> Issues. Be aware that this method may not work as expected.
Run the following commands to configure Torizon OS as a Wi-Fi access point, substituting
# nmcli con add type wifi ifname uap0 mode ap con-name <WIFI_AP_NAME> ssid <WIFI_SSID>
# nmcli con modify <WIFI_AP_NAME> 802-11-wireless-security.key-mgmt wpa-psk
# nmcli con modify <WIFI_AP_NAME> 802-11-wireless-security.proto rsn
# nmcli con modify <WIFI_AP_NAME> 802-11-wireless-security.group ccmp
# nmcli con modify <WIFI_AP_NAME> 802-11-wireless-security.pairwise ccmp
# nmcli con modify <WIFI_AP_NAME> 802-11-wireless-security.psk <WIFI_PASSWORD>
# nmcli con modify <WIFI_AP_NAME> ipv4.addresses <IPV4_ADDR>
# nmcli con modify <WIFI_AP_NAME> ipv4.method manual
# nmcli con up <WIFI_AP_NAME>
Besides a Wi-Fi access point, you also need to activate a DHCP server in Torizon OS. To do that, you can leverage systemd's built-in DHCP server support, creating the file
/etc/systemd/network/80-wifi-ap.network with the following content (substitute
You can refer to Systemd manpages for more configuration possibilities and details.
Now just restart the
$ sudo systemctl restart systemd-networkd
Method 2: Hostapd
This section is based on the BSP Access Point mode
Tell NetworkManager to stop managing the uap interface. Create the file
/etc/NetworkManager/conf.d/99-disable-uap.confwith the following content:/etc/NetworkManager/conf.d/99-disable-uap.conf
Set the Access Point interface IP and SSID in Hostapd configuration file. Change the following variables in
hostapd.conffile that creates a WLan in the 5GHz range, protected with WPA2:/etc/hostapd.conf
hostapd.confis documented in the default
hostapd.conffile that is deployed, as well as here: https://w1.fi/cgit/hostap/plain/hostapd/hostapd.conf
To provide the Access Point interface with a static IP address and DHCP, it is necessary to create the file
<STATIC_DNS_ADRESS>accordingly. This also automatically sets up forwarding and the iptables masquerading rules, also including the setup of the AP sharing interface with a DHCP server. You can find more information and examples on the systemd-networkd documentation.
Enable and start hostapd:
# sudo systemctl enable hostapd
# sudo systemctl start hostapd
AP will not survive a reboot: To make it persist do the following
hostapd.serviceto execute after the desired interface (uap) is created and add these lines:hostapd.service
Description=Hostapd IEEE 802.11 AP, IEEE 802.1X/WPA/WPA2/EAP/RADIUS Authenticator
Now your access point is all set and should work as expected.
Wi-Fi hotspot mode
To configure a hotspot, first make sure to follow the steps at the section Method 2: Hostapd. Then, proceed with the next instructions. If you are using the Method 1: NetworkManager, this steps are not needed.
Once AP Mode is configured, it is a common use-case to share an internet connection from another interface (hotspot), when you want your system-on-module with Torizon OS to act as a Wi-Fi hotspot. This section relies on the Internet Sharing article from the Arch Wiki and on BSP internet sharing mode.
Enable the Packet Forwarding settings by editing the
30-ipforward.confwith the following content:/etc/sysctl.d/30-ipforward.conf
The changes will take effect after a reboot.
modprobeto load the kernel modules related to IP tables, NAT and Conntrack.
# modprobe ip_tables
# modprobe nf_nat
# modprobe nf_conntrack
iptablesto enable NAT:
# sudo iptables -t nat -A POSTROUTING -o ethernet0 -j MASQUERADE
# sudo iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
# sudo iptables -A FORWARD -i uap0 -o ethernet0 -j ACCEPT
Save the current config to
# sudo su
# mkdir /etc/iptables/
# iptables-save > /etc/iptables/iptables.rules
Create a systemd service file iptables.service. The example is modified from the iptables package from Arch Linux:/etc/systemd/iptables.service
Description=IPv4 Packet Filtering Framework
Reload systemd services and enable the new service:
$ sudo systemctl --system daemon-reload
$ sudo systemctl enable iptables
It's possible to configure a VPN tunnel in Torizon OS using WireGuard. In order to do this, please follow the instructions described in How to Use VPN on Torizon OS.
Torizon OS supports the NetworkManager's
ifupdown plugin. This plugin makes it possible to configure the network using a
/etc/network/interfaces file. For more information on how to use this plugin, please check the official NetworkManager documentation and the NetworkManager.conf manpage.
After you make the changes to the board, you can use the command
isolate from the TorizonCore Builder Tool to generate your custom Torizon OS image for the Toradex Easy Installer. To learn how to do it, please refer to the article Capturing Changes in the Configuration of a Board on Torizon OS.
Networking Inside Docker container
This section is a brief introduction on how to use different network configurations inside a Docker container. You must also refer to the Docker Networking documentation, which is a comprehensive source of information.
Show the list of networks:
# docker network ls
Inspect network to see what containers are connected to it:
# docker network inspect <NETWORK_NAME>
Bridge (containers communicate on the same Docker host)
Host (uses the host's networking directly)
Overlay (when containers running on different Docker hosts to communicate)
Macvlan (when you need your containers to look like physical hosts )
3rd-party- network plugins
When you run a new container, it automatically connects to the bridge network. A private network internal to the host is created in order to provide communication to the containers.
Create a user-defined bridge network:
# docker network create --subnet=<172.18.0.0/16> <NETWORK_NAME>
Create a container connected to our user-defined network:
# docker run --name <CONTAINER_NAME> -d --net <NETWORK_NAME> <IMAGE_NAME>
Specify the IP to a container and publish port 80 in the container to port 8080 to allow connections from other machine on the network :
# docker run --name <CONTAINER_NAME> -d --net <NETWORK_NAME> --ip <172.18.0.5> --publish <8080>:<80> <IMAGE_NAME>
Connect a running container to a network:
# docker network connect <NETWORK_NAME> <CONTAINER_NAME>
Macvlan driver can be configured in different ways. The advantage is to use the newest built-in and a lightweight driver, allowing the container to connect directly to host interfaces.
Create a macvlan network:
# docker network create -d macvlan --subnet=<172.16.86.0/24> \
--gateway=<172.16.86.1> -o parent=<ETHERNET_INTERFACE> \
Attach the container to the macvlan network:
# docker run -dit --network <NETWORK_NAME> \
--name <CONTAINER_NAME> <IMAGE_NAME> /bin/bash
Docker Networking Drivers Use Cases
To understand more about Docker networking drivers and which one is more advised to use on your application, please take a look at Understanding Docker Networking Driver Use Cases (archived).
Docker Network Using Docker-compose
When you start your application, Docker Compose sets up a bridge network by default. Each service connects to the network, which makes them reachable with each other.
You can create your own networks to provide isolation and more options:
# here you can configure your network
App2 is connected to frontend and backend network, so it can communicate with app1 and app3. App1 and app3 can't communicate with each other, because they are on separate networks.
Connect to the external network:
Docker compose looks for the pre-existing-network.
For more information about, please take a look at Docker Compose Documentation.