# 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"
admin