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.
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 |