Get the App
SLTechnology News&Howtos  ›  Development  › 

How to configure hostname for linux

Shulou Source: shulou.com Published: 2022-06-02 09:39:44 09月10日 Update

This article mainly shows you "how to configure host name in linux", which is easy to understand and clear. I hope it can help you solve your doubts. Let me lead you to study and learn this article "how to configure host name in linux".

1. Configure Linux hostname

Let's configure two centos7 virtual machines with hostnames of client and server with host IP addresses of 192.168.30.8 and 192.168.30.9, respectively.

Configure client host [root@client ~] # vi / etc/sysconfig/network

Add the following and save:

# Created by anacondaNETWORKING=yeshostname=client restart the network: [root@client ~] # systemctl restart network [root@client ~] # hostnameclient [root@client ~] #

If it does not work, you can use the following command:

[root@client ~] # hostnamectl set-hostname client configure server host [root@server ~] # hostnamectl set-hostname server

Restart the network:

[root@server] # systemctl restart network [root@server] # hostnameserver [root@server] # uname-nserver2. Configure hostname and IP Mappin

Configure hosts files for client and server

Vi / etc/hosts

Add the following:

192.168.30.8 client192.168.30.9 server3. test

Use ping hostname to test whether the configuration is successful:

Client ping server:

Time 2001msrtt min/avg/max/mdev = 0.384max 0.522max 0.616max 0.099ms [root@client] #

Server ping client:

[root@Server] # ping client-c 3PING client (192.168.30.8) 56 (84) bytes of data.64 bytes from client (192.168.30.8): icmp_seq=1 ttl=64 time=0.502 ms64 bytes from client (192.168.30.8): icmp_seq=2 ttl=64 time=0.678 ms64 bytes from client (192.168.30.8): icmp_seq=3 ttl=64 time=0.323 ms--- client ping statistics-3 packets transmitted, 3 received, 0 packet loss Time 2003msrtt min/avg/max/mdev = 0.323 / 0.501 / 0.678 / 0.144 ms [root@Server ~] #

After configuring the hostname and IP mapping, you can directly ping the hostname instead of the ping IP address.

4. Configure windows hosts

Configure windows hosts so that it can be accessed through the hostname under windows.

Edit the C:\ Windows\ System32\ drivers\ etc\ hosts file and add the following:

192.168.30.8 client192.168.30.9 server

Save

5. Windows Test C:\ Users\ 10287 > ping client-n 3 is Ping client [192.168.30.8] with 32 bytes of data: reply from 192.168.30.8: bytes = 32 time

Tags: Configuration host content byte time article test address data file network learning help longest success no information unit command easy to understand Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information vpn Linux MySQL Docker