How to get WAN IP adress from LAN side clients easily

Can you tell me a way to easily get IP address at WAN side of the router running openwrt from the LAN side devices (Linux, FreeBSD, etc.) ?

I'm trying to create a mechanism to update DNS records at the time that the IP address on the WAN side of openwrt has changed. (My domain registrar provide a method to modify DNS records by REST APIs.)
I created a mechanism using Firefox's marionette API to get WAN IP address by scraping Luci /cgi-bin/luci/admin/network/network page.
However, this process is too heavy for my client machine, and if possible, we would like to use more lightweight clients such as wget or curl, which cannot handle Javascript.

Of course I understand that it is easy to find the WAN-side address by preparing a page on the Internet and checking the remote address with CGI, but I would like to achieve this by only accessing from the LAN side.
I thought about logging in to openwrt via SSH to get the WAN-side IP address automatically, but I would have to save the openwrt password on the client side, which I would like to avoid this option for security issue.

Any help would be greatly appreciated.

curl should also work from windows


Is there a reason you can't just run DDNS on your router?


can be an alias pointing to your ddns where your ddns will take care of the update. there are quite some free ddns service out there and may be you already have a device on your network offering that, like Nases, routers with original firmwares etc. Do you have a specific use case that requires specifically updating the ip in your registrar?

1 Like

may be the script there can be of help for your usecase : Help with WireGuard please - #7 by ZOzo?

Thank you for your reply.
Your answers contain many suggestions and I think each one is a great solution.

But I think it is a little bit risky to trust and rely on an Internet-side server that I do not have control by my own, and most of DDNS services require me to transfer the privileges of my current registrar to that service.

After the post, I thought a little more on my own, and I found a way to do this well.

(1) Run command below with cron on openwrt router.

ifconfig pppoe-wan > /www/wan_info.txt

(2) Get redirected test by HTTP/HTTPS clients like wget, curl or fetch at FreeBSD like below:

wget https:// [router's LAN side IP address] /wan_info.txt

I would like to adopt this approach because it is closest to my current needs.

Many thanks.

What registrar are you with?

uci set dhcp.@dnsmasq[0].add_local_fqdn="0"
uci set dhcp.@dnsmasq[0].add_wan_fqdn="1"
uci commit dhcp
/etc/init.d/dnsmasq restart
grep -e ${HOSTNAME} /tmp/hosts/dhcp.*
nslookup ${HOSTNAME} localhost
1 Like

I use
Gandi provides REST API known as Live DNS that can set very short TTL.
So I don't need alternative Dynamic-DNS.

The DDNS client on OpenWRT has support for The simplest solution, by far, is to use that to both keep track of changes to your WAN IP (after all what better place to do that than on the router) and update your DNS when required.

All you need to do is install the client on your router (along with the support script) and add the relevant details. It'll then use the REST API to make any necessary changes.


Thank you for information.

It seems that ddns-scripts already contains a script for Gandi REST API.

As you told to me, this is extremely simplest solution.

I never imagined that such a script was contained DDNS package and already available.
I should have consider this sort of possibility at first.

I'll try this package.

Many thanks.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.