Forwarding Hostnames

TLDR: How do I forward traffic from one hostname on my LAN to another?

I have multiple servers set up on an old computer. When I'm setting a device on my LAN to access them, I enter with the port number of the server I want.

But In the future I'm planning to move them to different hardware. I'd like to set my various devices in a way that won't have to be changed in the future. I'd like them to be pointed to,, etc. with the router knowing that the hostnames serverone, servertwo, etc are alias for oldcomputer or newserver or raspberrypi or whatever and forwarding all the traffic. That way if I move a server in the future, I just change the setting on the router and don't have to change every device.

I'm guessing it's a simple thing to do in OpenWRT; I just don't know how. Any help would be appreciated.

static DHCP leases, or add them to the hosts file of the router.

Can I set up multiple static DHCP leases with different hostnames but the same IP?

And if I use the hosts file, how would you recommend I set it up? a static IP for "oldcomputer" and then an entry in the hosts file for each server hostname pointing to oldcomputer's static IP?

I'll go that way if I need to, but it would be nice if there was some way to do hostname > hostname and leave the IPs out of it.

Resolve LAN addresses - #6 by vgaetera

1 Like

I was thinking of your future lay out, with separate hosts....

You can't have several DHCP entries for one MAC, at least not in the same subnet.

Look at the links vgaetera posted.

You can also use cnames


Thanks, @trendy ! I think cnames is what I need.

Is there a way to set/edit cnames in the GUI or do I need to enter the uci commands through SSH? Also, what about when I want to change them later? Is there a UCI command for that or should I just edit /etc/config/dhcp ?

Nothing in luci for the time being. Either use uci commands as in the wiki to create and edit, or edit directly the config file.

1 Like

I use static leases to name the hardware (server1, server2, ...) then CNAMEs to name the services (files, data, ...). This way, I can move services among servers, without reconfiguring clients.


Yeah, that's basically what I've done based on trendy's suggestion above. In my case I didn't use static leases because it seems to work fine without them, but I'd be curious to hear if you found you needed them or just wanted the extra stability?

Also, I've mainly been using this for accessing web GUIs on the servers, but was wondering what you've found regarding whether this works with other protocols (SSH, Samba, FTP, etc.) as well?

If there is no static lease, then another system might get that IP. It's a trivial task that ensures there won't be surprises in the future.

It works with every client application using hostname as input apart from IP.

1 Like

Very true, but the CNAME is forwarding from hostname to hostname, so it doesn't seem to matter what the machine's IP address is. The dynamic IP doesn't seem to have any effect on what hostname is assigned, as I'm assuming OpenWRT assigns whatever hostname the machine reports.

Don't get me wrong, I agree that setting a static IP is a simple step that's helpful in adding stability. I was just inquiring (mainly for reference) whether or not it's absolutely necessary. Hasn't seemed so in my case, but I've only been using it for a few days.

This is unreliable for wired clients since the lease file doesn't survive the router's reboot.

No, I do not think it is technically necessary to use static leases: the alias will point to the real name, and this to the current address.

Some device might cache the address, instead of resolving the name each time, and use wrong information for some time. And I think it is a best practice to use static leases for machines that must receive connections.

1 Like

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