How do I find my network information - in Linux?
Taking a cue from Martin's helpful article (see "How do I find my IP Address") I thought it would be a good idea to offer the same information for the Linux operating system. But with Linux there is one issue to get around - that of the number of different tools available to use to find this information. Because there are so many graphical tools with which to find networking information, I thought it would be best to simply tackle this with everyone's favorite tool - the command line.
In this article I will show you how to find out various networking information on your Linux system. All of these tasks can be handled by any skill level of user, so don't think you have to be an ubergeek, hacker-type in order to gain this information.
Let's start off with the IP Address. Of course, before you do anything, you need to open up a terminal window. Once you have that open you can then issue the necessary command. The command for finding your IP Address is ifconfig. When you issue this command you will receive information for every network connection you have available. Most likely you will see information for both the loopback (lo) and your wired network connection (eth0). If you have a wireless connection that will be listed, most likely, as wlan0. The reported information will look like that shown in Figure 1. As you can see, you not only get the IP Address, but the Broadcast address, the Subnet Mask, and the IPv6 Address.
From that same command line, if you enter the command hostname you will see the actual hostname of your machine. In the case of my test machine, I see Ubuntu-desktop. Â For more information on using this command, take a look at my article "Set your hostname in Linux".
There is no actual command to see your DNS addresses. You don't really need one. All you need to do is examine the /etc/resolv.conf file with the command less /etc/resolv.conf, at whichpoint you will see something like:
Now let's find out what the Gateway address is. The command used for this is the netstat command. This command does quite a bit more than just discover your gateway. What the netstat command does is print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships. But to find the gateway address you would issue the command netstat -nr and you will see something like that shown in Figure 2. You can probably guess it, but the Gateway address is 192.168.1.1. The flags you used in that command are n (for numeric addresses) and r (for route).
Of course the netstat command can do much more than that (we'll cover that in another article).
Yes, there are a lot of tools that can be used in Linux. It all depends upon how you want to get your information. In both the GNOME and KDE desktops there are outstanding GUI tools you can use for all of this. But knowing the command line route makes you much more versatile.Advertisement
In Ubuntu and other distros, simply right clicking on your network icon on top panel and clicking on connection information reveals all these info with ease and no command required.
A couple of things
1) Don’t apologise for showing people how to use the command line, especially for stuff like this. Each distribution and desktop has its own ‘standard tools’ for use from the windowing environment, whereas the command line is the command line on all of them
2) Another useful network tool / file is the hosts file – It can be used to over ride the DNS commands, so if someone has got into your machine they can make ghacks.net point to 126.96.36.199 (which is cracked.com). The only thing that should be there is a line for 127.0.0.1 and perhaps your router address. You can check the contents by using:
which gives you something similar to (apologies for formatting)
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a ‘#’ symbol.
# For example:
# 188.8.131.52 rhino.acme.com # source server
# 184.108.40.206 x.acme.com # x client host
Just a small note: be aware that ifconfig (and the other tools from the net-tools package) are deprecated and might not be there anymore in future linux releases (depending on the distro).
It won’t happen overnight, but if you are still learning, might be best to learn the new commands of the new iproute2 package from the start:
Thank’s man. I never hear about iproute2 before
route -n for finding the gateway address.
Should have prefaced the full path on the commands. Most can be run as simple user without root access, but /sbin is not in their path.
Good post anyway :) I can always use a reminder.