Difference between revisions of "How to configure the network interfaces"

From DAVE Developer's Wiki
Jump to: navigation, search
(apply network configuration at runtime with systemd)
 
(11 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{InfoBoxTop}}
+
== How to configure the network interfaces ==
{{AppliesToAxel}}
 
{{AppliesToAxelLite}}
 
{{AppliesToAxelEsatta}}
 
{{Applies To Bora}}
 
{{Applies To BoraX}}
 
{{Applies To BoraLite}}
 
{{Applies To Diva}}
 
{{InfoBoxBottom}}
 
 
 
 
 
== Introduction ==
 
  
 
For deploying an Embedded System, one of the most important configuration is the ''Network Interface configuration''.  
 
For deploying an Embedded System, one of the most important configuration is the ''Network Interface configuration''.  
Line 25: Line 14:
 
* [https://www.freedesktop.org/software/systemd/man/systemd.network.html systemd network configuration]
 
* [https://www.freedesktop.org/software/systemd/man/systemd.network.html systemd network configuration]
  
== Examples==
+
=== Examples===
  
 
The following configuration assumptions are used in the paragraphs shown below:
 
The following configuration assumptions are used in the paragraphs shown below:
Line 33: Line 22:
 
* IP address of the device '''192.168.1.100'''
 
* IP address of the device '''192.168.1.100'''
  
== SysV ==
+
=== systemd ===
  
The configuration files for SysV can be found in pre-defined directorys as written [https://en.wikibooks.org/wiki/Linux_Networking/Where_should_I_put_the_configuration_commands%3F here]
+
The network configuration for systemd are basically found in the <code>/etc/systemd/network/</code> directory.
  
Basically, for network configuration, it should be enough to properly configure the <code>/etc/network/interfaces</code> file.
+
The most simply way for configuring the network interface is to create/edit the file '''/etc/systemd/network/20-eth0.network''' as per the following paragraphs. In the event that there are another network interface, then this must be create/edit as '''/etc/systemd/network/20-eth1.network'''.
 +
For more example and usage hints on systemd, please refer to our [[XELK-AN-008:_How_to_use_systemd_on_an_Embedded_system#Configuring_the_network_interfaces | wiki]] page.
  
# /etc/network/interfaces -- configuration file for ifup(8), ifdown(8)
+
==== Static IP address ====
 
+
SBC ORCA has two network interfaces, below is shown how to configure them both through a static IP. In the case of SBCX MINI there is only one ethernet interface, consequently going to configure only eth0 interface.
Here below an example of configuration file:
 
 
 
=== Static IP address ===
 
The network interface is configured with a static IP address by creating the configuration entry in the '''/etc/network/interfaces''' file as the following:
 
  
 +
Example for ethernet interface 0.
 
<pre>
 
<pre>
auto eth0
+
[Match]
iface eth0 inet static
+
Name=eth0
address 192.168.1.100
 
netmask 255.255.255.0
 
gateway 192.168.1.254
 
</pre>
 
  
=== Dynamic IP addres (DHCP) ===
+
# Prevent the interface loading if the kernel boots from nfs
 +
KernelCommandLine=!nfsroot
  
The network interface is configured - using a proper DHCP server on the network - by creating the configuration entry in the '''/etc/network/interfaces''' file as the following:
+
[Network]
 
+
Address=192.168.1.100
<pre>
+
Gateway=192.168.1.254
allow-hotplug eth0
+
DNS=192.168.1.1
iface eth0 inet dhcp
 
 
</pre>
 
</pre>
  
When the Linux kernel detects the physical interface eth0, the iface causes ''ifup'' to use DHCP to configure the interface.
+
Example for ethernet interface 1.
 
 
=== DNS ===
 
 
 
If the <code>resolvconf</code> package is not installed, the DNS configuration can be done manually by editing the '''/etc/resolv.conf''' as the following:
 
 
 
 
<pre>
 
<pre>
nameserver 192.168.1.1
+
[Match]
</pre>
+
Name=eth1
  
For example, it can be done on the command line echoing the string in this way:
+
# Prevent the interface loading if the kernel boots from nfs
 +
KernelCommandLine=!nfsroot
  
root@axel-lite:~# echo "nameserver 192.168.1.1" > /etc/resolv.conf
+
[Network]
 
+
Address=192.168.1.101
=== loopback network interface ===
+
Gateway=192.168.1.254
 
+
DNS=192.168.1.1
The following configuration entry in the '''/etc/network/interfaces''' file brings up the loopback network interface lo upon booting the system.
 
<pre>
 
# The loopback interface
 
auto lo
 
iface lo inet loopback
 
 
</pre>
 
</pre>
  
This one always exists in the ''/etc/network/interfaces'' file.
+
Once modified, the <code>networkd</code> service should be resarted:
  
== systemd ==
+
systemctl restart systemd-networkd
  
The network configuration for systemd are basically found in the <code>/etc/systemd/network/</code> directory.
+
==== Dynamic IP addres (DHCP) ====
  
The most simply way for configuring the network interface is to create/edit the file '''/etc/systemd/network/eth0.network''' as per the following paragraphs.
+
SBC ORCA has two network interfaces, below is shown how to configure them both through DHCP. In the case of SBCX MINI there is only one ethernet interface, consequently going to configure only eth0 interface.
  
For more example and usage hints on systemd, please refer to our [[XELK-AN-008:_How_to_use_systemd_on_an_Embedded_system#Configuring_the_network_interfaces | wiki]] page.
+
The network interface is configured - using a proper DHCP server on the network - by using the '''DHCP''' key in the configuration file as the following:
 
 
=== Static IP address ===
 
  
 
<pre>
 
<pre>
Line 106: Line 78:
  
 
[Network]
 
[Network]
Address=192.168.1.100
+
DHCP=yes
Gateway=192.168.1.254
 
DNS=192.168.1.1
 
 
</pre>
 
</pre>
  
=== Dynamic IP addres (DHCP) ===
+
In the event that there are another network interface, the configuration file as the following:
 
 
The network interface is configured - using a proper DHCP server on the network - by using the '''DHCP''' key in the configuration file as the following:
 
  
 
<pre>
 
<pre>
 
[Match]
 
[Match]
Name=eth0
+
Name=eth1
  
 
# Prevent the interface loading if the kernel boots from nfs
 
# Prevent the interface loading if the kernel boots from nfs
Line 128: Line 96:
 
When systemd network starts, it tries to use a DHCP server present in the network to configure the interface.
 
When systemd network starts, it tries to use a DHCP server present in the network to configure the interface.
  
=== DNS ===
+
==== DNS ====
  
 
The DNS key (in the configuration file)  is used only if the '''systemd-resolved service''' is enabled and the ''/etc/resolv.conf'' has a symbolic link to ''/run/systemd/resolve/stub-resolv.conf''
 
The DNS key (in the configuration file)  is used only if the '''systemd-resolved service''' is enabled and the ''/etc/resolv.conf'' has a symbolic link to ''/run/systemd/resolve/stub-resolv.conf''
Line 134: Line 102:
 
  ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf
 
  ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf
  
=== loopback network interface ===
+
Once modified, the <code>resolved</code> service should be resarted:
 +
 
 +
systemctl restart systemd-resolved
 +
 
 +
==== loopback network interface ====
 
systemd contains native implementations of various tasks that need to be executed as part of the boot process.  
 
systemd contains native implementations of various tasks that need to be executed as part of the boot process.  
  
 
For example, it sets the hostname or configures the loopback network device.
 
For example, it sets the hostname or configures the loopback network device.
  
=== Apply configuration changes ===
+
==== Apply configuration changes ====
 
After editing the above files, changes are applied after reboot or by restarting <code>systemd-networkd.service</code>:<syntaxhighlight lang="bash">
 
After editing the above files, changes are applied after reboot or by restarting <code>systemd-networkd.service</code>:<syntaxhighlight lang="bash">
root@imx6qdlxelk:~# systemctl restart systemd-networkd.service
+
root@desk-mx8mp:~# systemctl restart systemd-networkd.service
 
</syntaxhighlight>
 
</syntaxhighlight>

Latest revision as of 09:51, 15 February 2023

How to configure the network interfaces[edit | edit source]

For deploying an Embedded System, one of the most important configuration is the Network Interface configuration.

Once the Embedded Device is finally configured for stand-alone bootstrap, the network interface should be configured for reaching the device remotely via network connections like ssh, telnet, ftp, http, etc.

This Application Note briefly describes how it is possible to simply configure the network interfaces on SystemV (aka SysV) or systemd

Resources[edit | edit source]

For further details on network configuration, please refer - for example - to:

Examples[edit | edit source]

The following configuration assumptions are used in the paragraphs shown below:

  • IP address range of the LAN network 192.168.1.0 - 192.168.1.255
  • IP address of the gateway 192.168.1.254
  • IP address of the device 192.168.1.100

systemd[edit | edit source]

The network configuration for systemd are basically found in the /etc/systemd/network/ directory.

The most simply way for configuring the network interface is to create/edit the file /etc/systemd/network/20-eth0.network as per the following paragraphs. In the event that there are another network interface, then this must be create/edit as /etc/systemd/network/20-eth1.network. For more example and usage hints on systemd, please refer to our wiki page.

Static IP address[edit | edit source]

SBC ORCA has two network interfaces, below is shown how to configure them both through a static IP. In the case of SBCX MINI there is only one ethernet interface, consequently going to configure only eth0 interface.

Example for ethernet interface 0.

[Match]
Name=eth0

# Prevent the interface loading if the kernel boots from nfs
KernelCommandLine=!nfsroot

[Network]
Address=192.168.1.100
Gateway=192.168.1.254
DNS=192.168.1.1

Example for ethernet interface 1.

[Match]
Name=eth1

# Prevent the interface loading if the kernel boots from nfs
KernelCommandLine=!nfsroot

[Network]
Address=192.168.1.101
Gateway=192.168.1.254
DNS=192.168.1.1

Once modified, the networkd service should be resarted:

systemctl restart systemd-networkd

Dynamic IP addres (DHCP)[edit | edit source]

SBC ORCA has two network interfaces, below is shown how to configure them both through DHCP. In the case of SBCX MINI there is only one ethernet interface, consequently going to configure only eth0 interface.

The network interface is configured - using a proper DHCP server on the network - by using the DHCP key in the configuration file as the following:

[Match]
Name=eth0

# Prevent the interface loading if the kernel boots from nfs
KernelCommandLine=!nfsroot

[Network]
DHCP=yes

In the event that there are another network interface, the configuration file as the following:

[Match]
Name=eth1

# Prevent the interface loading if the kernel boots from nfs
KernelCommandLine=!nfsroot

[Network]
DHCP=yes

When systemd network starts, it tries to use a DHCP server present in the network to configure the interface.

DNS[edit | edit source]

The DNS key (in the configuration file) is used only if the systemd-resolved service is enabled and the /etc/resolv.conf has a symbolic link to /run/systemd/resolve/stub-resolv.conf

ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf

Once modified, the resolved service should be resarted:

systemctl restart systemd-resolved

loopback network interface[edit | edit source]

systemd contains native implementations of various tasks that need to be executed as part of the boot process.

For example, it sets the hostname or configures the loopback network device.

Apply configuration changes[edit | edit source]

After editing the above files, changes are applied after reboot or by restarting systemd-networkd.service:

root@desk-mx8mp:~# systemctl restart systemd-networkd.service