
In this article, we will guide you through the process of making Netplan write to the resolve.conf
file for DNS configuration. This is particularly useful when you want to manage your DNS settings without relying on external services like NetworkManager or systemd-resolved.
Yes, it is possible to make Netplan write to the resolve.conf
file for DNS configuration. By editing the Netplan configuration file and adding the nameservers
option under the appropriate section, you can specify the DNS server address. After applying the changes and verifying the resolv.conf
file, Netplan will be responsible for managing your DNS settings.
What is Netplan?
Netplan is a utility for easily configuring networking on a Linux system. It reads network configuration described in YAML format and applies it to the system.
What is resolve.conf?
The resolve.conf
file is a configuration file for DNS resolvers on Unix-like operating systems. It’s typically located at /etc/resolv.conf
.
Configuring Netplan to Write to resolve.conf
Step 1: Edit Netplan Configuration File
The first step is to edit your Netplan configuration file. This file is usually located at /etc/netplan/02-networkd.yaml
. Open the file using a text editor. For example, you can use nano:
sudo nano /etc/netplan/02-networkd.yaml
In the configuration file, you’ll need to add the nameservers
option under the eth0
section. Here’s an example:
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: yes
nameservers:
addresses: [10.0.0.1]
In this example, 10.0.0.1
is the DNS server address. Replace it with your DNS server address.
Step 2: Apply the Changes
After editing the configuration file, you need to apply the changes. You can do this by running the following command:
sudo netplan apply
This command will apply the changes you made to the Netplan configuration file.
Step 3: Verify the Changes
The final step is to verify that the /etc/resolv.conf
file has been updated with the DNS information. You can check the contents of the file by running the following command:
cat /etc/resolv.conf
This command will display the contents of the resolv.conf
file. You should see the DNS server address you specified in the Netplan configuration file.
Conclusion
By following these steps, you can make Netplan write to the resolve.conf
file for DNS configuration. This allows you to manage your DNS settings directly through Netplan, without relying on external services. Remember to replace the example DNS server address with your actual DNS server address.
Netplan is a utility for easily configuring networking on a Linux system. It reads network configuration described in YAML format and applies it to the system.
The resolve.conf
file is typically located at /etc/resolv.conf
on Unix-like operating systems.
You can edit the Netplan configuration file by opening it with a text editor, such as nano. For example, you can use the command sudo nano /etc/netplan/02-networkd.yaml
to open the file.
To specify DNS server addresses in the Netplan configuration file, you need to add the nameservers
option under the appropriate network interface section. For example:
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: yes
nameservers:
addresses: [10.0.0.1]
Replace 10.0.0.1
with your DNS server address.
After editing the Netplan configuration file, you can apply the changes by running the command sudo netplan apply
.
To verify the changes, you can check the contents of the resolve.conf
file by running the command cat /etc/resolv.conf
. The DNS server address specified in the Netplan configuration file should be displayed.