Difference between revisions of "How to configure ethernet interface"

[unchecked revision] [quality revision]
(Merge articles)
(Merge articles)
 

1 Purpose[edit]

This article describes how to configure the Ethernet interface.
This article provides two ways to make it:

  • via ifconfig: to put quickly and temporary the Ethernet interface with static IP address.
  • via systemd: to change durably the Ethernet configuration with static IP address

2 Using Ifconfig tools[edit]

  • Connect an Ethernet cable and enjoy

At startup SSH daemon (sshd) and ifplugd daemon are automatically launched:

  • sshd (useful to perform ssh, scp)
  • ifplugd detect:
    • udhcpc is launched on cable detection to retrieve an IP address,

If a DHCP server is not available, one can set the Ethernet IP adress with :

 
 ifconfig eth0 uuu.xxx.yyy.zzz
Warning white.png Warning
If there is some service such as systemd-networkd, NetworkManager, Connman , the configuration of Ethernet interface can change when the service see the change

To check if eth0 and the gateway are well configured, one can type:
 
ifconfig
 route
In the console, a log similar to the one below should be displayed:
 
 ifconfig
 eth0      Link encap:Ethernet  HWaddr 00:80:E1:01:39:61  
           inet addr:10.48.1.172  Bcast:10.48.3.255  Mask:255.255.252.0
           UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
           RX packets:18 errors:0 dropped:0 overruns:0 frame:0
           TX packets:2 errors:0 dropped:0 overruns:0 carrier:0
           collisions:0 txqueuelen:1000 
           RX bytes:3038 (2.9 KiB)  TX bytes:684 (684.0 B)
           Interrupt:103 
 STM32MP1 # route
 Kernel IP routing table
 Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
 default         lme-gw-vl802.lm 0.0.0.0         UG    10     0        0 eth0
 10.48.0.0       *               255.255.252.0   U     0      0        0 eth0

3 Using systemd-networkd service[edit]

Systemd-networkd is a network service provided by systemd.

3.1 Ethernet interface[edit]

Systemd-networkd provides a directory on which the Ethernet interface must be configured via configuration file: /lib/systemd/network.

 
 ls /lib/systemd/network
50-wired.network            52-static.network.static    80-container-vz.network
50-wired.network.static     80-container-host0.network  99-default.link 
51-wireless.network.sample  80-container-ve.network

ST provide some configurations file:

  • 50-wired.network: basic DHCP configuration for each ethX ethernet interface
  • 50-wired.network.static: example of basic DHCP configuration on which eth0 are exclude of list
  • 52-static.network.static: example of static IP configuration for eth0

3.2 Configuration file[edit]

Example of configuration:
DHCP configuration;

[Match]
Name=eth*

[Network]
DHCP=ipv4

Static IP configuration:

[Match]
Name=eth0

[Network]
DNS=192.168.72.254
Address=192.168.72.2/24
Gateway=192.168.72.254

[Match]

  • MACAddress= a whitespace-separated list of hardware addresses
  • Name= a white-space separated list of device names or expression (e.g. eth*).
  • Host= the machine hostname

[NETWORK]
[Network]

  • DHCP= enables the DHCP client, value can be: yes, no, ipv4, ipv6
  • DHCPServer= enables the DHCP server for this configuration
  • DNS= list DNS addresses in case of static configuration (you may specify several addresses)
  • IPForward= configures IP packet forwarding, value can be: ipv4 or ipv6
  • IPMasquerade= configures IP masquerading for the network interface. If enabled, packets forwarded from the network interface will be appear as coming from the local host. Takes a boolean argument. Implies IPForward=ipv4. Defaults to "no". Value can be yes or no.

All parameters are described on official documentation of systemd-networkd: [1]

3.3 DHCP configuration[edit]

DHCP configuration;

[Match]
Name=eth*

[Network]
DHCP=ipv4

All Ethernet interface are configured with DHCP client address.

3.4 STATIC configuration[edit]

Static configuration;
Add a new file 52-static.network with the following content
(/lib/systemd/network/50-wired.network or /lib/systemd/network/52-static.network)

[Match]
Name=eth0

[Network]
DNS=192.168.72.254
Address=192.168.72.2/24
Gateway=192.168.72.254

Eth0 Ethernet interface are configured with static IP address.


Info white.png Information
In case of static configuration or specific configuration, please take care to not configure two time your Ethernet interface
, with the static configuration example you need to exclude eth0 interface of default configuration (here 50-wired.network)

Exclude eth0 from default Ethernet configuration:
Change the file 50-wired.network (or 80-wired.network) with the following content
(/lib/systemd/network/50-wired.network or /lib/systemd/network/80-wired.network)

[Match]
Name=eth[1-9]

[Network]
DHCP=ipv4

3.5 DHCP Server configuration[edit]

DHCP server example:

[Match]
Name=eth0

[Network]
Address=192.168.72.1/24
DHCPServer=yes
IPForward=ipv4
IPMasquerade=yes


4 References[edit]


<noinclude>

{{ClonedFrom | stm32mpu}}</noinclude>
== Purpose ==
This article describes how to configure the Ethernet interface. <br/>

This article provides two ways to make it:
* via ifconfig: to put quickly and temporary the Ethernet interface with static IP address.
* via systemd: to change durably the Ethernet configuration with static IP address 

== Using [[Ifconfig]] tools=={{ReviewsComments|-- [[User:Bernard Puel|Bernard Puel]] ([[User talk:Bernard Puel|talk]]) 14:21, 9 April 2020 (CEST)<br /> "ifconfig" is obsolete and shall be replaced with "ip" command<br/>

[[User:Christophe Priouzeau|Christophe Priouzeau]]  16:53, 9 April 2020 (CEST)<br />

Ifconfig would be always available with busybox, but a section with '''ip''' must be added
}}
* <big>'''''Connect an Ethernet cable and enjoy'''''</big>

At startup SSH daemon (sshd) and ifplugd daemon are automatically launched:
* sshd (useful to perform ssh, scp)
* ifplugd detect:
** udhcpc is launched on cable detection to retrieve an IP address, 

If a DHCP server is not available, one can set the Ethernet IP adress with :
  {{Board$}} ifconfig eth0 uuu.xxx.yyy.zzz

{{Warning|If there is some service such as  ''systemd-networkd'', ''NetworkManager'', ''Connman'' , the configuration of Ethernet interface can change when the service see the change}}<br />


::To check if eth0 and the gateway are well configured, one can type:
  {{Board$}}ifconfig
  {{Board$}}route
::In the console, a log similar to the one below should be displayed:
  {{Board$}} ifconfig
  eth0      Link encap:Ethernet  HWaddr 00:80:E1:01:39:61  
            inet addr:10.48.1.172  Bcast:10.48.3.255  Mask:255.255.252.0
            UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
            RX packets:18 errors:0 dropped:0 overruns:0 frame:0
            TX packets:2 errors:0 dropped:0 overruns:0 carrier:0
            collisions:0 txqueuelen:1000 
            RX bytes:3038 (2.9 KiB)  TX bytes:684 (684.0 B)
            Interrupt:103 
  STM32MP1 # route
  Kernel IP routing table
  Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
  default         lme-gw-vl802.lm 0.0.0.0         UG    10     0        0 eth0
  10.48.0.0       *               255.255.252.0   U     0      0        0 eth0

== Using systemd-networkd service ==
''Systemd-networkd'' is a network service provided by systemd. <br/>


=== Ethernet interface ===
''Systemd-networkd'' provides a directory on which the Ethernet interface must be configured via configuration file: /lib/systemd/network. {{ReviewsComments|-- [[User:Bernard Puel|Bernard Puel]] ([[User talk:Bernard Puel|talk]]) 14:45, 9 April 2020 (CEST)<br />How do you know which configuration is used and what is the meaning of the numbers names: "50-", "51-", ...<br/>

[[User:Christophe Priouzeau|Christophe Priouzeau]]  16:53, 9 April 2020 (CEST)<br />

There is no spefic way to which config are used, you can see if the interface are managed by networkctl and for ip and route via ifconfig/route/ip
}}  {{Board$}} ls /lib/systemd/network
 50-wired.network            52-static.network.static    80-container-vz.network
 50-wired.network.static     80-container-host0.network  99-default.link 
 51-wireless.network.sample  80-container-ve.network

ST provide some configurations file:
* 50-wired.network: basic DHCP configuration for each '''ethX''' ethernet interface
* 50-wired.network.static: example of basic DHCP configuration on which eth0 are exclude of list
* 52-static.network.static: example of static IP configuration for eth0

=== Configuration file ===
Example of configuration:<br>

DHCP configuration;<pre>

[Match]
Name=eth*

[Network]
DHCP=ipv4</pre>

Static IP configuration:<pre>

[Match]
Name=eth0

[Network]
DNS=192.168.72.254
Address=192.168.72.2/24
Gateway=192.168.72.254</pre>


'''[Match]''' <br/>

* '''MACAddress=''' a whitespace-separated list of hardware addresses
* '''Name=''' a white-space separated list of device names or expression (e.g. eth*).
* '''Host=''' the machine hostname

'''[NETWORK]'''<br/>

[Network]
* '''DHCP=''' enables the DHCP client, value can be: yes, no, ipv4, ipv6
* '''DHCPServer=''' enables the DHCP server for this configuration
* '''DNS=''' list DNS addresses in case of static configuration (you may specify several addresses)
* '''IPForward=''' configures IP packet forwarding, value can be: ipv4 or ipv6
* '''IPMasquerade=''' configures IP masquerading for the network interface. If enabled, packets forwarded from the network interface will be appear as coming from the local host. Takes a boolean argument. Implies IPForward=ipv4. Defaults to "no". Value can be yes or no.

All parameters are described on official documentation of systemd-networkd: <ref>https://www.freedesktop.org/software/systemd/man/systemd.network.html</ref>

=== DHCP configuration ===
DHCP configuration;<pre>

[Match]
Name=eth*

[Network]
DHCP=ipv4</pre>

All Ethernet interface are configured with DHCP client address.

=== STATIC configuration ==={{ReviewsComments|ECO:
Please give pratical  guideline to recconfigure default config. Indeed the content of 52-static.network .
# to enable static IP on eth0:                                                  
# $> cp 50-wired.network 50-wired.network.notused                               
# $> cp 50-wired.network.static 50-wired.network                                
# $> cp 52-static.network.static 52-static.network                              
# $> systemctl restart systemd-networkd.service  <br/>

CPR: DONE
     }} 
Static configuration;<br/>

Add a new file 52-static.network with the following content<br/>

(/lib/systemd/network/50-wired.network or /lib/systemd/network/52-static.network)<pre>

[Match]
Name=eth0

[Network]
DNS=192.168.72.254
Address=192.168.72.2/24
Gateway=192.168.72.254</pre>

Eth0 Ethernet interface are configured with static IP address.

{{Info|In case of static configuration or specific configuration, please take care to not configure two time your Ethernet interface<br/>, with the static configuration example you need to exclude eth0 interface of default configuration (here 50-wired.network) }}<br />


Exclude eth0 from default Ethernet configuration:<br/>

Change the file 50-wired.network (or 80-wired.network) with the following content<br/>

(/lib/systemd/network/50-wired.network or /lib/systemd/network/80-wired.network)<pre>

[Match]
Name=eth[1-9]

[Network]
DHCP=ipv4</pre>
{{ReviewsComments|ECO:Show here the way to change the default config to static that is insided 52-static.network there is the command to update the config<br/>

CPR: there is no command to update network config and save it, only a manual method}}

=== DHCP Server configuration ===
DHCP server example:<pre>

[Match]
Name=eth0

[Network]
Address=192.168.72.1/24
DHCPServer=yes
IPForward=ipv4
IPMasquerade=yes
</pre>


==References==
<references />

<noinclude>

[[Category:Ethernet]]
{{PublicationRequestId | 10180 | 2019-01-07 | BrunoB }}</noinclude>
Line 1: Line 1:
<noinclude>
 
{{ClonedFrom | stm32mpu}}
 
</noinclude>
 
 
== Purpose ==
 
== Purpose ==
 
This article describes how to configure the Ethernet interface. <br/>
 
This article describes how to configure the Ethernet interface. <br/>
Line 9: Line 6:
   
 
== Using [[Ifconfig]] tools==
 
== Using [[Ifconfig]] tools==
{{ReviewsComments|-- [[User:Bernard Puel|Bernard Puel]] ([[User talk:Bernard Puel|talk]]) 14:21, 9 April 2020 (CEST)<br /> "ifconfig" is obsolete and shall be replaced with "ip" command
 
<br/>
 
[[User:Christophe Priouzeau|Christophe Priouzeau]]  16:53, 9 April 2020 (CEST)<br />
 
Ifconfig would be always available with busybox, but a section with '''ip''' must be added
 
}}
 
 
 
* <big>'''''Connect an Ethernet cable and enjoy'''''</big>
 
* <big>'''''Connect an Ethernet cable and enjoy'''''</big>
 
At startup SSH daemon (sshd) and ifplugd daemon are automatically launched:
 
At startup SSH daemon (sshd) and ifplugd daemon are automatically launched:
Line 50: Line 41:
 
=== Ethernet interface ===
 
=== Ethernet interface ===
 
''Systemd-networkd'' provides a directory on which the Ethernet interface must be configured via configuration file: /lib/systemd/network.  
 
''Systemd-networkd'' provides a directory on which the Ethernet interface must be configured via configuration file: /lib/systemd/network.  
{{ReviewsComments|-- [[User:Bernard Puel|Bernard Puel]] ([[User talk:Bernard Puel|talk]]) 14:45, 9 April 2020 (CEST)<br />How do you know which configuration is used and what is the meaning of the numbers names: "50-", "51-", ...
 
<br/>
 
[[User:Christophe Priouzeau|Christophe Priouzeau]]  16:53, 9 April 2020 (CEST)<br />
 
There is no spefic way to which config are used, you can see if the interface are managed by networkctl and for ip and route via ifconfig/route/ip
 
}}
 
 
   {{Board$}} ls /lib/systemd/network
 
   {{Board$}} ls /lib/systemd/network
 
  50-wired.network            52-static.network.static    80-container-vz.network
 
  50-wired.network            52-static.network.static    80-container-vz.network
Line 112: Line 98:
   
 
=== STATIC configuration ===
 
=== STATIC configuration ===
{{ReviewsComments|ECO:
 
Please give pratical  guideline to recconfigure default config. Indeed the content of 52-static.network .
 
# to enable static IP on eth0:                                                 
 
# $> cp 50-wired.network 50-wired.network.notused                             
 
# $> cp 50-wired.network.static 50-wired.network                               
 
# $> cp 52-static.network.static 52-static.network                             
 
# $> systemctl restart systemd-networkd.service 
 
<br/>
 
CPR: DONE
 
    }}
 
 
 
Static configuration;<br/>
 
Static configuration;<br/>
 
Add a new file 52-static.network with the following content<br/>
 
Add a new file 52-static.network with the following content<br/>
Line 150: Line 125:
 
DHCP=ipv4
 
DHCP=ipv4
 
</pre>
 
</pre>
{{ReviewsComments|ECO:Show here the way to change the default config to static that is insided 52-static.network there is the command to update the config
 
<br/>
 
CPR: there is no command to update network config and save it, only a manual method}}
 
   
 
=== DHCP Server configuration ===
 
=== DHCP Server configuration ===