Ubuntu Networking: Difference between revisions

From embeddedTS Manuals
No edit summary
No edit summary
Tag: Reverted
Line 1: Line 1:
From almost any Linux system you can use "ip" or the ifconfig/route commands to set up the network.
The network in Ubuntu is configured netplan. For complete documentation, see [https://netplan.io/ Netplan's documentation here]
<source lang=bash>
# Bring up the CPU network interface
ifconfig eth0 up
 
# Or if you're on a baseboard with a second ethernet port, you can use that as:
ifconfig eth1 up
 
# Set an ip address (assumes 255.255.255.0 subnet mask)
ifconfig eth0 192.168.0.50
 
# Set a specific subnet
ifconfig eth0 192.168.0.50 netmask 255.255.0.0
 
# Configure your route.  This is the server that provides your internet connection.
route add default gw 192.168.0.1
 
# Edit /etc/resolv.conf for your DNS server
echo "nameserver 192.168.0.1" > /etc/resolv.conf
</source>


Most networks will offer DHCP which can be set up with one command:
Some common examples are shown below. On this release network interfaces follow the [https://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames/ predictible network interface names]. Run <source inline lang=bash>ip addr show</source> to get a list of the network interfaces.
<source lang=bash>
# To setup the default CPU ethernet port
dhclient eth0
# Or if you're on a baseboard with a second ethernet port, you can use that as:
dhclient eth1
# You can configure all ethernet ports for a dhcp response with
dhclient
</source>


To make DHCP run on startup systemd's networking will need to be configured.
Most commonly:
* end0 - Ethernet device 0 (CPU Ethernet)
* enp1s0 - Ethernet PCIe port 1 slot 0 ethernet
* usb<mac> - USB ethernet
* wlan0 - WIFI


In /etc/systemd/network/eth.network
DHCP on end0. Edit the file /etc/netplan/ethernet.yaml and add:
<source lang=ini>
<pre>
[Match]
network:
Name=eth*
  version: 2
  renderer: networkd
  ethernets:
    end0:
      dhcp4: true
      dhcp6: true
</pre>


[Network]
Static IP on end0. Edit the file /etc/netplan/ethernet.yaml and add:
DHCP=yes
<pre>
</source>
network:
  version: 2
  renderer: networkd
  ethernets:
    end0:
    dhcp4: no
    addresses: [192.168.0.50/24]
    gateway4: 192.168.0.1
    nameservers:
      addresses: [8.8.8.8,8.8.4.4]
</pre>


Then, if you intend to use DHCP to configure your DNS, start and enable the network name resolver service:
After creating the yaml file, set the appropriate permissions and apply the netplan:
<source lang=bash>
<source lang=bash>
systemctl start systemd-resolved.service
sudo chmod 600 /etc/netplan/*.yaml
systemctl enable systemd-resolved.service
sudo netplan apply
ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf
</source>
</source>
For a static configuration create a config file for that specific interface.
/etc/systemd/network/eth0.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>
For more information on networking, see Ubuntu and systemd's documentation:
* [http://www.freedesktop.org/software/systemd/man/systemd.network.html Systemd Networking Documentation]
* [https://help.ubuntu.com/lts/serverguide/network-configuration.html Ubuntu Documentation]

Revision as of 11:54, 22 September 2023

The network in Ubuntu is configured netplan. For complete documentation, see Netplan's documentation here

Some common examples are shown below. On this release network interfaces follow the predictible network interface names. Run ip addr show to get a list of the network interfaces.

Most commonly:

  • end0 - Ethernet device 0 (CPU Ethernet)
  • enp1s0 - Ethernet PCIe port 1 slot 0 ethernet
  • usb<mac> - USB ethernet
  • wlan0 - WIFI

DHCP on end0. Edit the file /etc/netplan/ethernet.yaml and add:

network:
  version: 2
  renderer: networkd
  ethernets:
    end0:
      dhcp4: true
      dhcp6: true

Static IP on end0. Edit the file /etc/netplan/ethernet.yaml and add:

network:
  version: 2
  renderer: networkd
  ethernets:
    end0:
     dhcp4: no
     addresses: [192.168.0.50/24]
     gateway4: 192.168.0.1
     nameservers:
       addresses: [8.8.8.8,8.8.4.4]

After creating the yaml file, set the appropriate permissions and apply the netplan:

sudo chmod 600 /etc/netplan/*.yaml
sudo netplan apply