linux – How to display the ip of all DNS servers?

Question:

How can I find the IP addresses of all DNS servers in use?

Through the terminal and through the shell file

Answer:

the operating system uses the dns servers listed in the /etc/resolv.conf file as format strings:

nameserver ip-адрес

you can view the entire contents of this file, for example, with the command:

$ cat /etc/resolv.conf

you can display only lines starting with nameserver (usually there are no more than three of them), you can, for example, like this:

$ grep ^nameserver /etc/resolv.conf

you can display only ip-addresses from such lines, for example, like this:

$ sed -n 's/^nameserver\s\+//p' /etc/resolv.conf
Scroll to Top