TS-4900 Network configuration example: Difference between revisions

From embeddedTS Manuals
No edit summary
(Update for Zeus networking)
 
(5 intermediate revisions by one other user not shown)
Line 1: Line 1:
Most commonly networks will offer DHCP which can be set up with one command:
Our Yocto image uses systemd which stores its network files in <source lang=bash inline>/etc/systemd/network/</source>. Yocto will automatically enable DHCP on its wired interfaces. This can be overridden to set a static IP or enable other options for DHCP. The only requirement is that this file is named <source lang=bash inline>/etc/systemd/network/XX-wired.network</source> Where "XX" is a number smaller than 80, e.g. <source lang=bash inline>/etc/systemd/network/79-wired.network</source>  This format must be used for all <source lang=bash inline>eth*</source> and <source lang=bash inline>en*</source> named network interfaces. The lower file names will take priority.
 
An example of a static configuration would be:
 
/etc/systemd/network/42-wired.network
<source lang=ini>
[Match]
Name=eth0
 
[Network]
Address=192.168.0.50/24
Gateway=192.168.0.1
DNS=192.168.0.1
</source>
 
DNS will be loaded from /etc/resolv.conf.  To make this use a static DNS:
<source lang=bash>
<source lang=bash>
# To setup the network for this boot:
rm /etc/resolv.conf
udhcpc -i eth0
echo "nameserver 8.8.8.8" > /etc/resolv.conf
# Or if you're on a baseboard with a second ethernet port, you can use that as:
echo "nameserver 8.8.4.4" >> /etc/resolv.conf
udhcpc -i eth1
</source>


# To instead manually configure the interface for this boot:
To use the DNS assigned by DHCP, run:
killall udhcpc
<source lang=bash>
# Set IP + subnet mask
ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf
ifconfig eth0 192.168.0.50 netmask 255.255.255.0
# Set default gateway, usually your router
route add default gw 192.168.0.1
# Set your DNS server
echo "nameserver 8.8.8.8" > /etc/resolv.conf
</source>
</source>


To make your network settings take effect on startup in Yocto, edit /etc/network/interfaces: 
For more information on what options are available to configure the network, see the [http://www.freedesktop.org/software/systemd/man/systemd.network.html systemd network documentation].
  # We always want the loopback interface.                        
  #                                                               
  auto lo                                                         
  iface lo inet loopback                                           
                                                                   
  auto eth0                                                       
  iface eth0 inet static                                           
    address 192.168.0.50                                           
    netmask 255.255.255.0                                         
    gateway 192.168.0.1                                           
  auto eth1                                                       
  iface eth1 inet dhcp

Latest revision as of 17:55, 20 March 2020

Our Yocto image uses systemd which stores its network files in /etc/systemd/network/. Yocto will automatically enable DHCP on its wired interfaces. This can be overridden to set a static IP or enable other options for DHCP. The only requirement is that this file is named /etc/systemd/network/XX-wired.network Where "XX" is a number smaller than 80, e.g. /etc/systemd/network/79-wired.network This format must be used for all eth* and en* named network interfaces. The lower file names will take priority.

An example of a static configuration would be:

/etc/systemd/network/42-wired.network

[Match]
Name=eth0

[Network]
Address=192.168.0.50/24
Gateway=192.168.0.1
DNS=192.168.0.1

DNS will be loaded from /etc/resolv.conf. To make this use a static DNS:

rm /etc/resolv.conf
echo "nameserver 8.8.8.8" > /etc/resolv.conf
echo "nameserver 8.8.4.4" >> /etc/resolv.conf

To use the DNS assigned by DHCP, run:

ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf

For more information on what options are available to configure the network, see the systemd network documentation.