Linux show dns name

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

Читайте также:  Wifi hotspot with linux

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 to Find My DNS Server IP Address in Linux

DNS (Domain Name System) is a fundamental facilitator of several networking technologies such as mail servers, Internet browsing, and streaming services e.g. Netflix and Spotify, among others.

It works on a special computer called a DNS server – which keeps a database record of several public IP addresses along with their corresponding hostnames in order for it to resolve or translate hostnames to IP addresses upon user request.

This happens so that we would not need to bother ourselves with remembering the IP addresses of the different websites we visit.

While there are several things we can discuss on DNS servers such as redirection and malware attack prevention, our focus today is on how to find out your very own dns server IP address.

There are several ways to check for it depending on the Operating System that you’re running but Linux, BSD, and Unix-like systems all share the same method so let’s begin with them.

How to Find My DNS Server IP Address

1. To find out your DNS Server IP address, use the following cat command or less command.

$ cat /etc/resolv.conf OR $ less /etc/resolv.conf

2. Another way is to use the following grep command.

$ grep "nameserver" /etc/resolv.conf nameserver 109.78.164.20

Here, nameserver 109.78.164.20 is a name server IP address in what is called the dot notation – the format that applications on your workstation use for DNS routing.

Читайте также:  Commands in linux with syntax

How to Find My Website DNS Server IP Address

3. To find out a website DNS Server IP address, you can use the following dig command.

Sample Output
; > DiG 9.8.2rc1-RedHat-9.8.2-0.68.rc1.el6_10.1 > tecmint.com ;; global options: +cmd ;; Got answer: ;; ->>HEADER

Easy right? Perhaps we’ll talk about primary and secondary DNS Server addresses next time. Till then, feel free to share and drop your comments/suggestions in the discussion section below.

Источник

Как посмотреть 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.

Источник

How to know what DNS am I using in Ubuntu from 14.04 onwards

(A follow up to similar question for 12.04.) Prior to Ubuntu 12.04, you may see the active DNS in /etc/resolv.conf . In Ubuntu 12.04, NetworkManager no longer works with the file. You have to directly consult the command line tool nm-tool . Interestingly, nm-tool is no longer installed by default in 14.04 and later. Although you may still install through apt-get install , you can't assume all Ubuntu to have that out of the box. So the question remains. How do you know, by default installation, the DNS you're using by command line?

7 Answers 7

Quick Answer

A new NetworkManager tool nmcli is installed by default now. The command line tool is very powerful but a bit harder to learn. Stick to our question, the short answer is:

or, to have cleaner output

nmcli dev show | grep DNS | sed 's/\s\s*/\t/g' | cut -f 2 

Explain

If you have time, I can explain the above jumbo-mumble:

  1. nmcli dev show Works a bit like the old nm-tool command. It elaborate the current networking info. You may also learn the setting of a certain interface by adding the interface name. For example, to learn the information of eth0 , you may use nmcli dev show eth0 .
  2. grep DNS Obviously grep only the lines with the text "DNS" in it.
  3. sed 's/\s\s*/\t/g' | cut -f 2 This is only to clean up the output. The cut may select the output by column, but it takes only 1 character as separator (while nmcli uses MANY SPACE). The sed turns the spaces, in original output, into TAB.

+1. Didn't know about this utility, however, I run Ubuntu 14.04, and my command is nmcli d list . Other than that, great stuff here!

What version is this answer based on? On my Trusty's nmcli version 0.9.8.8 nmcli dev show throws out big curly error messages.

@Oli nmcli dev show belongs to nmcli on 15.04. For some reason the old nmcli was deemed unstable , so . . . now they use nmcli that has same flags as Fedora. Probably that is due to the switch to systemd. And because this answer fits for 15.04 but not 14.04, I am strongly tempted to downvote it

I'd like to echo the above comments, this may be correct for 15.04, but is not correct for 14.04, which is the question.

Packet analysis would be an alternative method that works regardless of NetworkManager or other network connection tool that you use. Basic idea is to send a dns query with nslookup and in a second terminal check where the packets go.

For that we'd need to connect to the network for the first time, so that there is nothing cluttering the connections, and run the following command:

sudo tcpdump -vv -i wlan0 -W 1200 | grep google.com 

In alternative terminal run:

Once you get packets listing from the tcpdump , check where do they go from your IP address.

$ sudo tcpdump -vv -i wlan0 -W 1200 | grep google.com tcpdump: listening on wlan0, link-type EN10MB (Ethernet), capture size 65535 bytes eagle.29862 > b.resolvers.Level3.net.domain: [udp sum ok] 64057+ [1au] A? google.com. ar: . OPT UDPsize=4096 (39) b.resolvers.Level3.net.domain > eagle.29862: [udp sum ok] 64057 q: A? google.com. 11/0/0 google.com. A 173.194.115.64, google.com. A 173.194.115.65, google.com. A 173.194.115.72, google.com. A 173.194.115.66, google.com. A 173.194.115.69, google.com. A 173.194.115.78, google.com. A 173.194.115.70, google.com. A 173.194.115.71, google.com. A 173.194.115.68, google.com. A 173.194.115.67, google.com. A 173.194.115.73 (204) eagle.16429 > b.resolvers.Level3.net.domain: [udp sum ok] 38822+ A? google.com. (28) 

As you can see , my laptop, eagle , sends packets to my university's dns , b.resolvers.Level3.net.domain . If you want to see the IP address, you can use the -n flag with tcpdump .

$ sudo tcpdump -n -vv -i wlan0 -W 1200 | grep google.com tcpdump: listening on wlan0, link-type EN10MB (Ethernet), capture size 65535 bytes 10.10.87.145.56474 > 4.2.2.2.53: [udp sum ok] 15606+ A? google.com. (28) 

Источник

Оцените статью
Adblock
detector