Posted: . At: 8:50 PM. This was 6 years ago. Post ID: 12095
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.


Another way to get the actual IP address of your machine.


This is yet another way to get the actual IP address of your Linux machine on a LAN. This returns just the IP address of your Linux computer.

jason@jason-Lenovo-H50-55:~$ ip a | awk '/inet / { print $2 }' | sed -n 2p
192.168.1.4/24

This is very effective in a script, people want a way to get just the IP address and this is it.

How to get just the IP address of your Linux machine using curl.

http://securitronlinux.com/debian-testing/how-to-get-just-the-ip-address-of-your-linux-machine-using-curl/.

This is how to get the gateway IP address from a machine and print just the number.

jason@jason-Lenovo-H50-55:~$ netstat -r -n | sed -n 3p | awk '{print $2}'
192.168.1.1

This one-liner will print just the interface used for that gateway address.

jason@jason-Lenovo-H50-55:~$ netstat -r -n | sed -n 3p | awk '{print $8}'
eth0

List all available networking interfaces.

jason@jason-Lenovo-H50-55:~$ ls -l /sys/class/net
total 0
lrwxrwxrwx 1 root root 0 May  9 11:16 eth0 -> ../../devices/pci0000:00/0000:00:03.4/0000:02:00.0/net/eth0
lrwxrwxrwx 1 root root 0 May  9 17:58 lo -> ../../devices/virtual/net/lo
lrwxrwxrwx 1 root root 0 May  9 11:16 wlan0 -> ../../devices/pci0000:00/0000:00:15.2/0000:05:00.0/net/wlan0

Leave a Comment

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