Linux hostname hostname to view and set

Queries host name:

  uname -n

  hostname

[root@oldboy ~]# uname -n
oldboy
[root@oldboy ~]# hostname
oldboy

 

Linux operating system kernel hostname is a variable , you can view the machine's hostname by the hostname command. Can also directly cat / proc / sys / kernel / hostname view.

[root@oldboy ~]# hostname 
oldboy
[root@oldboy ~]# cat /proc/sys/kernel/hostname
oldboy

The above two kinds of the same output.

  

hostname modify Linux runtime system, ie without rebooting

hostname command can set the hostname of the system, to take effect immediately after the operation, but after a system restart will lose your changes, if you want to permanently change the hostname of the system, it is necessary to modify the relevant settings file.

 

Set the host name:

Temporary effect:

    • hostname set the hostname and display
      • The default display is the host name
      • Set the host name: hostname hostname

Permanent:

  • vim / etc / sysconfig / network; modified hostname to the desired value; save and exit.
    • /etc/sysconfig/network
  • vim / etc / hosts; hostname i.e. modifying or adding a host name corresponding to an IP address. Save and exit.
    • /etc/hosts
  • service network restart; network restart.

 

 

 

 

  

Guess you like

Origin www.cnblogs.com/zoe233/p/11819374.html