Using nmcli to set nameservers

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

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.