# tested on Debian 10 su - root; # become root apt update; apt install dnsutils dig -v DiG 9.11.5-P4-5.1+deb10u2-Debian # tested on CentOS Linux 7 (Core) dig -v DiG 9.9.4-RedHat-9.9.4-74.el7_6.1 vim /scripts/what_is_my_public_ip.sh echo "my public (internet facing) ip is:" # echo "asking opendns..." # kind of failed: (does not return anything) # dig +short myip.opendns.com @resolver1.opendns.com echo "asking google..." # gives ipv6 per default dig TXT +short o-o.myaddr.l.google.com @ns1.google.com # gives ipv4 echo "trying to get one's public ipv4:" dig -4 TXT +short o-o.myaddr.l.google.com @ns1.google.com | awk -F'"' '{ print $2}' # gives ipv6 echo "trying to get one's public ipv6:" dig -6 TXT +short o-o.myaddr.l.google.com @ns1.google.com | awk -F'"' '{ print $2}'
all coffees go to: https://www.cyberciti.biz/faq/how-to-find-my-public-ip-address-from-command-line-on-a-linux/
alternativ:
visit via browser: https://ipinfo.io/
or from bash:
curl ipinfo.io
{
"ip": "123.123.123.123",
"hostname": "domain.com",
"city": "City",
"region": "Region",
"country": "DE",
"loc": "49.XXXX,10.XXXX",
"postal": "12345",
"org": "Hetzner Online GmbH"
liked this article?
- only together we can create a truly free world
- plz support dwaves to keep it up & running!
- (yes the info on the internet is (mostly) free but beer is still not free (still have to work on that))
- really really hate advertisement
- contribute: whenever a solution was found, blog about it for others to find!
- talk about, recommend & link to this blog and articles
- thanks to all who contribute!