How to find your IPv4 and IPv6 ip-addresses?

December 7th, 2018

How to check your IPv4 and IPv6 ip-adresses on the command line

Sure you can start up your browser and use Google to find a suitable website, but why not keep it simple and use the command line for this trivial task. Fire up a terminal and type:

> my_ip
> 2001:db8:85a3::8a2e:370:7334
> 172.16.254.1

Above IP-addresses are bogus, but you got my drift. To do this simply create the following bash script:

#!/bin/bash
# bin/my_ip

curl -6 v6.ifconfig.co
curl -4 v6.ifconfig.co

It will first output your IPv6 address.  If you don’t have one, it it will tell you:

> curl: (7) Couldn't connect to server
> xx.xx.xx.xxx

The script uses the great curl application with the simple -6 and -4 flags, to connect with IPv6 and IPv4.

Of course you could extend the script a bit to include geographical information:
#!/bin/bash
# bin/my_ip

curl -6 v6.ifconfig.co
curl -6 v6.ifconfig.co/city
curl -6 v6.ifconfig.co/country
curl -4 v6.ifconfig.co
curl -4 v6.ifconfig.co/city
curl -4 v6.ifconfig.co/country

Now you will get info about your city and country as well.

Leave a Reply