List all DNS Servers, including those pushed by VPN

102

If you're using NetworkManager you can use the command line tool that's part of it, nmcli to get this list:

$ nmcli dev list iface wlan0 | grep IP4
IP4-SETTINGS.ADDRESS:           192.168.1.110
IP4-SETTINGS.PREFIX:            24 (255.255.255.0)
IP4-SETTINGS.GATEWAY:           192.168.1.1
IP4-DNS1.DNS:                   192.168.1.8
IP4-DNS2.DNS:                   192.168.1.5
IP4-DNS3.DNS:                   24.92.226.11

You have to change the bit, wlan0 to whatever is your network interface. You can make it a bit more dynamic by using the iwgetid command:

$ nmcli dev list iface $(iwgetid | awk '{print $1}') | grep IP4

You can also use nm-tool to get a full report:

$ nm-tool 
...
  IPv4 Settings:
    Address:         192.168.1.110
    Prefix:          24 (255.255.255.0)
    Gateway:         192.168.1.1

    DNS:             192.168.1.8
    DNS:             192.168.1.5
    DNS:             24.92.226.11
Share:
102

Related videos on Youtube

Fad Eyi
Author by

Fad Eyi

Updated on September 18, 2022

Comments

  • Fad Eyi
    Fad Eyi over 1 year

    ***how can you implement the constructor without naming or needing the class such as EX:

    string x = new string()

    how can i just implement

    new string() by itself without the need for string x.

    I known it's calling the constructor but doesn't the class has to be initialized?

    Ex:

    1. new InvalidOperationException(".....")
    2. throw new ArgumentException("...");
    • Tomislav Markovski
      Tomislav Markovski over 12 years
      What exactly is the question?
    • mellamokb
      mellamokb over 12 years
      What do you mean by initialized? Somewhere internally in the .NET framework there are class definitions for InvalidOperationException and ArgumentException, and they have constructors with code that runs when the class is instantiated. What's the problem/question?
    • Mitch Wheat
      Mitch Wheat over 12 years
      @Fad Eyi: suggest you add more explanation, otherwise your question might be closed.
  • Fad Eyi
    Fad Eyi over 12 years
    My question is i have seen both examples in my initial question been used without instantiation. So how is that possible?
  • Andrew Barber
    Andrew Barber over 12 years
    They are initialized by the code you posted. new InvalidOperationException() calls the constructor for InvalidOperationException, which is responsible for initialization.
  • Fad Eyi
    Fad Eyi over 12 years
    But what variable are they stored in, the original code does have the "var excep" sessions it just goes straight into instantiation of the constructor. "new InvalidOperationException();". Maybe my question is not understood correctly. The code doesn't assign a variable to the constructor so how can it run?
  • Andrew Barber
    Andrew Barber over 12 years
    The first code sample is worthless for just the reason you suggest; it's not being assigned to anything. I said so in my answer. But it is still creating and initializing the object - you just can't do anything with it. The second code is "throwing" the exception object; code up the stack somewhere will catch that exception and will get it there.
  • Fad Eyi
    Fad Eyi over 12 years
    Thanks, i think that answered my question. So what you saying it's possible to create object without assigning variable it just means you can't do anything with it but how is throw one different "The second code is "throwing" the exception object; code up the stack somewhere will catch that exception and will get it there" maybe i don't understand how "throw" works i though it would have the same effect as the first code.
  • Andrew Barber
    Andrew Barber over 12 years
    I'd recommend looking up "Exception handling" in .NET for more on what throw does.
  • Fad Eyi
    Fad Eyi over 12 years
    i Know what "throw" does in general i'm wondering how "catch" is incorporated?
  • Piotr Dobrogost
    Piotr Dobrogost about 10 years
    And what if I do not use NetworkManager?
  • slm
    slm about 10 years
    @PiotrDobrogost - ask your Q on the main site. This Q specifically dealt with NetworkManager. Notice it was tagged as such by the OP?
  • lreeder
    lreeder over 7 years
    When I try to use nmcli on the tunneling interface "tun0" setup by my vpn, I get "Error: Device 'tun0' not found."
  • Tyler
    Tyler over 4 years
    That did work. I used nmcli d show enp2s0 | grep IP4