How to get your IP from a BASH script

For when you have many network interfaces

Shawn Grover
May 25 · 4 min read
Photo by Jonathan on Unsplash

The short version:

ip addr show $(ip route | awk '/default/ { print $5 }') | grep "inet" | head -n 1 | awk '/inet/ {print $2}' | cut -d'/' -f1