Skip to content

Find out my public IP on the terminal

Published: | 1 min read

Often it is important to find out, what is my machine’s public IP address. There are numerous websites to get this information, but it is much faster to do on the terminal.

We can do this by querying Google’s name servers with a specific query using dig. This will send back my IP as a response.

I want to query both IPv4 and IPv6 addresses, so I run the query twice with different parameter to dig.

As per usual, I ended up creating a new alias to my .zshrc.

alias myip='echo "IPv4:" && dig -4 TXT +short && echo "IPv6:" && dig -6 TXT +short'

Now I can just run myip on the terminal to get my public IPs.

> myip


This article is inspired by another article by someone, but I lost the link :(