Rewriting outbound URLs

Dear all

When we got 900 mbps FTTP a couple of years ago, I installed OpenWrt SNAPSHOT r15599-37752336bd / LuCI Master git-21.020.56896-af422b1 on a Raspberry Pi 4 Model B Rev 1.4 as my main router. It has been working excellently ever since.

One reason for choosing OpenWrt was because I hoped it might be able to be configured to do some other special stuff and I've finally got round to thinking about it.

I have a number of devices on the lan which are pre-programmed to send data to specific url's on the wan, an example is a weather station sending data as GET requests to a restful endpoint at weathercloud.com
eg
http://api.weathercloud.net/v01/set?wid=$WID&key=$Key&…

What I would like to do is rewrite "api.weathercloud.net" to "www.myserver.com" where myserver is also on the wan and running an instance of node-red in which I can create a matching endpoint and parse the data into my own database (and then forward the whole thing onwards to api.weathercloud.net)

Can this rewrite be done as it passes through openWrt ? how?

Thanks for your help.

Richard

If this does not involve HTTPS, then you can simply rebind the domain like this:
https://openwrt.org/docs/guide-user/base-system/dhcp_configuration#hostnames

3 Likes

You can change the ip address of api.weathercloud.net in DNSMasq so that it points e.g. to your router or a server on your lan.

You can add this as in /etc/config/dhcp so that api.weathercloud.net points to 192.168.6.2:
list address '/api.weathercloud.net/192.168.6.2'

1 Like

I have already set weather device to a static local IP

so according yo your link (ip v4 only) the script would be?

uci add dhcp domain
uci set dhcp.@domain[-1].name="api.weathercloud.net"   // url we want to intercept
uci set dhcp.@domain[-1].ip="60.70.80.90"  // IP of myserver.com
uci commit dhcp
/etc/init.d/dnsmasq restart

(assume // is comment, but doesn't matter)

Presumably this is a script I run by SSHing into my router as root ?

or is there a way of doing it in the LuCI UI ?

Thanks

Richard

Yes.

Carefully reading the linked section gives you: