Jack Wallen takes a break from his usual rants and raves to offer up some new-to-Linux-user help. This time around it's all about finding networking information on your Linux box. Learn how to find your IP address, hostname, DNS addresses, and gateway address here.
I have been asked, by numerous readers, to intersperse my regular rants and raves with some beginner technical posts. So from this point on you will find the occasional article targeted for new users -- this one being one of them.
You're new to Linux. You've installed a distribution that seems to be working out just perfectly for you. But you've come up against a small hitch - you need to know your networking information. For whatever reason you need to know your IP Address, your hostname, your DNS addresses, and your gateway address. How do you find this information? You could go to your desktop environments' networking GUI tool, but that would depend upon the distribution and the desktop. So let's take a more universal approach to this task - the command line.
Although many newbies fear the command line, the tasks you will see below are a very simple way of getting to know both the command line AND your networking configuration.
The first bit of information we want to find out is the IP address of our machine. If you've used Windows enough, you know the command ipconfig will give you this bit of information (and more). For Linux, the command is ifconfig. If you issue the command without arguments you will see listed all addresses associated with all networking interfaces. A typical entry will look like:
eth0 Link encap:Ethernet HWaddr 00:30:1b:81:d3:f7
inet addr:192.168.1.108 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::230:1bff:fe81:d3f7/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1610700 errors:0 dropped:0 overruns:0 frame:0
TX packets:1185599 errors:5 dropped:0 overruns:0 carrier:0
RX bytes:1790159713 (1.7 GB) TX bytes:160110456 (160.1 MB)Interrupt:32 Base address:0x2000
As you can see, the address you are looking for is the inet addr and, in this case, would be 192.168.1.108.
The next piece of information is the hostname. If you notice in your terminal window (the window you are running your commands in) you will see that your bash prompt looks like:
You can see a portion of the hostname there (in this case, "ubuntu"). To get the full hostname you would issue the command hostname. On my machine it's ubuntu.wallen.local.
To find your current DNS addresses, issue the command less /etc/resolv.conf which will reveal something like:
# Generated by NetworkManager
nameserver 220.127.116.11nameserver 18.104.22.168
Now we come to the gateway address. The command used to find your gateway, netstat, is a very powerful command that can print network connections, routing tables, interface statistics, NAT connections, and multicast memberships. For the purposes of this article we are going to issue the command using the n and r switches like so:
Which will output something like you see in Figure A. As you can see there are basically three addresses listed but only one address has an associated gateway. That solo gateway address listed in the gateway address for your machine.
Wrap it up
There you go. You have now used the command line and done so to gather up your basic networking information for your new Linux box. Pretty simple stuff eh? We'll continue on with new-user-friendly articles now and then and eventually those new users will be drilling down deeper and deeper into the Linux operating system.