Command-line to list DNS servers used by my system
But it doesn’t list any servers, if I go to «Network Manager GUI Tool», in Wireless section it lists «DNS 192.168.1.1 8.8.8.8 8.8.4.4» Can I get same information from command line? I am using Ubuntu 12.04 LTS
What are you trying to find? the DNS servers being used by your system? or are you trying to do a DNS lookup?
13 Answers 13
resolv.conf isn’t really used anymore, unless you implement it yourself. The network manager does it now. I created an alias to list the DNS servers on my system, as I sometimes switch from OpenDNS to Google’s open DNS.
nmcli device show | grep IP4.DNS
nmcli dev list iface | grep IP4
In my case, is eth0 , which is common, but not always the case. You can see your interfaces with
See if this is what you want.
I think resolv.conf is actually used indirectly, because the network manager creates the server that listens on 127.0.0.1, but I was told that this is an implementation detail that should not be counted on. I think that if you enter DNS addresses before this entry, they might get used, but I’m not sure exactly how this works. I think it’s best to use the network manager in most cases, when possible.
thanks, yes that seems to be working, ubuntu networking seems to be confusing, so I can set dns servers in resolve.conf/base or in /etc/network/interfaces or in network manager, is there a definitive guide for ubuntu networking?
@vcardillo: the original question stated: «I am using Ubuntu 12.04 LTS». It’s been 5 years since I posted my answer. Nothing lasts forever.
I would like to warn readers that the information provided by nmcli and nm-tool might not be correct. In testing my router setup, I changed the DHCP server to configure a DNS. On my client (linux mint 17.3) I did sudo dhclient -r; sudo dhclient to renew IP configuration. At this point both commands I mentioned showed the old DNS, not the new one. cat /etc/resolv.conf did work for me, but according to op it did not work for him. The only reliable way to figure out which DNS is used appears to be to a lookup with for example dig, but I doubt dig will show you all configured DNS.
In Ubuntu 18.04 and 20.04 you can use systemd-resolve —status . In newer versions use resolvectl status .
IMO this should be the accepted answer. Also, it’s worth pointing out that systemd-resolve mydomain.com outputs which DNS server exactly is being queried (very useful if e.g. you have set up a VPN and so on).
This is valid for Ubuntu 13.10 and earlier. For Ubuntu 14.04 and above, see Koala Yeung’s answer to: How to know what DNS am I using in Ubuntu from 14.04 onwards
You will get an output similar to
NetworkManager Tool State: connected (global) - Device: eth0 [Wired connection 1] ------------------------------------------- Type: Wired Driver: e1000e State: connected Default: yes HW Address: 00:11:22:33:44:55 Capabilities: Carrier Detect: yes Speed: 1000 Mb/s Wired Properties Carrier: on IPv4 Settings: Address: 10.21.6.13 Prefix: 24 (255.255.255.0) Gateway: 10.21.6.1 DNS: 10.22.5.133 DNS: 10.22.5.3
Or to see just the DNS do
yeah this doesn’t work anymore. no nm-tool in 16.x either. nmcli (in Marty Fried’s answer) is the way to go
The two top-scoring answers, nmcli dev list iface | grep IP4 and nm-tool both assume that network-manager is in control. Which it is — on desktop machines most of the time at least. But the fuller answer is that sometimes network-manager is not in control. E.g. vpnc messes with /etc/resolv.conf directly.
So: First check if 127.0.0.1/localhost is used. This could be done with dig :
> dig something.unknown | grep SERVER: ;; SERVER: 127.0.0.1#53(127.0.0.1)
Now you know that we are using localhost. Go ahead with one of the popular answers. I like:
> nm-tool | grep DNS: DNS: 8.8.8.8
But if 127.0.0.1/localhost is not used, then nm-tool ‘s and nmcli ‘s output will be misleading:
> dig something.unknown | grep SERVER: ;; SERVER: 172.22.216.251#53(172.22.216.251) > nm-tool | grep DNS: DNS: 8.8.8.8
Here, dig is correct and nm-tool ‘s information is misleading. In reality addresses local to the environment I’ve VPN-ed into are resolved correctly. All of which Google’s DNS 8.8.8.8 doesn’t know about.
This is because after connecting to a VPN with vpnc , it puts a line in /etc/resolv.conf so it looks like:
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8) # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN nameserver 1.2.3.4 nameserver 127.0.0.1 search MyDomain
How do I list DNS server order in systemd-resolve?
I know that systemd-resolve —status lists all my connections and their DNS servers and nmcli connection show
2 Answers 2
It is stupid, but you can’t!
systemd-resolved follows internal rules to choose the «correct» DNS. This might be different for each query. It uses things like if a server worked or failed in the past, interface order and even what domains allocated to each interface. It’s difficult to manage with some VPN setups.
The best you can do is to cat /run/systemd/resolve/resolv.conf to see the resolv.conf file generated by systemd-resolved .
I also gave up and install dnsmasq with rules to resolve some domains in certain servers (ie: internal DNS to the internal network dns server). This solved my problems using several VPNs and dns resolve order
Why o why am I not surprised that linux developers, who after 20 years still can’t make a properly functional desktop that isn’t littered with bugs and inconsistencies, can’t make a properly functional command line interface also. It’s so depressing. Open Sores indeed.
@ChristopherThomas notice that all OS have weak and strong points, having used both windows and macosX, i can tell you that they both have lot of stupid «features» in the DNS. I understand that systemd was developed for the clueless user and it tries to guess things. but still, not all users are clueless and having only that operating node is stupid.The problem is that there is no «one size fits all» and that is why all OS have major issues with managing DNS. That being said, while not perfect, IMHO, linux is still a much better OS and desktop than the other two, and it’s free and open
systemd’s command line interface is absolute garbage. It lacks many features that would be useful for people building interfaces to automate and control a linux system through user interfaces, etc. But it just doesn’t have them. They only implemented the basic functionalities and missed a lot of what actual system administrators need. We don’t want to parse weird and wacky command line outputs using sed or grep for some value. I expect to be able to query the value and get it directly. It’s absolute garbage. Even knowledgable administrators suffer to get useful information out of it.
and by the way, mac does not have problems managing DNS and has had a consistent command line interface for years already and it’s stable and reliable. So your claim that all OS have this issue is false. Windows also has a stable way to interact with it’s networking system through the command line. Linux is the only one out of those three with problems.
Как посмотреть DNS в Linux
Служба DNS или Domain Name System позволяет превращать легко читаемый адрес сайта в ip адрес сервера на котором расположен этот сайт. Для этого используются DNS серверы, которые содержат таблицы соответствия ip адресов их доменным именам. По умолчанию система получает адрес DNS сервера автоматически по DHCP при подключении к сети.
В этой статье мы разберемся как посмотреть какие DNS серверы используются в Linux.
Как посмотреть DNS в Linux
Если вы уже имели опыт настройки сети в Linux, то знаете, что DNS серверы, используемые для резолвинга доменных имен указаны в файле /etc/resolv.conf:
Но в современных дистрибутивах Linux с системой инициализации systemd обычно запущен локальный DNS сервер, адрес которого и прописан в этом файле, а какие сервера используются на самом деле непонятно. В таком случае можно воспользоваться утилитой systemd-resolve:
В самом низу вывода утилиты можно посмотреть DNS в Linux, которые сейчас используются. Информация выводится по каждому сетевому интерфейсу отдельно.
Также для решения подобной задачи можно использовать утилиту nmcli:
Как видите, все очень просто. А чтобы изменить DNS сервер тоже трогать /etc/resolv.conf не желательно, так как он будет автоматически обновляться после перезагрузки. Если вы используете NetworkManager, то можно настроить DNS для сетевого подключения в интерфейсе программы. Или же можно отредактировать файл /etc/systemd/resolved.conf и добавить нужные адреса в секцию Resolve:
sudo vi /etc/systemd/resolved.conf
Как видите, все очень просто. Надеюсь, эта информация была вам полезной.
Обнаружили ошибку в тексте? Сообщите мне об этом. Выделите текст с ошибкой и нажмите Ctrl+Enter.
Linux DNS Server List
Domain Name System (DNS) is a critical component of the internet infrastructure that resolves human-readable domain names into machine-readable IP addresses. A DNS server is responsible for translating domain names to IP addresses and vice versa. In this article, we will explore the different DNS servers available for Linux operating systems.
BIND (Berkeley Internet Name Domain) is the most widely used DNS server on the internet. It is an open-source software that is used to translate domain names into IP addresses. BIND is available for various Linux distributions such as Ubuntu, CentOS, and Debian. To install BIND on Ubuntu, use the following command:
NSD (Name Server Daemon) is a lightweight and high-performance DNS server that is ideal for serving authoritative DNS zones. It is designed to be secure, scalable, and reliable. NSD is available for various Linux distributions such as Ubuntu, CentOS, and Debian. To install NSD on Ubuntu, use the following command:
Unbound is a validating, recursive, and caching DNS server that is designed to be fast and secure. It is an open-source software that is available for various Linux distributions such as Ubuntu, CentOS, and Debian. Unbound is easy to configure and provides advanced features such as DNSSEC validation and DNS-over-TLS. To install Unbound on Ubuntu, use the following command:
PowerDNS is a modern, advanced, and high-performance DNS server that supports various backends such as MySQL, PostgreSQL, and BIND. It is an open-source software that is available for various Linux distributions such as Ubuntu, CentOS, and Debian. PowerDNS provides advanced features such as DNSSEC validation, DNS-over-TLS, and load balancing. To install PowerDNS on Ubuntu, use the following command:
MaraDNS is a small and lightweight DNS server that is designed to be secure and easy to configure. It is an open-source software that is available for various Linux distributions such as Ubuntu, CentOS, and Debian. MaraDNS provides basic features such as DNS caching and forwarding. To install MaraDNS on Ubuntu, use the following command:
So, there are various DNS servers available for Linux operating systems, each with its unique features and capabilities. The choice of DNS server depends on the specific requirements of your organization. By understanding the differences between these DNS servers, you can make an informed decision and choose the right DNS server for your needs.
Related Searches and Questions asked:
That’s it for this post. Keep practicing and have fun. Leave your comments if any.