Set a host name alias in /etc/hosts?

23,720

Is there anyway to set a host to url? E.g. something like the following in /etc/hosts

That is not a URL. Its a hostname. The point of the /etc/hosts file is that it provides and alternative to DNS for resolving hostnames to addresses.

The files nameservice (the bit of code that sits between your application and the /etc/hosts file) does not support this.

If you have your own nameserver then you could setup a CNAME record pointing the name puppet to example,com

Alternatively you could write a script to capture the DNS address of example.com and append it to a template to create the hosts file (at boot up or at intervals).

Or just fix your certificates.

Share:
23,720

Related videos on Youtube

Philip Kirkbride
Author by

Philip Kirkbride

Updated on September 18, 2022

Comments

  • Philip Kirkbride
    Philip Kirkbride over 1 year

    I'm having an issue relating to host names and SSL signing. The certificate signing process works fine if my host name is puppet. With the IP of the puppet master server being set in /etc/hosts.

    I don't want to use the IP as it will likely change and I'll have to update /etc/hosts again.

    Instead I point directly to the url but this causes additional issues relating to inconsistency in certificate names.

    Is there anyway to set a host to url? E.g. something like the following in /etc/hosts:

    example.com puppet
    
    • Kusalananda
      Kusalananda almost 7 years
      That's not an URL. The format of that file should be ip-address hostname alias(es).
    • Pankaj Goyal
      Pankaj Goyal almost 7 years
      No, /etc/hosts is used specifically to assign an IP address to a given set of hostnames.
    • Satō Katsura
      Satō Katsura almost 7 years
      Just use DNS instead.
    • Philip Kirkbride
      Philip Kirkbride almost 7 years
      @SatoKatsura can I do this to associate local host name puppet with a url?
    • Satō Katsura
      Satō Katsura almost 7 years
      Not until you understand what DNS does.
    • Philip Kirkbride
      Philip Kirkbride almost 7 years
      @SatoKatsura I know that DNS servers are used to associate public website names with IP addresses. I take it from your comment that if I do more reading on DNS and linux I can over-ride public DNS locally to forward hostname puppet to a url. Unsure because comment is a bit vague.
    • Satō Katsura
      Satō Katsura almost 7 years
      You need to understand the details of how certificates work (that's a long, very technical read), then you need to read about DNS views. How exactly you can do what you want depends a lot on your exact setup. Which is to say you should probably ask on a puppet forum.
    • ivanivan
      ivanivan almost 7 years
      When you reference puppet do you really want to connect to puppet.example.com ? if so, just setting a search domain option to example.com in /etc/resolv.conf should do that for you (if it can't find puppet via hosts or dns it tries puppet.example.com)