Usage ipify API fails with error: Could not resolve host

Hello,
I want to fetch my public IP and display it in CLI using ipify API.
Therefore I created file /root/.profile with this code:

root@clancy:~# cat /root/.profile
#!/bin/sh

currentWANIP="$(curl http://api.ipify.org/ 2> /dev/null)"

echo
echo "My current WAN IP is: $currentWANIP" && echo

Unfortunately this is not working.
Verifying this using curl in CLI fails with error:

root@clancy:~# curl http://api.ipify.org/
curl: (6) Could not resolve host: api.ipify.org

However, there's no general DNS failure, means I can resolve any other domain, e.g.

root@clancy:~# nslookup openwrt.org
Server:         172.16.1.1
Address:        172.16.1.1#53

Name:      openwrt.org
Address 1: 139.59.209.225
Address 2: 2a03:b0c0:3:d0::1af1:1

root@clancy:~# nslookup cloudflare.com
Server:         172.16.1.1
Address:        172.16.1.1#53

Name:      cloudflare.com
Address 1: 104.16.132.229
Address 2: 104.16.133.229
Address 3: 2606:4700::6810:85e5
Address 4: 2606:4700::6810:84e5

Can you please advise how to fix this issue?

Try

 curl --ipv4 https://api.ipify.org/

This is weird...
curl command is working now, with and w/o --ipv4.

1 Like

Check your DNS address