Jump to content
Slate Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate Marble
Slate Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate Marble
NukeNick

Αλλαγή hostname σε LinuxBased λειτουργικό

Recommended Posts

How to change the hostname of your VPS

Many times the default or first-choice hostname of your VPS doesn’t please you any more. Changing the hostname is easy if you have ssh access, by following these steps:
  1. Edit your server’s /etc/sysconfig/network file with your preferred text editor (in this case, nano).
    [root@vps ~]# nano /etc/sysconfig/network

    Find the line containing “HOSTNAME=” and add your FQDN hostname.

    HOSTNAME=mynode.domain.com

     

  2. If you utilize internal networking, also change the host associated with the main IP address of your VPS.
    [root@vps ~]# nano /etc/hosts
    127.0.0.1 localhost localhost.localdomain
    123.45.67.89  hostname.domain.com  hostname
    ~
    ~
    -- INSERT -- 2,43-57 ALL

     

  3. Run “hostname” commad, followed by your preferred FQDN hostname:
  4. [root@vps ~]# hostname mynode.domain.com 
    [root@vps ~]# hostname
    mynode.domain.com
    [root@vps ~]#

     

    4. Don’t forget to also restart your network service, for the changes to persist on restart

    /etc/init.d/network restart

     

And that’s it! You now have a new hostname for your DS/VPS !

  • Like 1

Share this post


Link to post
Share on other sites

Με CentOs 7 OpenVZ containers είχα κάποιες φορές θέμα λόγω του /etc/hostname (άλλαζε upon reboot και έχανα το FQDN)

 

Εκεί μπορείς και να βάλεις στο crontab

 

@reboot hostname {your FQDN}

 

  • Like 2

Share this post


Link to post
Share on other sites

On a CentOS Linux 7 server you can use any one of the following tool to manage hostnames:

  1. hostnamectl command : Control the system hostname. This is recommended method.
  2. nmtui command : Control the system hostname using text user interface (TUI).
  3. nmcli command : Control the system hostname using CLI part of NetworkManager.

 

Types of hostnames

The hostname can be configured as follows

  1. Static host name assigned by sysadmin. For example, “server1”, “wwwbox2”, or “server1.mydomain.gr”.
  2. Transient/dynamic host name assigned by DHCP or mDNS server at run time.
  3. Pretty host name assigned by sysadmin/end-users and it is a free-form UTF8 host name for presentation to the user. For example, “My Laptop”.

Method #1: hostnamectl command

Let us see how to use the hostnamectl command.

How do I see the host names?

$ hostnamectl
## OR ##
$ hostnamectl status

Sample outputs:

   Static hostname: centos-7-rc
         Icon name: computer
           Chassis: n/a
        Machine ID: b5470b10ccfd49ed8e4a3b0e953a53c3
           Boot ID: f79de79e2dac4670bddfe528e826b61f
    Virtualization: oracle
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-229.1.2.el7.x86_64
      Architecture: x86_64

How do I set the host name?

The syntax is:

# hostnamectl set-hostname Your-New-Host-Name-Here
# hostnamectl set-hostname "Your New Host Name Here" --pretty
# hostnamectl set-hostname Your-New-Host-Name-Here --static
# hostnamectl set-hostname Your-New-Host-Name-Here --transient

To set host name to “R2-D2”, enter:

# hostnamectl set-hostname R2-D2

To set static host name to “server1.mydomain.gr”, enter:

# hostnamectl set-hostname server1.mydomain.gr --static

To set pretty host name to “My Server”, enter:

# hostnamectl set-hostname "My Server" --pretty

To verify new settings, enter:

# hostnamectl status

Sample outputs:

   Static hostname: server1.mydomain.gr
   Pretty hostname: My Server
Transient hostname: r2-d2
         Icon name: computer
           Chassis: n/a
        Machine ID: b5470b10ccfd49ed8e4a3b0e953a53c3
           Boot ID: f79de79e2dac4670bddfe528e826b61f
    Virtualization: oracle
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-229.1.2.el7.x86_64
      Architecture: x86_64

How do I delete a particular host name?

The syntax is:

# hostnamectl set-hostname ""
# hostnamectl set-hostname "" --static
# hostnamectl set-hostname "" --pretty

How do I change host name remotely?

Use any one of the following syntax:

# ssh root@server-ip-here hostnamectl set-hostname server1

Method #2: nmtui command

You can set host name using nmtui command which has text user interface for new users:

# nmtui

Sample outputs:

3YxpF1Bq.jpg

Fig.01: Use nmtui to set hostname on a CentOS 7

 

Use the Down arrow key > select the “Set system hostname” menu option > Press the “Ok” button:

qJwp0hpB.jpg

Fig.02: Set hostname

 

You will see the confirmation box as follows:

QmtGW1i0.jpg

Finally, restart hostnamed service by typing the following command

# systemctl restart systemd-hostnamed

To verify changes, enter:

# hostnamectl status

Method #3: nmcli command

 

The nmcli is a command line tool for controlling NetworkManager and reporting network status.

To view the host name using nmcli command:

The syntax is:

# nmcli general hostname

To set the host name using nmcli command:

The syntax is:

# nmcli general hostname R2-D2
# nmcli general hostname server1.mydomain.gr

Finally, restart the systemd-hostnamed service:

# systemctl restart systemd-hostnamed
  • Like 2

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×