免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1407 | 回复: 9
打印 上一主题 下一主题

When The System Get The Hostname [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-09-07 14:05 |只看该作者 |倒序浏览
hi,
please help .
I am using redhat9.0.
I removed the line 'DOMAINNAME=localdomain' from /etc/sysconfig/network.
then after a reboot, the hostname change to 'unassigned'.
how could it be.  

is anybody know:
which is the file we are using to store the machine`s name?
and when it is read to set up the hostname ?I mean which step at start time.

by the way, I tried to use 'hostname' to rename my machine, it work fine.
is this the way used in the start time?

if you know these ,please stop me wonderring.

thanks a lot.

论坛徽章:
0
2 [报告]
发表于 2005-09-07 14:09 |只看该作者

When The System Get The Hostname

给你移到linux版了~~~

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
3 [报告]
发表于 2005-09-07 15:04 |只看该作者

When The System Get The Hostname

please check /etc/hosts

论坛徽章:
0
4 [报告]
发表于 2005-09-07 16:39 |只看该作者

When The System Get The Hostname

add HOSTNAME=yourhostname to /etc/sysconfig/network

论坛徽章:
33
荣誉会员
日期:2011-11-23 16:44:17天秤座
日期:2014-08-26 16:18:20天秤座
日期:2014-08-29 10:12:18丑牛
日期:2014-08-29 16:06:45丑牛
日期:2014-09-03 10:28:58射手座
日期:2014-09-03 16:01:17寅虎
日期:2014-09-11 14:24:21天蝎座
日期:2014-09-17 08:33:55IT运维版块每日发帖之星
日期:2016-04-17 06:23:27操作系统版块每日发帖之星
日期:2016-04-18 06:20:00IT运维版块每日发帖之星
日期:2016-04-24 06:20:0015-16赛季CBA联赛之天津
日期:2016-05-06 12:46:59
5 [报告]
发表于 2005-09-07 17:04 |只看该作者

When The System Get The Hostname

I think the "hostname" should setup with the init script "sysinit",

you can check the /etc/rc.d/sysinit for more information.

and the hostname is stored is /etc/sysconfig/network
like this "HOSTNAME=localhost.localdomain"

the hostname in /etc/hosts only indecate that the ip address of the localhost, maybe an other hostname.

论坛徽章:
0
6 [报告]
发表于 2005-09-07 17:13 |只看该作者

When The System Get The Hostname

原帖由 "q1208c" 发表:
I think the "hostname" should setup with the init script "sysinit",

you can check the /etc/rc.d/sysinit for more information.

and the hostname is stored is /etc/sysconfig/network
like this "..........


exactly the file is /etc/rc.d/rc.sysinit

I checked this file and found this

  1. HOSTNAME=`/bin/hostname`
  2. HOSTTYPE=`uname -m`
  3. unamer=`uname -r`
  4. eval version=`echo $unamer | awk -F '.' '{ print "(" $1 " " $2 ")" }'`

  5. if [ -f /etc/sysconfig/network ]; then
  6.     . /etc/sysconfig/network
  7. fi
  8. if [ -z "$HOSTNAME" -o "$HOSTNAME" = "(none)" ]; then
  9.     HOSTNAME=localhost
  10. fi

复制代码

论坛徽章:
33
荣誉会员
日期:2011-11-23 16:44:17天秤座
日期:2014-08-26 16:18:20天秤座
日期:2014-08-29 10:12:18丑牛
日期:2014-08-29 16:06:45丑牛
日期:2014-09-03 10:28:58射手座
日期:2014-09-03 16:01:17寅虎
日期:2014-09-11 14:24:21天蝎座
日期:2014-09-17 08:33:55IT运维版块每日发帖之星
日期:2016-04-17 06:23:27操作系统版块每日发帖之星
日期:2016-04-18 06:20:00IT运维版块每日发帖之星
日期:2016-04-24 06:20:0015-16赛季CBA联赛之天津
日期:2016-05-06 12:46:59
7 [报告]
发表于 2005-09-07 17:15 |只看该作者

When The System Get The Hostname

[quote]原帖由 "wolfg"][/quote 发表:


Thanks.    

论坛徽章:
0
8 [报告]
发表于 2005-09-07 17:22 |只看该作者

When The System Get The Hostname

原帖由 "q1208c" 发表:


Thanks.    


I just wonder how the command 'hostname' get the hostname or where it save the hostname to?

论坛徽章:
0
9 [报告]
发表于 2005-09-07 23:42 |只看该作者

When The System Get The Hostname

thanks everybody,
after the discussion, I think I got the point. ,even I have not look the sysinit yet.I will check it later.

you help me a lot. I love CU.

more, I found these to share you.

http://lxr.linux.no/source/kernel/sys.c?v=1.0.9#654
sys_sethostname
http://lxr.linux.no/source/include/linux/utsname.h?v=1.0.9#L33
system_utsname

and here comes anther question:

  1. Function: long int gethostid (void)

  2. This function returns the Internet address of the machine the program is running on.

  3. Function: int sethostid (long int id)

  4. The sethostid function sets the address of the host machine to id. Only privileged processes are allowed to do this. Usually it happens just once, at system boot time.

  5. The return value is 0 on success and -1 on failure. The following errno error condition is defined for this function:
复制代码

I found these in GNU C Library document .
you know these functions? does we need to set the IP address at start time? Is there two correspond system functions the above two funcs call on? If it is ,why I can not found them?If not , so when and how we will use them?


thanks again!

论坛徽章:
0
10 [报告]
发表于 2005-09-08 10:30 |只看该作者

When The System Get The Hostname

http://www.linuxforum.net/books/LinuxFAQ/common-sys-v-init.html

according this document, when booting, the init process will read /etc/inittab first, then it found script for system initialization
si::sysinit:/etc/rc.d/rc/rc.sysinit
(This maybe varies from distribution of linux)

when rc.sysinit be executing, it gets HOSTNAME from /etc/sysconfig/network (if not set in the file, use localhost) and uses following scripts to set the hostname

  1. update_boot_stage RChostname
  2. action $"Setting hostname ${HOSTNAME}: " hostname ${HOSTNAME}
复制代码


and I think the command 'hostname' save the value in /proc/sys/kernel/hostname


  1. # hostname
  2. foo
  3. # cat /proc/sys/kernel/hostname
  4. foo
  5. # hostname foobar
  6. # cat /proc/sys/kernel/hostname
  7. foobar
  8. # echo "bar" >; /proc/sys/kernel/hostname
  9. # hostname
  10. bar
复制代码


but after you reboot, the server's hostname is still the original one    "foo" because we didn't modify /etc/sysconfig/network.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP