18.04 - does it force netplan or can I still use resolved.conf?
Solution 1
You first have to make a decision to use NetworkManager or systemd-networkd. If you connect wi-fi to various wireless networks, then NetworkManager is probably the better choice. systemd-networkd is best used in servers, where the configuration doesn't change much. See https://netplan.io/examples.
/etc/netplan .yaml example to enable NetworkManager...
network:
version: 2
renderer: NetworkManager
In terminal
...
sudo netplan generate
# generate config files
sudo netplan apply
# apply the new config
reboot
# reboot to confirm network operation
Solution 2
Another option is systemd-networkd.service, instead of NetworkManager.service.
Background story
I was having problems with NetworkManager when after changing network settings a couple of times the DNS would fail.
I noticed that systemd-resolved.service
is supposed to work with both network-manager
and systemd-network
.
But systemd-networkd
is actually part of the systemd
family of software. So (I thought maybe) it will communicate better with systemd-networkd
than NetworkManager
. It tried it and it did seem better.
How to set up systemd-networkd
Set up /etc/systemd/network/10-enp2s0.network
where enp2s0
is the name of your interface as seen with ifconfig
. It might be eth0
. Here is a simple example of DHCP with DNS override. Note the DNS=
directive can be used multiple times.
[Match]
MACAddress=1c:dd:dd:dd:dd:dd
[Network]
DHCP=yes
DNS=208.67.222.222
DNS=208.67.220.220
The [Network]
section for a fixed address.
[Network]
Address=192.168.1.172/24
Gateway=192.168.1.1
DNS=208.67.222.222
DNS=208.67.220.220
Test it out -
systemctl stop NetworkManager.service
systemctl start systemd-networkd.service
systemctl restart systemd-resolved.service
On my system with systemd-resolved
running, the resolv.conf
file is a link -
/etc/resolv.conf -> ../run/systemd/resolve/stub-resolv.conf
If the link is not replaced automatically during the restart
, you might want to link it manually and restart systemd-resolved
again.
If its working as hoped than set their boot time startup behaviour -
systemctl disable NetworkManager.service
systemctl enable systemd-networkd.service
Blame
There are always two sides to an interface.
Related videos on Youtube
stackinator
Updated on September 18, 2022Comments
-
stackinator over 1 year
I kept getting timeout errors on 18.04 Bionic Beaver, until I switched to OpenDNS using these commands
sudo rm -f /etc/resolv.conf sudo ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf sudo nano /etc/systemd/resolved.conf # with body nameserver 208.67.222.222
Should I really be doing this OpenDNS configuration with Netplan? I tried the following but it doesn't work.
# Create a netplan file sudo vi /etc/netplan/50-cloud-init.yaml
.
# Put this in the body nameservers: addresses: [208.67.222.222, 208.67.220.220]
I also tried this syntax in the body to no avail, but maybe it because I'm on wifi and I called out 'ethernet'??? wlo1 is my wifi logical name when I
sudo lshw -C network
.network: ethernet: wlo1: nameservers: addresses: [208.67.222.222, 208.67.220.220]
-
Boris Hamanov over 5 yearsYou first have to make a decision to use NetworkManager or netplan. If you connect wi-fi to various wireless networks, then NetworkManager is probably the better choice. Netplan is best used in servers, where the configuration doesn't change much. See netplan.io/examples.
-
stackinator over 5 years@heynnema is this NetworkManager? Or is it something else? Please see this image linuxconfig.org/images/…
-
Boris Hamanov over 5 yearsThat's NetworkManager. netplan has no GUI... only files in /etc/netplan, and the netplan CLI. However, if you're using NetworkManager, there's still one relevant .yaml file in /etc/netplan.
-
stackinator over 5 years@heynnema and correct me if I'm wrong but I'll need to enable NetworkManager for 18.04 in my
/etc/netplan
file like this:network:\n [TAB]version: 2 [TAB]renderer: NetworkManager
and then I runnetplan generate && netplan apply
. -
Boris Hamanov over 5 yearsThat's correct. Indentation is important. See my answer, below, or the examples site that I quoted earlier. Use spaces, not tabs.
-
-
fkraiem about 5 yearsProbably you meant "You first have to make a decision to use NetworkManager or systemd-networkd." The configuration in your answer is using netplan, with NetworkManager as the renderer (instead of systemd-networkd).
-
Asfand Qazi about 4 yearsTHANK YOU. I used the mini ISO to install Ubuntu, and connected via WiFi during the install process. When I installed my GUI desktop I found that network manager didn't pick up my WiFi! (I use Ansible to provision my desktops to prefer to start with a blank slate, hence mini ISO). This helped me, thank you.
-
Boris Hamanov about 4 years@AsfandQazi Glad it was helpful for you.