LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 834|回复: 6

无论怎么改,我的主机名还是改不了???求救!

[复制链接]
发表于 2005-8-11 22:23:37 | 显示全部楼层 |阅读模式
我用的Redhat9.0和rhel as 3.0
我修改了/etc/hosts,/etc/sysconfig/network,/etc/sysconfig/network-script/ifcfg-eth0
都不管用我的主机名还是dhcp-xx-xx什么的,具体什么记不太清楚了
求哪位大虾指点迷津
发表于 2005-8-11 22:55:04 | 显示全部楼层
echo 'coolcomputer' > /etc/hostname
回复 支持 反对

使用道具 举报

发表于 2005-8-11 23:04:36 | 显示全部楼层
man hostname
如果没有hostname这个程序,就装上.
回复 支持 反对

使用道具 举报

发表于 2005-8-12 00:35:34 | 显示全部楼层
看看下面这一页, 对您有没有用?

http://www.cpqlinux.com/hostname.html



Checking your Linux host name
First, see if your host name is set correclty using the following commands:

uname -n
hostname -a
hostname -s
hostname -d
hostname -f
hostname

If the above commands return correctly with no errors then all may be well; however, you may want to read on to verify that all settings are correct.

Configuring /etc/hosts
If your IP address is assigned to you by a DHCP server, then /etc/hosts is configured as follows:

127.0.0.1        mybox.mydomain.com        localhost.localdomain localhost mybox

If you have a static IP address, then /etc/hosts is configured as follows:

127.0.0.1        localhost.localdomain localhost
192.168.0.10        mybox.mydomain.com        mybox

Setting the Host Name using "hostname"
After updating the /etc/hosts file correctly, the "hostname" command should be run as follows to set your hostname:

hostname mybox.mydomain.com

Checking /etc/HOSTNAME (if present)
You may or may not have the file /etc/HOSTNAME:

mybox.mydomain.com

Checking /etc/sysconfig/network
If you have a static IP address, then /etc/sysconfig/network is configured as follows:

NETWORKING=yes
HOSTNAME="mybox.mydomain.com"
...

If your IP address is assigned to you by a DHCP server, and you wish to update the local DNS server through Dynamic DNS, then /etc/sysconfig/network is configured as follows:

NETWORKING=yes
HOSTNAME="mybox.mydomain.com"
DHCP_HOSTNAME="mybox.mydomain.com"
...

It makes more sense to move this "DHCP_HOSTNAME" variable into /etc/sysconfig/network-scripts/ifcfg-eth0 (or appropriate NIC cfg file). So the above section has been moved, see below. If you have only 1 NIC, then the above struck section works fine, but with more than 1 NIC it makes no sense. Maybe this is true for the "'HOSTNAME" line too, maybe that line should be moved into /etc/sysconfig/network-scripts/ifcfg-eth0 as well. I will investigate further. By default RHL places HOSTNAME=localhost.localdomain in /etc/sysconfig/network.
Checking /proc/sys/kernel/hostname
This is checked with the following command:

cat /proc/sys/kernel/hostname

If you need to set this file, you can either reboot or set it now with the following command:

echo mybox.mydomain.com > /proc/sys/kernel/hostname

Dynamic DNS - Updating the local DNS server with your host name and DHCP IP
For Red Hat Linux if you receive your IP address from a DHCP server, you may update the local DNS server by adding the following line to the correct ifcfg file in /etc/sysconfig/network-scripts, such as ifcfg-eth0 or ifcfg-eth1:

DHCP_HOSTNAME="mybox.mydomain.com"

or if running Debian, edit /etc/network/interfaces as follows (adding the hostname line):

iface eth0 inet dhcp
    hostname mybox.mydomain.com

Updated information about ddns:
Kill the dhclient process ("killall dhclient") - make sure it is gone
Then restart networking - "service network restart"

Updated information for ddns on Gentoo:
killall dhclient
Edit /etc/conf.d/net
uncomment and modify the line as follows:
dhcpcd_eth0="-h yourhostname"
reboot or restart your network subsystem

Thanks to Jack for the Gentoo information!

For more info in Debian, see "man interfaces" and scroll down to"The dhcp Method".
WINS - Updating the local WINS server with your host name and IP
If you wish to update the local WINS server, then use SAMBA, and configure it to point to the local WINS server. samba.html i.e. update the /etc/samba/smb.conf "wins server = " entry with the WINS server addresses for your network - be sure not to enable "wins support = yes" as that will make Linux a WINS server.
Changing the hostname while in X-Windows
Changing the hostname while in X-Windows can be problematic. Most often, new windows cannot be opened. Either
1. change the hostname while the X-Windows is not running or
2. in X-Windows change the hostname, then restart X-Windows.
回复 支持 反对

使用道具 举报

发表于 2005-8-12 16:16:01 | 显示全部楼层
我原来也遇见过你这种情况.
我改的方法是在hosts里面是这样改的.
127.0.0.1       localhost.localdomain   localhost
192.168.0.5     hostname
之后我在 /etc/sysconfig/network里面是
NETWORKING=yes
HOSTNAME=hostname
我在 vi /etc/sysconfig/network-scripts/ifcfg-eth0里面是
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=none
IPADDR=192.168.0.5
NETMASK=255.255.255.0
TYPE=Ethernet
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-8-12 22:23:31 | 显示全部楼层
多谢各位的鼎力相助,但是好像还是不行。以下是我的配置文件。我的目的是想主机名为localhost

/etc/hosts
127.0.0.1       localhost.localdomain          localhost
/etc/sysconfig/network
NETWORKING=yes
HOSTNAME=localhost.localdomain
/etc/sysconfig/network-script/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=dhcp
TYPE=Ethernet

如果象Guanka1兄所说的作修改,是不是就变成固定IP了,那不是不能上网了码?
还有我觉得应该和/etc/resolve.conf中的search关键字有关系
/etc/resolve.conf
search localdomain
nameserver         202.96.209.133

希望哪位高手能指点,很急
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-8-12 23:09:44 | 显示全部楼层
I have solved the problem.
Just as what n00b quoted,I added DHCP_HOSTNAME=localhost into /etc/sysconfig/network-script/ifcfg-eth0,and then all set.
I am really a little fuzzy though.Does it mean if I use dhcp,the system will get the hostname from dhcp server?
I hope some masters can help me,likewise I hope my answer can help other people who love linux?
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表