How do I to set the DNS server for a device using nmcli?

11,853

To add custom dns servers use

nmcli connection modify Wired_connection_1 ipv4.dns "192.168.1.1,8.8.8.8,8.8.4.4" 

to check if the config is ok use

nmcli connection show Wired_connection_1 | grep "dns"

ipv4.dns:                               192.168.1.1,8.8.8.8,8.8.4.4
ipv4.dns-search:                        --
ipv4.dns-options:                       (default)
ipv4.dns-priority:                      0
ipv4.ignore-auto-dns:                   no
ipv6.dns:                               --
ipv6.dns-search:                        --
ipv6.dns-options:                       (default)
ipv6.dns-priority:                      0
ipv6.ignore-auto-dns:                   no

I stumbled upon same issue if I remove the 192.168.1.1 then due to some internal vmware networking bridging it wasn't working, but to set the additional dns server, you can use the above method.

Share:
11,853

Related videos on Youtube

Alexey Ce
Author by

Alexey Ce

Updated on September 18, 2022

Comments

  • Alexey Ce
    Alexey Ce over 1 year

    How do I set the DNS server to be 8.8.8.8 and 8.8.4.4 through the CLI with nmcli?

    $ nmcli device show eno1
    GENERAL.DEVICE:                         eno1
    GENERAL.TYPE:                           ethernet
    GENERAL.HWADDR:                         C8:9C:DC:28:86:CA
    GENERAL.MTU:                            1500
    GENERAL.STATE:                          100 (connected)
    GENERAL.CONNECTION:                     Wired connection 1
    GENERAL.CON-PATH:                       /org/freedesktop/NetworkManager/ActiveConnection/1
    WIRED-PROPERTIES.CARRIER:               on
    IP4.ADDRESS[1]:                         192.168.1.6/24
    IP4.GATEWAY:                            192.168.1.1
    IP4.ROUTE[1]:                           dst = 169.254.0.0/16, nh = 0.0.0.0, mt = 1000
    IP4.DNS[1]:                             192.168.1.1
    IP6.ADDRESS[1]:                         fe80::49c7:61b4:886f:27e9/64
    IP6.GATEWAY:                            --
    

    The Wired Connection 1, configured with the GUI, is using those DNS settings:

    $ nmcli con show
    NAME                UUID                                  TYPE             DEVICE  
    Wired connection 1  f5687342-d1bd-3e5e-83a1-a1e2ec627d3c  802-3-ethernet   eno1    
    docker0             84b0d93b-f4f7-4b52-a6cb-800d161f0954  bridge           docker0 
    virbr0              024c6c7a-12f4-49ad-92b3-434106caad25  bridge           virbr0  
    vici                c19aafd8-fa10-4577-a748-dee4cb684675  802-11-wireless  --      
    

    in detail:

    $ nmcli con show Wired_connection_1 | grep ipv4.dns
    ipv4.dns:                               8.8.8.8,8.8.4.4
    ipv4.dns-search:                        --
    ipv4.dns-options:                       (default)
    ipv4.dns-priority:                      0
    

    but I'd like to apply that configuration using nmcli to eno1.

    Somewhat tangentially, there looks to be a problem with DNS configuration for Ubuntu, perhaps a bug. (I'm effected by this bug, insofar as it shows in resolve.conf)

    perhaps:

    sudo nmcli dev set enp8s0 managed yes
    

    or similar...

  • Alexey Ce
    Alexey Ce about 6 years
    I can't quite recall what I was doing, and won't be able to check the answer for some time. But sounds right.