另外:修改hosts文件 立即生效 linux ubuntu windows
大概原因是:应该是dnscache服务cache了dns查询结果。
方法一:命令行(cmd)运行:ipconfig /flushdns #清除DNS缓存内容。
ps:ipconfig /displaydns //显示DNS缓存内容
DnsCacheTimeout 0x0 (REG_DWORD)
ServerInfoTimeOut 0x0 (REG_DWORD) 这三个DWORD。
如果是使用Firefox浏览器,强烈推荐DNS Flusher插件,换了hosts绑定后,只需要使用一下这个插件,就会使HOST绑定立即生效;非常好用的!~
另外,在Linux下修改/etc/hosts,若想要它立刻生效,运行source /etc/hosts应该就可以了(这涉及到source命令的功能,下次再总结一下吧)[me补充:应该是立即生效的]
修改hostname
Normally we will set the hostname of a system during the installation process. Many peoples don’t care about this, and don’t change the hostname even if for example this was set to something really stupid by the datacenter that installed the system (most likely they will set this to “debian” on any debian installation, etc). For me, it is important to see on each one of the ssh screens I will have open at any time a different hostname that is relevant and will give me quickly the information on what system I am logged in.
Change the hostname on a running system
On any Linux system you can change its hostname with the command ‘hostname ‘ (surprised?)… Here are some quick usages of the command line hostname:
hostname
without any parameter it will output the current hostname of the system.
hostname --fqd
it will output the fully qualified domain name (or FQDN) of the system.
will set the hostname of the system to NEW_NAME. This is active right away and will remain like that until the system will be rebooted (because at system boot it will set this from some particular file configurations – see bellow how to set this permanently). You will most probably need to exit the current shell in order to see the change in your shell prompt.
Permanent hostname change on Debian based systems
Debian based systems use the file /etc/hostname to read the hostname of the system at boot time and set it up using the init script /etc/init.d/hostname.sh
/etc/hostname
输出:june-desktop
So on a Debian based system we can edit the file /etc/hostname and change the name of the system and then run:
/etc/init.d/hostname.sh start
to make the change active. The hostname saved in this file (/etc/hostname) will be preserved on system reboot (and will be set using the same script we used hostname.sh).
Permanent hostname change on RedHat based systems
RedHat based system use the file /etc/sysconfig/network to read the saved hostname at system boot. This is set using the init script /etc/rc.d/rc.sysinit
/etc/sysconfig/network
NETWORKING=yes
HOSTNAME="plain.domainname.com"
GATEWAY="192.168.0.1"
GATEWAYDEV="eth0"
FORWARD_IPV4="yes"
So in order to preserve your change on system reboot edit this file and enter the appropriate name using the HOSTNAME variable.
Use sysctl to change the hostname
Why would someone need a different method of doing the same thing as above? No idea, but here is anyway: use sysctl to change the variable kernel.hostname :
Use:
sysctl kernel.hostname
to read the current hostname, and
sysctl kernel.hostname=NEW_HOSTNAME
to change it.
//
参考一:
参考二:
linux下修改主机名
修改主机名:
1./etc/sysconfig/network
内容:
NETWORKING=yes
HOSTNAME=lh //主机名(没有这行?那就添加这一行吧)
GATEWAY=192.168.1.1
2.运行命令:
#hostname lh
//lh为主机名
3./etc/hosts
内容:
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost localhost.localdomain localhost
把第二localhost写为lh,即:
127.0.0.1 lh localhost.localdomain localhost
但是步骤3不是必须的。如果这三个步骤都做了,无论是否重起,
主机名都将修改成功
在Linux 系统中,默认的主机名是loalhost,如果想修改自己的主机名,可以使用命令:hostname xxx。不过如果你正在使用X Window窗口,用这个命令修改了主机名之后就打不开xterm了。所以,彻底一点的办法是直接修改/etc/network文件:HOSTNAME= xxx,然后重启计算机,主机名已经被修改了。
使用DHCP的系统就不能用上述方法了,因为启动network时主机名会被改成DHCP服务器提供的名称。怎么办呢?既然主机名被粗暴的修改了,那咱们也粗暴的改回来:编辑/etc/rc,在最后加上一行hostname xxx,重启系统就OK了。。