Using a customer nameserver often requires disabling the DHCP based resolv.conf modifications. Here is what I got to work.
I needed to modify the connection associated with the Ethernet device. In my case, this was called “System eth0”. The two values I needed to change were: ipv4.ignore-auto-dns (from no to yes) and the ipv4.dns value, setting the desired DNS servers.
Here were the commands.
nmcli conn modify "System eth0" ipv4.ignore-auto-dns yes nmcli conn modify "System eth0" ipv4.dns "192.168.24.7 8.8.8.8" systemctl restart NetworkManager |
Below that are the commands I used to check the pre-and-post states.
[root@idm ~] nmcli conn show "System eth0" | grep dns: connection.mdns: -1 (default) ipv4.dns: 128.31.27.57,8.8.8.8 ipv4.ignore-auto-dns: no ipv6.dns: -- ipv6.ignore-auto-dns: no [root@idm ~] nmcli conn modify "System eth0" ipv4.ignore-auto-dns yes [root@idm ~] nmcli conn modify "System eth0" ipv4.dns "192.168.24.7 8.8.8.8" [root@idm ~] nmcli conn show "System eth0" | grep dns: connection.mdns: -1 (default) ipv4.dns: 192.168.24.7,8.8.8.8 ipv4.ignore-auto-dns: yes ipv6.dns: -- ipv6.ignore-auto-dns: no [root@idm ~]# systemctl restart NetworkManager [root@idm ~]# cat /etc/resolv.conf # Generated by NetworkManager search demo.redhatfsi.com nameserver 192.168.24.7 nameserver 8.8.8.8 |
Thank you very much! There is a lot of old outdated incorrect information out there.
Don’t treat this as official docs…it is just what I got working when I did it. Much of what I have written over the years has been superceded, and I do not always realize it and update. But glad to help.
I guess Thomas was referring to other posts, not yours.
Anyway, did you figured out how to prepend a `nameserver` entry while keeping dhcp provided servers?
I’ve tried this but w/o success:
“`
$ cat /etc/resolv.conf
# Generated by NetworkManager
search us-east-2.compute.internal
nameserver 10.0.0.2
$ sudo nmcli connection modify “$UUID” \
+ipv4.dns 10.233.0.3 \
ipv4.dns-priority 1
$ sudo systemctl restart NetworkManager
$ cat /etc/resolv.conf
# Generated by NetworkManager
search us-east-2.compute.internal
nameserver 10.0.0.2
nameserver 10.233.0.3
“`
I’d like to have 10.233.0.3 before 10.0.0.2.
I have not tried that.
The only way to change dns servers is to use nmtui and modify the entries.
nmcli does not remove the old entries, instead it only adds to the existing ones.
This has been a bug and as of today on a el8 machine i am able to replicate it.
This works for me:
nmcli connection modify ens192 ipv4.dns “192.178.1.1 192.178.1.2”
nmcli con mod ens19 ipv4.ignore-auto-dns yes