Get IP address translations
A server can be configured with multiple network address, and sometimes these can be behind a firewall that provides NAT.
Mappings between public and private IPv4 addresses are not always intuitive. When multiple IP addresses are present, investigating each interface can take some time.
To check all interfaces sequentially, try one of these:
Using the ifconfig
command:
for IP in $(ifconfig | grep "inet addr" | cut -d: -f2 | awk '{ print $1 }') ; do \
echo -n "Internal $IP, External " ; \
timeout 5 curl icanhazip.com --interface $IP 2>/dev/null || echo "N/A" ; \
done | sort -V
Using the ip
command:
for IP in $(ip addr | grep inet | awk '{ print $2 }' | cut -d'/' -f1) ; do \
echo -n "Internal $IP, External " ; \
timeout 5 curl icanhazip.com --interface $IP 2>/dev/null || echo "N/A" ; \
done
This does require external access to the icanhazip.com service, but you could substitute another service, such as ifconfig.me, or any other service that returns just the IP address.