How to use neworkd instead of NetworkManager on ubuntu 18.04 desktop
Solution 1
I think this is as close to the "correct way" as you can get.
First you must find out what your interface name is. To do that just run ip address
from the Terminal. On my machine it is eno1
which can be found on the first line:
me@pc:~$ ip address
2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 90:b1:1c:aa:bb:cc brd ff:ff:ff:ff:ff:ff
inet 10.1.2.16/24 brd 10.1.2.255 scope global eno1
valid_lft forever preferred_lft forever
inet6 fe80::5cd1:3ee8:c461:6f12/64 scope link noprefixroute
valid_lft forever preferred_lft forever
Then you just need to edit the file /etc/netplan/01-network-manager-all.yaml
and make it look like this for a static IP address assignment:
# Let NetworkManager manage all devices on this system
network:
version: 2
renderer: NetworkManager
ethernets:
eno1:
renderer: networkd
match:
name: eno1
addresses: [10.1.2.16/24]
gateway4: 10.1.2.1
nameservers:
search: [example.com]
addresses: [10.1.2.10]
This tells netplan to use networkd on the interface eno1
instead of NetworkManager.
Solution 2
TL;DR
Edit /etc/systemd/network/*.network
FULL EXAMPLE:
For wifi to work properly below, make sure you replace wlan0
with your exact wifi name.
You can use systemd directly by adding config files to /etc/systemd/network/*.network
Edit: /etc/systemd/network/10-eth0.network
[Match]
Name=eth0
[Network]
Address=10.10.10.9/24
Gateway=10.10.10.1
DNS=9.9.9.9
Edit: /etc/systemd/network/20-wlan0.network
[Match]
Name=wlan0
SSID=Wifi-SSID
[Network]
DHCP=ipv4
I don't use netplan, so I prefer to remove it:
apt purge netplan.io
rm -rf /etc/netplan
Enable systemd-networkd:
systemctl unmask systemd-networkd
systemctl enable systemd-networkd
Set Wifi password and start at boot:
wpa_passphrase Wifi-SSID Sweet-Password >> /etc/wpa_supplicant/wpa_supplicant-wlan0.conf
systemctl enable [email protected]
Speed up boot times by refusing to wait for network at boot:
systemctl disable systemd-networkd-wait-online.service
EXPLANATION:
I can see this is old, but I've added a different method here, which doesn't use a layer of abstraction, such as netplan.io or NetworkManager, which probably more closely answers the title of this thread, if not the question.
Personally, I prefer this method because:
- Every major distro now uses systemd, but few use netplan.
- it's simple
- it's easy to troubleshoot
- can be used with very complex setups, including bridging, bonding, vlans etc
- can be used to rename devices and change MAC addresses
- can be used to set different settings based on wireless SSID and other [Match] directives
Seriously, take a look at the Arch wiki page which explains it in excellent detail with examples. Read the whole thing, because there are a few gotchas. https://wiki.archlinux.org/index.php/Systemd-networkd
Related videos on Youtube
Carlos Estrada
Updated on September 18, 2022Comments
-
Carlos Estrada over 1 year
I'm looking for the correct way of configuring the network with static IP on Ubuntu Desktop 18.04, but from the command line and not the GUI.
Thank you
-
Carlos Estrada about 4 yearsSince netplan is the default CLI way in ubuntu, I go with netplan as the right answer. But this is a very good method in general.