I have CentOS 7.2 (guest in VirtualBox, vagrant box centos/7
, no GUI).
I see there is a nameserver in file:
$ cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 10.0.2.3
But how to add or replace with new one?
I have done this manually directly in the network:
$ vi /etc/sysconfig/network-scripts/ifcfg-eth0
PEERDS=no
DNS1=8.8.4.4
DNS2=8.8.8.8
And it works.
But is there any way to do this through nmcli
?
P.S. No nmtui
installed (in a selected system).
Here is the command to modify an existing connection.
connectionName
can be found by command:nmcli con
. In the question case, it will be"System eth0"
If you want to ignore automatically configured nameservers and search domains, ie the settings passed from DHCP.
Finally, to enable the changes,
bring the connection down then up:Verify with
cat /etc/resolv.conf
. You should not edit/etc/resolv.conf
manually as it is generated by NetworkManager service, it is likely to get overridden at any given time.Useful nmcli manual
there is good TUI tool developed by red hat named
nmtui
that you really should try. it is pre-installed on various distros, nowadays, but if it is not on yours, try:it uses a curses based text interface - accessible from the command line.
nmcli
is only especially necessary when writing scripts, and has larger room for error due to the larger variety of possible input.In addition to setting the ipv4.dns property described above...
To exclude the DHCP provided DNS servers...set the ipv4.ignore-auto-dns property to yes.
To enable the changes, bring the connection down then up:
Verify with
cat /etc/resolv.conf
Just in case I have done a little script to do that automatically (here with google DNS) for every ethernet/wireless connections:
At the end, the wireless connections will be lost. You have to reconnect and voilà !