Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
625 views
in Technique[技术] by (71.8m points)

linux - Remove DNS from device using `nmcli`

I want to remove the DNS currently associated to the device and add a new one using nmcli

So, if I do nmcli device show eth0 I can see

IP4.DNS[1]:                             10.0.2.2

If I do sudo nmcli device modify eth0 ipv4.dns "8.8.8.8" then I can see

IP4.DNS[1]:                             10.0.2.2
IP4.DNS[2]:                             8.8.8.8

but I want to remove the first one. How can I do it? If i try sudo nmcli device modify eth0 ipv4.dns "" then the second one (8.8.8.8) is removed but the first one is still there.

My final goal is to set ONLY 8.8.8.8 (for example...)

EDIT:

I am a bit confused between connection and device.

For example, let's say that I had 10.0.2,2 and I had 8.8.8.8 using one of these two commands:

nmcli connection modify netplan-eth0 ipv4.dns 8.8.8.8

nmcli device modify eth0 ipv4.dns 8.8.8.8

Because it seems there is a device and then there is a connection bound to it, so I can modify the dns using one of these two commands.

Now, I can see:

Using nmcli device show I have in the result

IP4.DNS[1]:                             10.0.2.2
IP4.DNS[2]:                             8.8.8.8

but using nmcli connection show netplan-eth0 I can see only

ipv4.dns:                               8.8.8.8

So, my problem now is that I can easily modify the only dns in the connection, that is 8.8.8.8 using one of the followin command:

nmcli connection modify netplan-eth0 -ipv4.dns 8.8.8.8

nmcli device modify eth0 -ipv4.dns 8.8.8.8

BUT, I don't know how to remove the 10.0.2.2 that is showing only in the device but not in the connection.

BTW I did not set manually 10.0.2.2, I suppose it was taken through dhcp. And for some motivation this dns is bound only to the device but not to the connection.

With these details the problem should be more clear :)

question from:https://stackoverflow.com/questions/65922054/remove-dns-from-device-using-nmcli

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

For the general way to modify the dns, look at the answer of missconfigured.

About the problem of the dns get through netplan or dhcp, I could remove them using the following command:

nmcli device modify eth0 ipv4.ignore-auto-dns yes

After that, I was able to remove the 10.0.2.2 dns.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...