There are several circumstances where you need to know the IP of your current machine. It may also be programmatically through a script or an Ansible playbook. To do that you can a website like , , or even (you need to parse the JSON though). curl ifconfig.co icanhazip.com myip.com For example: curl ifconfig.co On an AWS instance, you can reliably to retrieve IPs and other info on your current instance. More details there curl http://169.254.169.254/latest/meta-data/ https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html While these APIs are free, they are 3rd parties and may have API rate limits. One day they could also disappear or not function, right? To avoid any incident, we want to find a reliable solution that lasts. And if it can also work in an internal network without internet it would be perfect. In that case, I recommend you create a new endpoint on any domain you like. And deploy the open-source software behind ifconfig.co: https://github.com/mpolden/echoip I deployed it myself, and it is available here: https://ip.alvesdi.as Here is how I did. First, I pulled the Docker image: docker pull mpolden/echoip Then to activate the Geolocation, I went to the MaxMind website here: https://dev.maxmind.com/geoip/geoip2/geolite2/ Signed up for a free account and downloaded the GeoLite 2 Databases for ASN, Cities, and Countries. I also made a script to automate the update of my databases daily using my license key. Here is the script I use: LICENSE_KEY= wget -O ASN.tar.gz wget -O City.tar.gz wget -O Country.tar.gz file *.tar.gz; tar xzvf --strip-components 1 && rm ; #!/bin/bash # Fill your key "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-ASN&license_key= &suffix=tar.gz" ${LICENSE_KEY} "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&license_key= &suffix=tar.gz" ${LICENSE_KEY} "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country&license_key= &suffix=tar.gz" ${LICENSE_KEY} for in do " " ${file} " " ${file} done And then here is how I start the container: docker run --name ip -p 8080:8080 -d -v ./GeoLite2-ASN.mmdb:/GeoLite2-ASN.mmdb -v ./GeoLite2-City.mmdb:/GeoLite2-City.mmdb -v ./GeoLite2-Country.mmdb:/GeoLite2-Country.mmdb --restart=unless-stopped mpolden/echoip -H -a /GeoLite2-ASN.mmdb -c /GeoLite2-City.mmdb -f /GeoLite2-Country.mmdb "X-Real-IP" I use because I host it behind Nginx. FYI here is my Nginx configuration: -H "X-Real-IP" { ip.alvesdi.as; / { X-Real-IP ; Host ; http://127.0.0.1:8080; } ssl; /etc/letsencrypt/live/ip.alvesdi.as/fullchain.pem; /etc/letsencrypt/live/ip.alvesdi.as/privkey.pem; /etc/letsencrypt/options-ssl-nginx.conf; /etc/letsencrypt/ssl-dhparams.pem; } { ( = ip.alvesdi.as) { https:// ; } ip.alvesdi.as; ; ; } server server_name location proxy_set_header $remote_addr proxy_set_header $http_host proxy_pass listen 443 # managed by Certbot ssl_certificate # managed by Certbot ssl_certificate_key # managed by Certbot include # managed by Certbot ssl_dhparam # managed by Certbot server if $host return 301 $host $request_uri # managed by Certbot server_name listen 80 return 404 # managed by Certbot Voilà, if you did the same, you now have your own reliable IP service as well. Feel free to reuse it in all your scripts and Ansible playbook. Photo by on Fares Hamouche Unsplash