OpenWrt Forum Archive

Topic: how to change prompt and hostname

The content of this topic has been archived on 30 Mar 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

All,
I am running kamikaze 7.07 on RB532. I have 4 boards on my network and want
to identify as soon as I login.  The easy way to do it by changing the "prompt", hostname.
plse tell me how to change them....

thanks,
nv

Edit the /etc/config/system file and replace the OpenWRT with the name of your choice.

From my local wiki:

====== Set/get the hostname from a shell script ======

Set a hostname
<code>uci set system.cfg1.hostname=<somehostname>
uci commit system
echo $(uci get system.cfg1.hostname) > /proc/sys/kernel/hostname</code>


Read the hostname
<code>uci get system.cfg1.hostname</code>

Read the hostname using the UCI API
<code>#!/bin/sh

. /etc/functions.sh

config_load "system"
local section="cfg1"
config_get "hostname"  "$section" "hostname"

echo "$hostname"</code>

thank you guys ...

mazilo wrote:

Edit the /etc/config/system file and replace the OpenWRT with the name of your choice.

Done. Besides reboot, is there any specific service need to be restarted so that the new name will be effective immediately?

root@OpenWrt:~# cat /etc/config/system
config system
        option hostname NewHostName
        option timezone UTC

config timeserver ntp
        list server     0.openwrt.pool.ntp.org
        list server     1.openwrt.pool.ntp.org
        list server     2.openwrt.pool.ntp.org
        list server     3.openwrt.pool.ntp.org
        option enable_server 0
root@OpenWrt:~#

If you have done a reboot there is no much else you can restart.

Also for newer version you could use the uci commands, however I'm not sure which release is the first one compatible with them. Maybe somebody else could clarify that bit.

For changing the name you can type:

uci set system.@system[0].hostname=NewHostName

BTW, do not forget to do a commit whenever you've finished with your changes. Otherwise, they won't make any effect. Lets say is the same way as in the LUCI interface, first you save all changes, then apply:

uci commit

I hope this may help anyone using a later version.

(Last edited by diegomanas on 16 Sep 2013, 17:56)

uci set system.@system[0].hostname=your_new_hostname
uci commit system
/etc/init.d/boot restart

This works too:

uci set system.@system[0].hostname=myhostname
uci commit system
echo $(uci get system.@system[0].hostname) > /proc/sys/kernel/hostname

1.) No reboot

I changed the hostname thru the web GUI and it worked without restart.


2.) dnsmaq must be restarted/reloaded

(/etc/init.d/dnsmasq reload) otherwise it will not resolve the new hostname to DNS clients


So questions are:

1.) What does the GUI do (besides uci commit)? /etc/init.d/system reload?

2.) Can the changing of hostname be made to also trigger a reload of dnsmasq (if present) ?

(Last edited by xerces8 on 31 Mar 2014, 21:30)

How is this done during the make process to override the pre-existing default name?

For example, I want my package to modify the default configuration already being applied.

awolverton wrote:

How is this done during the make process to override the pre-existing default name?

For example, I want my package to modify the default configuration already being applied.

Like a year late answer, but this is done by adding a script into /etc/uci-defaults at build time. (you generate a /files/etc/uci-defaults folder in the /source folder, then in there you place your script)

Scripts into that folder are called when starting the system the first time, and there you can set whatever command to change anything.

The discussion might have continued from here.