Linux: How to check your Local and Public IPv4/v6 address


Local IPv4 address
Method 1:

ip -4 addr |grep -E '\b[0-9]+\.[0-9]+\.[0-9]+\.[0-9]\b'| awk '{ print $2}'

Method 2:

ip -4 addr |grep -E \\b[0-9]+\.[0-9]+\.[0-9]+\.[0-9]\\b | awk '{ print $2}'

Method 3:

ifconfig | grep -w inet | awk '{ print $2}'

Method 4:

ip a s | grep -w inet | awk '{ print $2}'

Public IPv4 address
Method 1:

curl -s4 https://www.cloudflare.com/cdn-cgi/trace |grep -E '\b[0-9]+\b.[0-9]+\b.[0-9]+\b.[0-9]+\b'| awk '{ print $1}'| sed 's/ip=//g'

Method 2:

echo $(wget -qO - https://api.ipify.org)

Method 3:

echo $(curl -s https://api.ipify.org)

Method 4:

echo $(wget -qO - http://ip.yooooo.us/ip)

Method 5:

echo $(curl -s http://ip.yooooo.us/ip)

Local IPv6 address

ip -6 addr |grep -P '\b([0-9a-f]{1,4}\b|[\:]){3,}\b' | awk '{ print $2}'

Public IPv6 address

curl -s6 https://www.cloudflare.com/cdn-cgi/trace|grep -P '\b([0-9a-f]{1,4}\b|[\:]){3,}\b' | awk '{ print $0}' | sed 's/ip=//g'

Leave a Reply