[Solved] How to change hostname without restarting?

Hello. I wanted to change my router hostname, so I checked https://openwrt.org/docs/guide-user/base-system/system_configuration and did as told there, that is, to change the /etc/config/system file. After saving, I noticed the previous name was still in use, and the new name was not. So I did as told on https://forum.openwrt.org/viewtopic.php?id=14620 and did uci commit and uci commit system. However, the previous name is still in use.

The Open-WRT forum topic doesn't tell how to apply the new hostname without the need to restart the system. Is it possible? How can I do that?

  • Some Linux manuals note to change the entry in /etc/hosts...but this is a workaround.
  • Systemd-based machines use hostnamectl to change the hostname instead, this is not an option on OpenWRT

This works for me:

uci set system.@system[0].hostname='insert-hostname'
uci commit system
/etc/init.d/system reload

I found your commands on a site that says:

Note: this paragraph is meant for routers with old firmware, that may not have 'pretty-hostname', yet.

@lido, please let us know how it works.

/etc/init.d/system restart should apply the new name. You should see the new name immediately in the next prompt. This is not a reboot.


Exactly what I needed! Thank you, problem solved.
By the name of the command (restart) I would indeed believe it would be a reboot. But it's not. It's as you said.

1 Like

This topic was automatically closed after 4 days. New replies are no longer allowed.