openwrt默认主机名为【OpenWrt】,透过修改源码方式,修改默认主机名。
适用版本openwrt v19.07.4
- 查看etc/config/system,默认hostname=OpenWrt
root@Eric:/# cat etc/config/system
config system
option hostname 'OpenWrt'
option timezone 'UTC'
option ttylogin '0'
option log_size '64'
option urandom_seed '0'
- 修改源码【package/base-files/files/bin/config_generate】,将"OpenWrt"替换为"Eric"
generate_static_system() {
# eric++
# set system.@system[-1].hostname='OpenWrt'
uci -q batch <<-EOF
delete system.@system[0]
add system system
set system.@system[-1].hostname='Eric'
set system.@system[-1].timezone='UTC'
set system.@system[-1].ttylogin='0'
set system.@system[-1].log_size='64'
set system.@system[-1].urandom_seed='0'
delete system.ntp
set system.ntp='timeserver'
set system.ntp.enabled='1'
set system.ntp.enable_server='0'
add_list system.ntp.server='0.openwrt.pool.ntp.org'
add_list system.ntp.server='1.openwrt.pool.ntp.org'
add_list system.ntp.server='2.openwrt.pool.ntp.org'
add_list system.ntp.server='3.openwrt.pool.ntp.org'
EOF
- 编译、下载后,重新查看system
root@Eric:/# cat etc/config/system
config system
option hostname 'Eric'
option timezone 'UTC'
option ttylogin '0'
option log_size '64'
option urandom_seed '0'
- 查看hostname文件
root@Eric:/proc/sys/kernel# cat hostname
Eric