Linux networking commands. How to get information about your network and ip addresses.

Some useful Linux networking commands.

Using the Linux arp command.

How to use the ipcalc command.

How to do a reverse lookup of an IP address with the dig command.

The dig -x command will perform a reverse lookup of an IP address. Just use this command and you can find out what the hostname of the IP is.

[email protected]:~/Documents$ dig -x 8.8.8.8

; <<>> DiG 9.9.3-rpz2+rl.13214.22-P2-Ubuntu-1:9.9.3.dfsg.P2-4 <<>> -x 8.8.8.8
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 15652
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;8.8.8.8.in-addr.arpa.		IN	PTR

;; ANSWER SECTION:
8.8.8.8.in-addr.arpa.	68487	IN	PTR	google-public-dns-a.google.com.

;; AUTHORITY SECTION:
8.in-addr.arpa.		67436	IN	NS	ns2.level3.net.
8.in-addr.arpa.		67436	IN	NS	ns1.level3.net.

;; Query time: 55 msec
;; SERVER: 192.168.1.1#53(192.168.1.1)
;; WHEN: Wed Sep 18 22:47:40 EST 2013
;; MSG SIZE  rcvd: 139

Using the ifconfig command.

The ifconfig command is used to get the IP addresses associated with your networking interfaces. Here you can see the eth0 ethernet adapter that has the IP address of 192.168.1.5. This is 11000000.10101000.00000001.00000101 in binary.

[email protected]:~/Documents$ ifconfig 
eth0      Link encap:Ethernet  HWaddr 08:00:27:85:68:81  
          inet addr:192.168.1.5  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe85:6881/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:12108 errors:0 dropped:0 overruns:0 frame:0
          TX packets:6529 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:18103190 (18.1 MB)  TX bytes:458899 (458.8 KB)
          Interrupt:19 Base address:0xd000 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:4 errors:0 dropped:0 overruns:0 frame:0
          TX packets:4 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:240 (240.0 B)  TX bytes:240 (240.0 B)

Here I am only showing results for one interface.

[email protected]:~/Documents$ ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 08:00:27:85:68:81  
          inet addr:192.168.1.5  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe85:6881/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:18721 errors:0 dropped:0 overruns:0 frame:0
          TX packets:10120 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:27674395 (27.6 MB)  TX bytes:753045 (753.0 KB)
          Interrupt:19 Base address:0xd000

The ifconfig command is the best way by far to get your IP address.

Using the ipcalc command to get information about an IP address. This tutorial is using Debian Linux 7.1.

Here I am using the ipcalc 192.168.1.1 command to get the binary value of that IP address. The IP address has 4 groups of 8 bits which makes up a 32bit IP address. Newer versions of the ipcalc command have different command-line parameters to the older versions and this is why I created this page.

Address:     192.168.1.1           11000000.10101000.00000001. 00000001
Netmask: 255.255.255.0 = 24 11111111.11111111.11111111. 00000000
Wildcard: 0.0.0.255 00000000.00000000.00000000. 11111111
=>
Network:     192.168.1.0/24        11000000.10101000.00000001. 00000000
HostMin: 192.168.1.1 11000000.10101000.00000001. 00000001
HostMax: 192.168.1.254 11000000.10101000.00000001. 11111110
Broadcast: 192.168.1.255 11000000.10101000.00000001. 11111111
Hosts/Net: 254 Class C, Private Internet

This example shows a Class D multicast network. There is some information about Class D networks on this page: http://superuser.com/questions/289310/class-d-ip-address.

Address:     224.1.1.1             11100000.00000001.00000001. 00000001
Netmask: 255.255.255.0 = 24 11111111.11111111.11111111. 00000000
Wildcard: 0.0.0.255 00000000.00000000.00000000. 11111111
=>
Network:     224.1.1.0/24          11100000.00000001.00000001. 00000000
HostMin: 224.1.1.1 11100000.00000001.00000001. 00000001
HostMax: 224.1.1.254 11100000.00000001.00000001. 11111110
Broadcast: 224.1.1.255 11100000.00000001.00000001. 11111111
Hosts/Net: 254 Class D, Multicast

Btw; I used the -h parameter for the ipcalc command to get the lovely HTML output I could paste into this page.

Use the arp -a command to get the arp routing table. I am using Ubuntu 13.10 in Virtualbox at the moment; so this does not show many entries; but this is a useful command.

[email protected]:~/Documents$ arp -n
Address                  HWtype  HWaddress           Flags Mask            Iface
192.168.1.1              ether   84:c9:b2:bd:c2:e7   C                     eth0

This is what the arp -a command looks like on Cygwin.

[email protected] $ arp -a

Interface: 192.168.1.4 --- 0x5
  Internet Address      Physical Address      Type
  192.168.1.1           84-c9-b2-bd-c2-e7     dynamic
  192.168.1.2           4c-0f-6e-5d-e1-25     dynamic
  192.168.1.5           08-00-27-85-68-81     dynamic
  192.168.1.255         ff-ff-ff-ff-ff-ff     static
  224.0.0.22            01-00-5e-00-00-16     static
  224.0.0.251           01-00-5e-00-00-fb     static
  224.0.0.252           01-00-5e-00-00-fc     static
  239.255.255.250       01-00-5e-7f-ff-fa     static
  255.255.255.255       ff-ff-ff-ff-ff-ff     static

Interface: 192.168.56.1 --- 0xc
  Internet Address      Physical Address      Type
  192.168.56.255        ff-ff-ff-ff-ff-ff     static
  224.0.0.22            01-00-5e-00-00-16     static
  224.0.0.251           01-00-5e-00-00-fb     static
  224.0.0.252           01-00-5e-00-00-fc     static
  239.255.255.250       01-00-5e-7f-ff-fa     static