Posted: . At: 12:17 PM. This was 10 years ago. Post ID: 7163
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.

Yet another way to get the IP address of a host and print it. And other useful networking commands.

This is a good way to get the IP address of a host and print it to the terminal.

homer@deusexmachina ~ $ host yahoo.com | awk '/ has address / { print $4 }' | cut -d " " -f14-
98.138.253.109

This is a very useful one liner for getting an IP address.

Very useful awk tips: http://stackoverflow.com/questions/21177338/ipcalc-output-and-grep-want-to-return-only-the-binary-output.

The finger command shows information about users that are logged into a machine.

homer@deusexmachina ~/Documents $ finger -lmps
Login: homer                            Name: John Cartwright
Directory: /home/homer                  Shell: /bin/bash
On since Tue Apr 15 09:29 (EST) on tty8 from :0
    2 hours 2 minutes idle
On since Tue Apr 15 09:49 (EST) on pts/0 from :0.0
   1 hour 1 minute idle
On since Tue Apr 15 11:30 (EST) on pts/1 from d110-33-8-105.bla800.nsw.optusnet.com.au
   6 seconds idle
No mail.

The who am i command shows information about your user. I am logged into my machine over SSH so it shows the hostname of my current ISP.

homer@deusexmachina ~/Documents $ who am i
homer    pts/1        2014-04-15 11:30 (d110-33-8-105.bla800.nsw.optusnet.com.au)

Display the routing table with the ip route command.

homer@deusexmachina ~/Documents $ ip route
default via 192.168.1.1 dev eth0  proto static
192.168.1.0/24 dev eth0  proto kernel  scope link  src 192.168.1.2  metric 1
192.168.122.0/24 dev virbr0  proto kernel  scope link  src 192.168.122.1

Another way to show the routing table. Use the arp -a command.

homer@deusexmachina ~/Documents $ arp -a
? (192.168.1.1) at 84:c9:b2:bd:c2:e7 [ether] on eth0

Yet another way to show the routing table on Linux.

homer@deusexmachina ~/Documents $ route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.1.1     0.0.0.0         UG    0      0        0 eth0
192.168.1.0     *               255.255.255.0   U     1      0        0 eth0
192.168.122.0   *               255.255.255.0   U     0      0        0 virbr0

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.