Get all our network configuration with commands

Either because we are managing a server or because we do not yet have a graphical environment, there are times when we need to know all the network data that the computer to which we are connected has, here I will explain how to obtain this data.

IP adress

A simple command can tell us our IP, I mean: ifconfig

ifconfig

It will show us something like this:

ifconfig

As you can see, all network interfaces appear, in the 2nd line of each interface we see something like: «internet 192.168.1.5»… Inet is the IP address, for example, if I do a grep filtering inet I can show only the IPs:

sudo ifconfig | grep inet

It would show us our IPv4 and IPv6 IPs.

MAC

The same command allows us to know our MAC address, we can see it in the line that begins with "ether", we can still use a grep to filter by ether and that only our MACs appear:

sudo ifconfig | grep ether

DNS server

To know our DNS server we can see the content of the /etc/resolv.conf file:

cat /etc/resolv.conf

There we will see the domain of our network (in case we have one in the LAN) or the IP of the DNS server that we use.

Gateway or Gateway

Knowing our gateway is just as easy, we will use:

ip route show

We will see that several lines may appear, but the (generally) first line contains our gateway at the beginning, it is the line that begins with default

ip-route

Anyway ... obviously you can use grep again to filter by default:

ip route show | grep default

And ... getting more exquisite we can use awk to show only the 3rd column, that of the IP:

ip route show | grep default | awk {'print $3'}

But hey, this is to get us detailed 😀

Hostname or Computer Name

Simple, very simple ... just run: hostname

hostname

The end!

So far the post goes, I do not know if I have any pending configuration ... if so, share the command to show it in a terminal 😉

Enjoy!


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

      Gonzalo said

    It never hurts to remember them

      Hugo said

    In the case of DNS, this is not always the case.
    In Ubuntu or some of its derivatives the file '/etc/resolv.conf' contains 'nameserver 127.0.1.1'
    How to determine the DNS configured in these cases?

         Xurxo said

      This happens because the system is using: / usr / sbin / NetworkManager and it is this program that is in charge of calling / sbin / dhclient.

      If you want to see all the information including the IP names of the nameserver, just run the command:

      "Nm-tool"

      In Ubunto and Mint it will offer you something like this:

      Network Manager Tool

      State: connected (global)

      - Device: eth0 —————————————————————–
      Type: Wired
      Driver: jme
      State: unavailable
      Default: no
      HW Address: 00: 90: F5: C0: 32: FC

      capabilities:
      Carrier Detect: yes

      wired properties
      Carrier: off

      - Device: wlan0 [Auto MOVISTAR_JIJIJI] ——————————————
      Type: 802.11 WiFi
      Driver: rtl8192ce
      State: connected
      Default: yes
      HW Address: E0: B9: A5: B3: 08: CA

      capabilities:
      Speed: 72 Mb / s

      wireless Properties
      WEP Encryption: yes
      WPA Encryption: yes
      WPA2 Encryption:yes

      Wireless Access Points (* = current AP)
      * MOVISTAR_D44A: Infra, F8: 73: 92: 50: D4: 53, Freq 2452 MHz, Rate 54 Mb / s, Strength 40 WPA

      IPv4 Settings:
      Address: 192.168.1.37
      Prefix: 24 (255.255.255.0)
      Gateway: 192.168.1.1

      DNS: 80.58.61.250
      DNS: 80.58.61.254
      DNS: 193.22.119.22
      DNS: 208.67.222.222

      That is, all the information that the commands in this post (and some more) offer you separately at once. To know other options, you already know: «man nm-tool» 🙂

      Apart from the orders:

      "Hostname"
      "Route"

           barnarasta said

        #dig http://www.google.com | grep SERVER

        and it will tell you the DNS used

           chemabs said

        As of Ubuntu 15.04 you must use:

        nmcli device show

        because nm-tool disappeared:
        http://askubuntu.com/questions/617067/why-nm-tool-is-no-longer-available-in-ubuntu-15-04

      cohiote said

    Dear, I installed Huayra 2.0 and I have updated to 2.1.
    At least in these versions, by default there is no "ifconfig" command, otherwise I use the "ip" command to see the status of the network cards:

    ip addrsh

      jhb said

    xd men jnbkj kjbkjbk kjbkj kj kj

      JMonzon said

    How do I update a change of IP address of my mail server in the ISP DNS?