Ping my server via name and not IP.

Issues related to configuring your network
Post Reply
hack3rcon
Posts: 757
Joined: 2014/11/24 11:04:37

Ping my server via name and not IP.

Post by hack3rcon » 2018/11/28 07:18:11

Hello
I'm using CentOS 7 x86_64 and I like to change my hostname and ping it in local network via its name and not IP. I used below command:

Code: Select all

$ hostnamectl 
   Static hostname: myserver
         Icon name: computer-server
           Chassis: server
        Machine ID: cf7fd176d7894138b9408e80946cf0d5
           Boot ID: f76da434640d43029548b3b70d676fd6
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-327.el7.x86_64
      Architecture: x86-64
But when I run "ping" command then it show me:

Code: Select all

$ ping myserver
ping: unknown host myserver
And my "hosts" file content is:

Code: Select all

$ cat /etc/hosts

127.0.0.1   myserver

Thank you.

hack3rcon
Posts: 757
Joined: 2014/11/24 11:04:37

Re: Ping my server via name and not IP.

Post by hack3rcon » 2018/11/29 09:03:26

Any idea?

User avatar
jlehtone
Posts: 4523
Joined: 2007/12/11 08:17:33
Location: Finland

Re: Ping my server via name and not IP.

Post by jlehtone » 2018/11/29 09:37:15

When you say "via name and not IP" it sounds like you don't want to be able to ping with IP. I don't think that is possible.

I think you actually want to ping with both IP and name.

When you give name to ping, ping attempts to resolve the name into IP (and then it does the actual ping with IP).

Name resolution has (almost) nothing to do with your machine. The question is, how the machine where you run "ping myserver" resolves the name. A primary method is to send a query to DNS (server). What your machine calls itself is not important, unless it can somehow register that name to DNS.


You have to configure the DNS of your local network to resolve "myserver" to desired IP.

Post Reply