Hostname in Google Cloud Compute Debian/Ubuntu instance

Discussion in 'Installation/Configuration' started by adamjedgar, Sep 30, 2017.

  1. adamjedgar

    adamjedgar Member

    hi guys,

    I have added my question to this forum as its not ISPConfig specific as such. I have been running around in circles with this for weeks asking question after question and getting confused as to why answers i am getting are not really working in the way it seems they should. Now i think i may have narrowed down my problem. I had believed that a recent comment to simply leave everything as google cloud setup on first install would be best, however, i am concerned that in doing this my mail servers are not going to be resolving properly (I am having problems iwth reverse dns ( only one of the 3 instances below is using the mail server service with at the moment)

    I have been playing around with 3 google cloud compute instances using webmin/virtualmin (web hosting and email), Vestacp (hosting only), and ISPconfig (hosting only) control panels.

    The ISPConfig instance has a static external ip address, however the other 2 at this stage are dhcp.

    All 3 instances are using a dynamically assigned internal ip addresses, although i have not yet seen any of those ip addresses change in 6 months of testing and restarting and deleting and re-deploying. Whenever i delete an instance, the same internal ip sequence is used (ie whatever is the next lowest unassigned available number is re-added as internal ip address).

    I am having some problems with forcing google cloud to bloodywell stop changing my hostname -f configuration in my /etc/hosts file.

    It should read localhost.localdomain localhost
    ::1 localhost ip6-localhost ip6-loopback
    ff02::1 ip6-allnodes
    ff02::2 ip6-allrouters

    10.x.x.x server1
    # server1 # Added by Google
    # # Added by Google

    (where x is my ip address, "foo" is my domain name, and "bar" is my google cloud project ID)

    However, on any 3 of my instances, as soon as i reboot the instance, the comment i add to the first and second "#added by Google" lines above are removed by google cloud. If i delete the lines all together, google cloud adds them back in again on next restart. ie by default google cloud keeps changing the file to read the same 2 "# added by Google" lines as shown below localhost.localdomain localhost
    ::1 localhost ip6-localhost ip6-loopback
    ff02::1 ip6-allnodes
    ff02::2 ip6-allrouters

    10.x.x.x server1 server1 # Added by Google # Added by Google

    (where x is my ip address, "foo" is my actual domain name, and "bar" is my google cloud project ID)

    This is really causing me problems and i have no idea on which is the best way around it.

    -Do i do it from within google cloud DNS API?
    -setup a static internal ip address in google cloud network settings?
    -setup a script that continues to check for a change to this file and immediately replace any changes google cloud attempts to make?
    -or do i need to change the metadata information on the last line of my hosts file so it does not have " # Added by Google" line?

    At present option 1 above is not working. As soon as i enable the DNS API then try to enter it i get a "failed to load" error from within my google cloud console. This is a flaming pain in the ass!!! (i have sent a support request to google...who knows how long it will take for an answer)
    Last edited: Sep 30, 2017
    gilson likes this.
  2. adamjedgar

    adamjedgar Member

    I habe my solution...comment out first 'Added by Google line'
    Then save hosts file...

    Then from command sudo chattr +i /etc/hosts.

    google doesnt appear to be changing hosts file anymore and replacing what i have added with its defaults.

    A word of warning for google cloud users, do not remove or comment out the google added metadata line...doing this will block your google cloud compute dashboard ssh access. If you have a control panel with command shell you can use this to correct this.
    Last edited: Oct 3, 2017
  3. FlashPaperGrind

    FlashPaperGrind New Member

    Yup, been there too... I settled for doing the extra legwork by using
     hostnamectl set-hostname myhostname 
    - use it in a script that runs as root at startup.
  4. gilson

    gilson Member

    ISPConfig 3 Hostname Change, try try change in /etc/hosts and /etc/hostname, even deleting, it goes back again to: srv # Added by Google # Added by Google

    I want run the command and stay that way hostname -f and not like

    Can you help me? Thank
  5. Taleman

    Taleman Well-Known Member HowtoForge Supporter

    You keep hijacking threads and posting the same question.
  6. gilson

    gilson Member

    Taleman, sorry, Yes, because nobody even helped me, simple as that, you can help me? thank
  7. Taleman

    Taleman Well-Known Member HowtoForge Supporter

    I help you, but you continue ignoring my questions
    Anyway, the threads you already found explain the problem well and offer at least two ways to solve it. Do you not read the articles at all?
  8. gilson

    gilson Member

    Hi my dear Taleman, do not ignored it, only I already did what you teach, but does not work... what should I do to hostname -f stay that way and not so

    Very thank!
  9. adamjedgar

    adamjedgar Member

    Hi Gilson,
    the reason that your command above doesnt work is because the vps provider has setup their network instances such that it automatically changes back to the line you dont want.

    to prevent this you can do the following after you have changed the hostname in the hosts file as i stated earlier in the thread. You can prevent the system from automatically changing the file back again by locking the file immediately after saving it. The command below does this...

    " sudo chattr +i /etc/hosts. "

    Just remember, that if you ever need to edit hosts file later on, you need to reverse the above command otherwise you cannot edit the file because it is locked.

    kind regards

    P.S I have had others tell me that you dont actually need to worry about doing any of this as the default hostname <> is also fine and will work too. It just means you have to remember to input the default instead of your own in cpanel etc.
    ahrasis and gilson like this.
  10. gilson

    gilson Member

    @adamjedgar very thank by responding... already tried and does not work, the reason why I want to change the hostname, it's because I want to install SSL in main and only works if you are as well and not I already ran this command "sudo chattr + i / etc / hosts." but has not changed my hostname...
  11. ahrasis

    ahrasis Well-Known Member

    Try to understand what are being advised to you before saying any or all advises are not working. If you cannot understand the any given advises, no one can help you, so try hard to understand them.

    For instance the above "sudo chattr +i /etc/hosts" command is to fix that file so it will not changed by the system, not to change the hostname itself. You will have to edit the hosts file using nano or similar command before running the suggested chattr command.
    gilson likes this.
  12. gilson

    gilson Member

    Very thank @ahrasis I run the command (sudo chattr +i /etc/hosts) before and now I can not change my file etc/hosts... how to undo? thank
  13. ahrasis

    ahrasis Well-Known Member

    Google is your friend. Try "chattr -i /etc/hosts" to undo, then "nano /etc/hosts" to edit and finally "chattr +i /etc/hosts" to lock it back.
    gilson likes this.
  14. gilson

    gilson Member

    very thanks @ahrasis, see, also into of GCP - custom metadata I'm going to restart VPS and see if it will work, if not give up, I tried everything... still continue very very complicated
  15. ahrasis

    ahrasis Well-Known Member

    Good luck.
    gilson likes this.
  16. gilson

    gilson Member

    Not work again my friend @ahrasis, but thank by try help...
    ahrasis likes this.
  17. ahrasis

    ahrasis Well-Known Member

    Sorry to hear that. You could try other vps like Hertzner.
    gilson likes this.
  18. gilson

    gilson Member

    Thank you for trying to help. I have not paid anything to google cloud, so I don't want to change...
  19. Taleman

    Taleman Well-Known Member HowtoForge Supporter

    Does it matter what lines google ads to /etc/hosts? If you set /etc/hostname to painel, and put painel
    line to /etc/hosts things should be the way you want.
    Even if google changes the hosts file, it is only the hosts file. You can set mail name to something else entirely, same for other services. If all else fails, use the hostname google forces and set up services to use the hostname you want.
    Or does google change also /etc/hostname?
  20. gilson

    gilson Member

    @Taleman I already did all this, but as I said, persists in the back again... not understand this you said:
    "You can set mail name to something else entirely, same for other services. If all else fails, use the hostname google forces and set up services to use the hostname you want."

Share This Page