hostname解析原理

今天遇到个问题,启动系统的时候:
Mounting local filesystems...
Setting up networking...done.
Hostname: none.
Configuring network interfaces: done.
Starting portmap daemon: portmap.
Fast Replaying boot udev events...
INIT: Entering runlevel: 3
Starting sshd:/usr/sbin/sshd: error while loading shared libraries: libcrypto.so.0.9.8: cannot open shared object file: No such file or directory
ok
Starting xinetd: ok
STMicroelectronics Base Distribution version 2.3
none login: root
Linux xxha 2.6.23.17_stm23_A19-SDK7105_7105-STSDK #19 PREEMPT Thu Jun 24 11:38:20 CST 2010 sh4 unknown unknown GNU/Linux
Welcome to STMicroelectronics Base Distribution.
No mail.
root@(none ):~#
 
hostname,没解析出来,于是就在网上查了些关于主机名解析资料。终于知道怎么一回事了。
原来是etc/下面没有hostname文件。
系统启动的时候,会运行etc/init.d/hostname.sh 脚本。
[root@localhost etc]# cat init.d/hostname.sh
#
# hostname.sh   Set hostname.
#
# Version:      @(#)hostname.sh  1.10  26-Feb-2001  miquels@cistron.nl
#
# chkconfig: S 40 0
#
echo -n "Hostname: "
if [ -f /etc/hostname ]
then
        hostname --file /etc/hostname
fi
echo $(hostname)"."
[root@localhost etc]#
 
可以看出,他是读取了hostname文件,来命名主机名。
所以添加个hostname文件。
[root@localhost etc]# cat hostname
xxha

[root@localhost etc]#
 
然后再做成yaffs2文件系统,启动,oye,
Mounting local filesystems...
Setting up networking...done.
Hostname: xxha.
Configuring network interfaces: done.
Starting portmap daemon: portmap.
Fast Replaying boot udev events...
INIT: Entering runlevel: 3
Starting sshd:/usr/sbin/sshd: error while loading shared libraries: libcrypto.so.0.9.8: cannot open shared object file: No such file or directory
ok
Starting xinetd: ok
STMicroelectronics Base Distribution version 2.3
xxha login: root
Linux xxha 2.6.23.17_stm23_A19-SDK7105_7105-STSDK #19 PREEMPT Thu Jun 24 11:38:20 CST 2010 sh4 unknown unknown GNU/Linux
Welcome to STMicroelectronics Base Distribution.
No mail.
root@xxha :~#
 
主机名出来了。
 
另外用hostname命令,也可以添加主机名,如下:
 
[root@localhost etc]# hostname --help
Usage: hostname [-v] {hostname|-F file}      set hostname (from file)
       domainname [-v] {nisdomain|-F file}   set NIS domainname (from file)
       hostname [-v] [-d|-f|-s|-a|-i|-y|-n]  display formatted name
       hostname [-v]                         display hostname
       hostname -V|--version|-h|--help       print info and exit
    dnsdomainname=hostname -d, {yp,nis,}domainname=hostname -y
    -s, --short           short host name
    -a, --alias           alias names
    -i, --ip-address      addresses for the hostname
    -f, --fqdn, --long    long host name (FQDN)
    -d, --domain          DNS domain name
    -y, --yp, --nis       NIS/YP domainname
    -F, --file            read hostname or NIS domainname from given file
   This command can read or set the hostname or the NIS domainname. You can
   also read the DNS domain or the FQDN (fully qualified domain name).
   Unless you are using bind or NIS for host lookups you can change the
   FQDN (Fully Qualified Domain Name) and the DNS domain name (which is
   part of the FQDN) in the /etc/hosts file.
[root@localhost etc]#
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值