How to use the same hostname for two addresses?

I have a computer with two connections, with ethernet and wifi.

The computer obtains the address by ethernet
The computer obtains the address by wifi

The computer has a webapp and needs the domain mysuperapp.local

The computer might be connected both by ethernet and wifi at the seame time. Also, the computer might be connected only by wifi or ethernet.

Is there a way using openwrt to have the same hostname for any available ip address available for the same computer?

Add another, virtual IP address similar to a loopback and configure two static routes to it via the IP addresses of the real interfaces.

1 Like

This should just work if your dnsmasq is set up properly. The name provided by the computer must be unique on your network. A hostname is one word which then becomes attached to the local domain. The default domain is .lan. You can change that though.

It is not recommended to do that. If you do, the named IP should be assigned to the first interface that connects. The other interface using the same name will get a random IP and appear in the list of DHCP clients with a * for hostname. To change from one connection to the other you have to wait for the lease to expire. Use a short lease time if you're going to do that.

To always get a definite numeric IP, DHCP reservations can be entered by hostname. Enter name and ip but leave macaddress blank.

1 Like

A domain can be resolved to multiple IPs in round-robin using hostnames.
Then the client browser should reach it no matter which connection is currently active.

Note however, that the .local domain is reserved for mDNS and you should not use it for DNS, otherwise the result is unpredictable due to possible race condition between different resolver backends.

local was only an example. But now I learned about it, I won't use it.

so, basically, I just set the same hostname with two different ips? That's it?

Also, how to wilcard the domain? In the documentation, there's a section "A and AAAA RR". What I understand is that adding /mysuperapp.lan/ in Network -> DHCP and DNS -> General Settings, Addreses field I could ping to example.mysuperapp.lan and it would resolve to

Would it work if I add another record like /mysuperapp.lan/

1 Like

If you are trying to use this way for reverse lookup purpose (i.e. So that you can know those 2-3 IPs are actually same device) it works, but if you want to use it for PING from other device you will have trouble. The DNS lookup has 3 records and you don't know which one will be picked by peer device, for example your WiFi interface has .1.10 (CONNECTED) while Ethernet has .1.11 (UNPLUGGED) and peer device OS picked .1.11 the PING will fail even though the WiFi is connected.

then ping is a nono but what if I want to access the webserver on that machine? Would it work having two "address" records with the same domain but two ips?


Would it round robin the ips?

This is not supported, a possible solution is setting up an HTTP redirect on the router with uHTTPd.

Seems like it's not possible. Out of curiosity, how to set the redirect you mention?

I think a more viable aproach would be to use another computer, /mysuperapp.lan/ and that machine could do some load balancing and rerverse proxy with nginx.

If PING doesn't work, how would you think HTTP would work? Clients are reaching out to the server with the same logic, you still have 50% chance of no connection if server side has only 1 IP online.

Use HAProxy
But in your case, if you have 2 x ethernet then the easiest way is doing linux bonding and you don't need to worry about any one of the link down.

Your link already tells that DNS-RR is not for covering application failures, which in OP's case when one link is being taken down on server side. And also different OSes/HTTP requesters will have different way of handling, you can't simply control them.

According to your post above it should work like ping with 50% of failure rate, but I actually tested it, and a modern browser like Chrome or Firefox running on a Linux system sticks to the last working IP and switches to another IP on timeout, apparently utilizing a built-in failover, and ping does not do that.

I used the ┬┤address=/domain.lan/┬┤ and HAproxy.

In worked like I always wanted.

1 Like

This is what I mentioned: You are relying on unknown client handling, did you test with ALL HTTP clients in the world to see how it performs? What if their handling logic changing in future? Or someone is doing HTTP request by their own program? Obiously It's not a consistent solution, and when something like HAProxy is there I don't see why we should use the DNS-RR here.

Glad it works for you!

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