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

From DAVE Developer's Wiki
Jump to: navigation, search
(17 intermediate revisions by 2 users not shown)
Line 9: Line 9:
 
{{InfoBoxBottom}}
 
{{InfoBoxBottom}}
  
 +
<section begin=Body/>
  
== Introduction ==
+
== How to configure the network interfaces ==
  
One of the most used configuration is the ''Network Interface configuration''.  
+
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 has to be automatically configured for reaching the device remotely via network connections like ssh, telnet, ftp, htpp, etc.
+
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 [https://en.wikipedia.org/wiki/UNIX_System_V SystemV] (aka ''SysV'') or [https://www.freedesktop.org/wiki/Software/systemd/ systemd]
 
This Application Note briefly describes how it is possible to simply configure the network interfaces on [https://en.wikipedia.org/wiki/UNIX_System_V SystemV] (aka ''SysV'') or [https://www.freedesktop.org/wiki/Software/systemd/ systemd]
  
== Resources ==
+
=== Resources ===
  
 
For further details on network configuration, please refer - for example - to:
 
For further details on network configuration, please refer - for example - to:
Line 25: Line 26:
 
* [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 31: Line 32:
 
* IP address range of the LAN network '''192.168.1.0 - 192.168.1.255'''
 
* 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 gateway '''192.168.1.254'''
* IP address of the PC '''192.168.1.100'''
+
* IP address of the device '''192.168.1.100'''
  
== SysV ==
+
=== SysV ===
  
 
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 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]
  
 
Basically, for network configuration, it should be enough to properly configure the <code>/etc/network/interfaces</code> file.
 
Basically, for network configuration, it should be enough to properly configure the <code>/etc/network/interfaces</code> file.
 +
 +
# /etc/network/interfaces -- configuration file for ifup(8), ifdown(8)
  
 
Here below an example of configuration file:
 
Here below an example of configuration file:
  
=== Static IP address ===
+
==== 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:
 
The network interface is configured with a static IP address by creating the configuration entry in the '''/etc/network/interfaces''' file as the following:
  
 
<pre>
 
<pre>
 +
auto eth0
 
iface eth0 inet static
 
iface eth0 inet static
 
  address 192.168.1.100
 
  address 192.168.1.100
Line 51: Line 55:
 
</pre>
 
</pre>
  
=== Dynamic IP addres (DHCP) ===
+
==== Dynamic IP addres (DHCP) ====
  
 
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:
 
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:
Line 62: Line 66:
 
When the Linux kernel detects the physical interface eth0, the iface causes ''ifup'' to use DHCP to configure the interface.
 
When the Linux kernel detects the physical interface eth0, the iface causes ''ifup'' to use DHCP to configure the interface.
  
=== DNS ===
+
==== 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:
 
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:
Line 74: Line 78:
 
  root@axel-lite:~# echo "nameserver 192.168.1.1" > /etc/resolv.conf
 
  root@axel-lite:~# echo "nameserver 192.168.1.1" > /etc/resolv.conf
  
=== loopback network interface ===
+
==== loopback network interface ====
  
 
The following configuration entry in the '''/etc/network/interfaces''' file brings up the loopback network interface lo upon booting the system.
 
The following configuration entry in the '''/etc/network/interfaces''' file brings up the loopback network interface lo upon booting the system.
 
<pre>
 
<pre>
 +
# The loopback interface
 
auto lo
 
auto lo
 
iface lo inet loopback
 
iface lo inet loopback
Line 84: Line 89:
 
This one always exists in the ''/etc/network/interfaces'' file.
 
This one always exists in the ''/etc/network/interfaces'' file.
  
== systemd ==
+
=== systemd ===
  
 
The network configuration for systemd are basically found in the <code>/etc/systemd/network/</code> directory.
 
The network configuration for systemd are basically found in the <code>/etc/systemd/network/</code> directory.
Line 92: Line 97:
 
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.
 
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.
  
=== Static IP address ===
+
==== Static IP address ====
  
 
<pre>
 
<pre>
Line 107: Line 112:
 
</pre>
 
</pre>
  
=== Dynamic IP addres (DHCP) ===
+
==== Dynamic IP addres (DHCP) ====
  
 
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:
 
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:
Line 124: Line 129:
 
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 '''ystemd-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''
  
 
  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 ====
 +
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 ====
 +
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
 +
</syntaxhighlight>

Revision as of 16:09, 14 July 2021

Info Box
Axel-04.png Applies to Axel Ultra
Axel-lite 02.png Applies to Axel Lite
Axel-02.png Applies to AXEL ESATTA
Bora5-small.jpg Applies to Bora
BORA Xpress.png Applies to BORA Xpress
BORALite-TOP.png Applies to BORA Lite
Diva-am335x-overview.png Applies to Diva


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

SysV[edit | edit source]

The configuration files for SysV can be found in pre-defined directorys as written here

Basically, for network configuration, it should be enough to properly configure the /etc/network/interfaces file.

# /etc/network/interfaces -- configuration file for ifup(8), ifdown(8)

Here below an example of configuration file:

Static IP address[edit | edit source]

The network interface is configured with a static IP address by creating the configuration entry in the /etc/network/interfaces file as the following:

auto eth0
iface eth0 inet static
 address 192.168.1.100
 netmask 255.255.255.0
 gateway 192.168.1.254

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

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:

allow-hotplug eth0
iface eth0 inet dhcp

When the Linux kernel detects the physical interface eth0, the iface causes ifup to use DHCP to configure the interface.

DNS[edit | edit source]

If the resolvconf package is not installed, the DNS configuration can be done manually by editing the /etc/resolv.conf as the following:

nameserver 192.168.1.1

For example, it can be done on the command line echoing the string in this way:

root@axel-lite:~# echo "nameserver 192.168.1.1" > /etc/resolv.conf

loopback network interface[edit | edit source]

The following configuration entry in the /etc/network/interfaces file brings up the loopback network interface lo upon booting the system.

# The loopback interface
auto lo
iface lo inet loopback

This one always exists in the /etc/network/interfaces file.

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/eth0.network as per the following paragraphs.

For more example and usage hints on systemd, please refer to our wiki page.

Static IP address[edit | edit source]

[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

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

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

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

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@imx6qdlxelk:~# systemctl restart systemd-networkd.service