- Some useful Linux networking commands.
- How to do a reverse lookup of an IP address with the dig command
- Using the ifconfig command
- Using the ipcalc command to get information about an IP address
- Use the arp command to get the arp routing table
Some useful Linux networking commands.
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]:~$ dig 8.8.8.8 ; <<>> DiG 9.10.3-P4-Ubuntu <<>> 8.8.8.8 ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 3984 ;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 65494 ;; QUESTION SECTION: ;8.8.8.8. IN A ;; Query time: 93 msec ;; SERVER: 127.0.0.53#53(127.0.0.53) ;; WHEN: Sat Sep 16 12:10:04 AEST 2017 ;; MSG SIZE rcvd: 36 |
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]:~$ ifconfig enp0s25: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.2 netmask 255.255.255.0 broadcast 192.168.1.255 inet6 fe80::5afa:8eba:e6f6:fba8 prefixlen 64 scopeid 0x20<link> inet6 fdc8:1451:5fa9:4700:80e0:31d9:68af:bb35 prefixlen 64 scopeid 0x0<global> inet6 fdc8:1451:5fa9:4700:cdb5:2a0a:91c7:16e6 prefixlen 64 scopeid 0x0<global> inet6 fdc8:1451:5fa9:4700:7163:b140:65a4:ae4e prefixlen 64 scopeid 0x0<global> ether d0:50:99:0d:ab:0f txqueuelen 1000 (Ethernet) RX packets 4641369 bytes 6763162659 (6.7 GB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 3422758 bytes 283587787 (283.5 MB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 device interrupt 20 memory 0xf3200000-f3220000 enp3s0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 ether 00:13:46:3a:02:83 txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1000 (Local Loopback) RX packets 41990 bytes 2557336 (2.5 MB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 41990 bytes 2557336 (2.5 MB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 |
Here I am only showing results for one interface.
[email protected]:~$ ifconfig enp0s25 enp0s25: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.2 netmask 255.255.255.0 broadcast 192.168.1.255 inet6 fe80::5afa:8eba:e6f6:fba8 prefixlen 64 scopeid 0x20<link> inet6 fdc8:1451:5fa9:4700:80e0:31d9:68af:bb35 prefixlen 64 scopeid 0x0<global> inet6 fdc8:1451:5fa9:4700:cdb5:2a0a:91c7:16e6 prefixlen 64 scopeid 0x0<global> inet6 fdc8:1451:5fa9:4700:7163:b140:65a4:ae4e prefixlen 64 scopeid 0x0<global> ether d0:50:99:0d:ab:0f txqueuelen 1000 (Ethernet) RX packets 4663205 bytes 6795159019 (6.7 GB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 3439047 bytes 284948229 (284.9 MB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 device interrupt 20 memory 0xf3200000-f3220000 |
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
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.
[email protected]:~$ ipcalc 192.168.1.1 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 |
Use the arp command to get the arp routing table
[email protected]:~$ arp -n Address HWtype HWaddress Flags Mask Iface 192.168.1.1 ether c8:14:51:5f:a9:47 C enp0s25 |
This is what the arp -a command looks like on Cygwin.
Homer@bejiitas $ 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 |