Unable to resolve hostname for Redhat Linux server

5,557

If you are trying to reach the system by hostname from another system, it will not work. You will need to either set up a DNS server on your network and add these entries, or manually add the hostname to the hosts file of the remote system you are using.

Share:
5,557

Related videos on Youtube

L P
Author by

L P

Software Tester

Updated on September 18, 2022

Comments

  • L P
    L P over 1 year

    I've setup a Linux Red Hat server and would like to use it by referring to its hostname instead of the static IP.

    eg. ssh [email protected], instead of ssh [email protected]

    but I get a message:

    ssh: Could not resolve hostname myhostname Name or service not known.
    

    OR

    If I do a nslookup from a windows client I get this such that it can detect the IP but I see dhcp-IP instead of my set hostname:

    Server:  UnKnown
    Address:  1903:ad:8s10::fd
    Name:    dhcp-xx-xxx-xx-xxx.blah.di.blah
    Address:  xx.xxx.xx.xxx
    

    As per several other stackoverflow posts, I set the hostname in:

    /etc/sysconfig/network-scripts/ifcfg-eth0

    as

    DHCP_HOSTNAME=myhostname.blah.di.blah

    I made the changes and did a dhclient -r followed by dhclient eth0 but no luck.

    Also, my /etc/hosts file looks like this:

    127.0.0.1  localhost localhost.localdomain
    xx.xxx.xx.xxx myhostname.blah.di.blah
    
    • Matej Vrzala M4
      Matej Vrzala M4 over 8 years
      Did you add the hostname to your /etc/hosts file?
    • L P
      L P over 8 years
      Yes, I had: 127.0.0.1 localhost localhost.localdomain xx.xxx.xx.xxx myhostname.blah.di.blah.. updated description to include this.
    • Matej Vrzala M4
      Matej Vrzala M4 over 8 years
      Ok.. what happens when you ping the domain?
    • L P
      L P over 8 years
      When I ping IP - I get the correct response, pinging domain returns ping: unknown host myhostname.blah.di.blah
    • Matej Vrzala M4
      Matej Vrzala M4 over 8 years
      Ok one last thing you can try is changing your ~/.ssh/config file to associate the IP address with the host.. This is definitely a DNS problem...
    • L P
      L P over 8 years
      It doesn't work either. I'm not sure where is the "dhcp-xx-xxx-xx-xxx" bit coming from, it just needs to be populated with 'myhostname'. Don't know which config. needs to be updated to achieve this.