Set hostname through ssh command login

After login the device through ssh via putty. I would like to change the hostname in OpenWrt.

Kindly assist here.

It is defined in /etc/config/system. Change it there and reboot.

3 Likes

Do this for instant satisfaction

uci set system.@system[0].hostname=newhostname
uci commit
echo newhostname > /proc/sys/kernel/hostname
1 Like

An easy way to find the commands for certain operation is to do it in LuCI and see how it translate in the UNSAVED CHSNGES review. For example:

After changing the host name in LuCI you click the cyan button at the top, and you see:

Probably this is not the perfect example to demonstrating the idea of using the review, as the value of @system[0] changes from a device to another, but the idea applies to other commands.

3 Likes

Don't forget you must always use

uci commit

After setting each uci value, and in the case of somethings they are not changed without reboot unless you know how and where in the kernel systems those values are located.

Hostname is just one example

1 Like