stop rewriting /etc/hosts

penguin_brian

New Member
Dec 9, 2010
14
0
1
linuxpenguins.xyz
Hello,

How do I stop Proxmox from rewriting my /etc/hosts on OpenVZ VMs?

Maybe I am old fashioned, but I very much dislike aliasing the fqdn to 127.0.0.1 - if I want the localhost interface I will type in localhost! I find it rather confusing when it gives me different results depending on what box I am typing it in on. Also setting localhost==fqdn==127.0.0.1 seems to break some applications.

Furthermore my DNS server works just fine for resolving the fqdn and even returns IPv6 addresses.

So how do I tell proxmox to leave it alone? I just want:

127.0.0.1 localhost.localdomain localhost

plain and simple.

I have tried doing Google searches on this issue, however this hasn't helped yet.

Thanks.
 
Proxmox uses OpenVZ - We do not plan to change how it works.

So are you saying this is a something that I need to configure with OpenVZ? Or is it a limitation of OpenVZ that cannot be configured?

Worst case I guess I could always automatically rewrite it when the VM boots, however this would seem silly...

When Linux Containers is supports will this fix this problem?

Thanks
 
You could make the /etc/hosts file immutable so it cannot be changed.

I have no idea how this would affect the initialization scripts though.

You could also create your own distribution script, then remove the section that adds the unwanted into to /etc/hosts.
 
So are you saying this is a something that I need to configure with OpenVZ? Or is it a limitation of OpenVZ that cannot be configured?

OpenVZ creates correct /etc/hosts files here:

Code:
...
127.0.0.1 localhost.localdomain localhost
# Auto-generated hostname. Please do not remove this comment.
192.168.3.103 deb6.proxmox.com  deb6
What is wrong with that?
 
I also would like hosts stay in a sane way, I've re-done some tests with proxmox 1.7 just in case things were better than last time I checked.
If I create a openvz, debian5 based (hostname zzz, domain name mydomain.it), BRIDGED network veth (vmbr0) and NEVER start it, the hosts is:
# cat /var/lib/vz/private/115/etc/hosts
127.0.0.1 localhost.localdomain localhost

::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
proxmox:~#

then if I start it and enter and watch again I find:
# vzctl enter 115
entered into CT 115
zzz:/# cat /etc/hosts

::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
# Auto-generated hostname. Please do not remove this comment.
127.0.0.1 zzz.mydomain.it localhost zzz localhost.localdomain

This auto generate line, for instance, confused mysql installation in Zimbra, and needs to be fixed before install.
Maybe you tested with different networking type.
Thanks a lot
 
OpenVZ creates correct /etc/hosts files here:

Code:
...
127.0.0.1 localhost.localdomain localhost
# Auto-generated hostname. Please do not remove this comment.
192.168.3.103 deb6.proxmox.com  deb6
What is wrong with that?

While not ideal (I don't like to have duplicated information - it increases the chance of errors if I ever have to change IP addresses) - I would be happy with that.

The trouble is I am not getting that, instead I get:

Code:
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
# Auto-generated hostname. Please do not remove this comment.
127.0.0.1 webby.pri localhost localhost.localdomain  webby

I am speculating this is because I am using the bridge config, not the venet config.

On the other hand, all the IPv6 entries are just fine. The problem only exists for IPv4.

So I type in a command like "telnet -4 webby.pri port" expecting to test if port is listening to external connections only it uses localhost instead. Which I consider is wrong.

I think I have found out a way to stop it rewriting the /etc/hosts, just need to test it...

Brian May
 
I think I have found out a way to stop it rewriting the /etc/hosts, just need to test it...

Ok, so it looks like whenever you start the VM, openvz uses the name of the template file to locate the config file under /etc/vz/dists (see http://wiki.openvz.org/Configuring_container_creation). On my system I would assume this is default.conf as there isn't a debian-6.0.conf file. This file has:

Code:
ADD_IP=debian-add_ip.sh
DEL_IP=debian-del_ip.sh
SET_HOSTNAME=debian-set_hostname.sh
SET_DNS=set_dns.sh
SET_USERPASS=set_userpass.sh
SET_UGID_QUOTA=set_ugid_quota.sh
POST_CREATE=postcreate.sh

This reference scripts under /etc/vz/dists/scripts. The important one is not debian-add_ip.sh as I first suspected (this only creates the /etc/hosts if it doesn't exist), but debian-set_hostname.sh.

This script has a call to change_hostname:

Code:
change_hostname /etc/hosts "${HOSTNM}" "${IP_ADDR}"

This function is defined in /etc/vz/dists/scripts/functions. It is rather complicated looking with a mixture of shell and awk.

If I insert the line at the top of the change_hostname function "return 0" then I think rewriting /etc/hosts is disabled.

So far I have tested it by changing the hostname in the proxmox interface. Before I made this change, /etc/hosts would get rewritten every time. After the change it remains static.

At least the theory sounds good to me, the acid test will be after a reboot a VM.

Also note, this is obviously going to affect all VMs.

Brian May
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!