`
fantaxy025025
  • 浏览: 1329736 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类

How to change the hostname of a Linux system

阅读更多

 

 

 

另外:修改hosts文件 立即生效 linux ubuntu windows

windows参考:

做 web开发和测试的,难免需要经常修改hosts来指定某个域名访问某个特定的IP;在windows中,每次修改了C:\windows \system32\drivers\etc\hosts,都需要重启浏览器才生效。今天我就这个问题就行了学习,下面介绍三种方法,当然不一定对每个人 都有效,可以尝试一下吧。
大概原因是:应该是dnscache服务cache了dns查询结果。
方法一:命令行(cmd)运行:ipconfig /flushdns     #清除DNS缓存内容。
ps:ipconfig /displaydns    //显示DNS缓存内容
方法二:修改注册表:HKeyCurrentUser\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings ,新建: DnsCacheEnabled  0x0 (REG_DWORD)
DnsCacheTimeout 0x0 (REG_DWORD)
ServerInfoTimeOut 0x0 (REG_DWORD) 这三个DWORD。
方法三:打开:控制面板 -管理工具– 服务, 在其中找到“DNS Client” 将其停用并改为手动模式(做了这个后,运行ipconfig /flushdns就没必要了,也运行不成功)

如果是使用Firefox浏览器,强烈推荐DNS Flusher插件,换了hosts绑定后,只需要使用一下这个插件,就会使HOST绑定立即生效;非常好用的!~

另外,在Linux下修改/etc/hosts,若想要它立刻生效,运行source /etc/hosts应该就可以了(这涉及到source命令的功能,下次再总结一下吧)[me补充:应该是立即生效的]

 

修改hostname

Linux 参考:

 

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.

 

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

http://hi.baidu.com/landnow/blog/item/a03c6989741aa2b30e244459.html

更改linux主机名
2007年01月29日 星期一 19:02

参考一:

在linux下修改主机名,只需修改/etc/sysconfig/network 文件就可以了 。
直接用hostname newname只能临时修改主机名,重启后就回到原来的主机名了。

参考二:

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了。。

 

 

 

 

分享到:
评论

相关推荐

    解决linux找不到hostname的处理

    This prevents creation of a GUID. Cause was: java: java: No address associated with hostname java.net.UnknownHostException: java: java: No address associated with hostname at java.net.InetAddress....

    Linux中hostname修改方法详解

    Linux操作系统的hostname是一个kernel变量,可以使用如下两种方式查看 # hostname 和 # cat /proc/sys/kernel/hostname 临时修改hostname 通过hostname命令可以设置系统的hostname # hostname newname new...

    rhce guide

    They should know how to verify the integrity of the installation media and how to troubleshoot common issues that may arise during the installation process. ### Conclusion The RHCE certification is ...

    drupal 6.12

    (modify the file system path of each installation to a different directory so that uploads do not overlap between installations); or, * your site runs a number of web server front-ends behind a ...

    Google C++ Style Guide(Google C++编程规范)高清PDF

    The definition of an inline function needs to be in a header file, so that the compiler has the definition available for inlining at the call sites. However, implementation code properly belongs in ....

    hands-network-programming-c-optimized.rar

    This book covers core concepts, such as hostname resolution with DNS, that are crucial to the functioning of the modern web. You’ll delve into the fundamental network protocols, TCP and UDP. ...

    TC版本控制器最新版本

    Installation Instructions ... If the server was installed on another machine, you will need to change the 'HostName' property in the Connection Properties dialog to point to the relevant machine.

    2009 达内Unix学习笔记

    [] 匹配中括号里的内容[a-z][A-Z][0-9]。 ! 事件。 $ 取环境变量的值。 | 管道。把前一命令的输出作为后一命令的输入,把几个命令连接起来。 |经常跟tee连用,tee 把内容保存到文档并显示出来。 三、通用后...

    深入理解Linux修改hostname(推荐)

    当我觉得对Linux系统下修改hostname已经非常熟悉的时候,今天碰到了几个个问题,这几个问题给我好好上了一课,很多知识点,当你觉得你已经掌握的时候,其实你了解的还只是皮毛。技术活,切勿浅尝则止! 实验环境:...

    MidtermExam_吴先_13000128171

    This path is defined by a sequence of virtual circuit identifiers (VCIDs) assigned to each link along the way. Each node on the network is aware of the VCID and uses it to forward packets along the ...

    linux-suse11修改主机名

    在Linux操作系统中,主机名是标识系统在网络中的唯一名称,对于SUSE Linux Enterprise Server (SLES) 11来说,修改主机名是一个重要的系统管理任务。这个过程涉及到多个步骤,通常包括配置网络接口、更新系统文件...

    Linux 常用命令(xls 文件)非常实用

    Linux 常用命令(xls ...• hostname -i Lookup local ip address (equivalent to host `hostname`) • netstat -tupl List internet services on a system • netstat -tup List active connections to/from system

    impala-2.8

    - **Describe the Impala Table**: Discover how to view the schema of a table. - **Query the Impala Table**: Execute complex queries and analyze the results. #### Advanced Tutorials - **Attaching an...

    VB编程资源大全(英文源码 网络)

    displays the number of new messages (as msn messenger display messages) and plays a WAV file<END><br>52 , urlhist.zip This sample demonstrates how to loop through the history folder of Internet ...

    TraceRoute

    callback messages, and events, I have illustrated how it is possible to avoid blocking in an application.These controls form a custom set of TCP/IP controls I have been developing over the past year....

    crtmpserver源码

    * Change the 127.0.0.1 to either the IP of your crtmpserver or simply use a hostname of your machine * Replace file-download with the actual filename of your sample you download. Remeber to omit the ....

    linux全志R16的linux系统编译的资料_20170502_1655.7z

    # configuration written to /home/wwt/linux_r16/lichee/out/sun8iw5p1/linux/common/buildroot/.config # make:离开目录“/home/wwt/linux_r16/lichee/buildroot” make:进入目录'/home/wwt/linux_r16/lichee/...

    How to get all the IP available in LAN using java

    System.out.println("Host Name: " + inetAddress.getHostName()); } ``` `isReachable()`方法可以用来检查设备是否在线,但请注意,它可能需要管理员权限才能正确工作。 5. **注意网络安全和性能**: 在实际...

Global site tag (gtag.js) - Google Analytics