Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ubuntu 18.04 Server - how to check DNS IP server setting being used

Working with Ubuntu 18.04 Server LTS. I am trying to find a way to check the DNS IP(s) that is actually being used when set via DHCP. The resolv.conf only will point to 127.0.0.53 now. /etc/systemd/network folder is empty. The NSLOOKUP output also always references the internal 127.0.0.53 IP. Seems all the old tricks aren't working.

The Ubuntu documentation is not updated yet as it still looks like the help for 16.04 referencing eth0, ifup and ifdown which are all deprecated on 18: https://help.ubuntu.com/lts/serverguide/network-configuration.html

I've tried setting a static adapter setup with Netplan via a custom .yaml. The settings work fine but I can't seem to find the DNS IP that I set anywhere. I expect it will be consistent between DHCP and static settings but I'm not sure where to look now.

I would settle for either a C library call or a bash CLI method at this point. Does anyone have a way to check this on 18.04 Server?

like image 338
Nathan Smith Avatar asked May 11 '18 19:05

Nathan Smith


People also ask

How do you check which DNS server is being used in Linux?

To determine what DNS servers are being used, you simply need to view the contents of the “/etc/resolv. conf” file. This can be done via a graphical editing tool such as gedit, or can easily be viewed from the command line with a simple “cat” of the file, to show the contents.

How do you check if an IP is a DNS server?

The easiest way to find out your dns server IP address is to go through the router's admin interface status page. All routers have a built-in web-based setup page that allows the user to customize settings and set view properties such as IP address and dns settings.


2 Answers

I found the following showed my the DNS servers by adapter towards the end of the output:

systemd-resolve --status 

It contains a list under 'DNS Servers' organized by Link. I think this has changed from previous versions with Ubuntu. It will take a little text parsing work but this gives me what I'm after.

like image 172
Nathan Smith Avatar answered Oct 02 '22 21:10

Nathan Smith


Another way is:

cat /run/systemd/resolve/resolv.conf 

That file is dynamically generated by systemd-resolved, but contains the actual DNS servers instead of 127.0.0.53.

In fact, if you want make that the default for /etc/resolv.conf, you simply create symlink for it. (/etc/resolv.conf is a symlink that points to /run/systemd/resolve/stub-resolv.conf by default):

sudo mv /etc/resolv.conf /etc/resolv.conf.orig sudo ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf 

Sample /run/systemd/resolve/resolv.conf :

# This file is managed by man:systemd-resolved(8). Do not edit. # # This is a dynamic resolv.conf file for connecting local clients directly to # all known uplink DNS servers. This file lists all configured search domains. # # Third party programs must not access this file directly, but only through the # symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a different way, # replace this symlink by a static file or a different symlink. # # See man:systemd-resolved.service(8) for details about the supported modes of # operation for /etc/resolv.conf.  nameserver 10.1.2.3 search host.domain.com 

For more info:

http://manpages.ubuntu.com/manpages/bionic/man8/systemd-resolved.service.8.html

like image 37
wisbucky Avatar answered Oct 02 '22 21:10

wisbucky