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

    127.0.0.1 localhost.localdomain localhost
    ::1 localhost ip6-localhost ip6-loopback
    ff02::1 ip6-allnodes
    ff02::2 ip6-allrouters

    10.x.x.x server1.foo.com.au server1
    #10.152.0.3 server1.c.bar.internal server1 # Added by Google
    #169.254.169.254 metadata.google.internal # 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

    127.0.0.1 localhost.localdomain localhost
    ::1 localhost ip6-localhost ip6-loopback
    ff02::1 ip6-allnodes
    ff02::2 ip6-allrouters

    10.x.x.x server1.foo.com.au server1
    10.152.0.3 server1.c.bar.internal server1 # Added by Google
    169.254.169.254 metadata.google.internal # 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 "...metadata.google.internal # 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
    Code:
     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:

    10.142.0.2 srv.us-east1-b.c.drarebecagomes-221302.internal srv # Added by Google
    169.254.169.254 metadata.google.internal # Added by Google


    I want run the command and stay that way hostname -f painel.drarebecagomes.com and not like
    srv.us-east1-b.c.drarebecagomes-221302.internal

    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 painel.drarebecagomes.com and not so srv.us-east1-b.c.drarebecagomes-221302.internal

    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
    Adam

    P.S I have had others tell me that you dont actually need to worry about doing any of this as the default hostname <srv.us-east-1-b.c.drarebecagomes-221302.internal> is also fine and will work too. It just means you have to remember to input the default instead of your own host.domain.com 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 panel.drarebecagomes.com:8080 and only works if you are as well painel.drarebecagomes.com and not srv.us-east-1-b.c.drarebecagomes-221302.internal I already ran this command "sudo chattr + i / etc / hosts." but has not changed my hostname...
     
  11. ahrasis

    ahrasis Well-Known Member HowtoForge Supporter

    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 HowtoForge Supporter

    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 http://prntscr.com/lnlfyo, also into of GCP http://prntscr.com/lnlu08 - custom metadata I'm going to restart VPS and see if it will work, if not give up, I tried everything... still continue srv.us-east-1-b.c.drarebecagomes-221302.internal very very complicated
     
  15. ahrasis

    ahrasis Well-Known Member HowtoForge Supporter

    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 HowtoForge Supporter

    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
    199.199.199.123 painel.drarebecagomes.com 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