LXC container hostname problems


New Member
Feb 21, 2017

So I have an LXC container running Ubuntu 16.04. I created a script that changes the default hostname (LXC-Ubuntu) to a randomly generated series of letters and numbers.

Running a command through /etc/rc.local each time I reboot the system, the hostname is changed using this script:


rhex=`cat /dev/urandom | tr -cd 'a-f0-9' | head -c 8`

if [ "$1" = "" ]; then
  hostname $nh
  echo -n "The hostname is now $nh"

echo "This script will configure the host with the following settings:"
echo Hostname: $nh

echo /etc/hostname:
echo $nh

echo /etc/hosts:
cat /var/tmp/newhosts | sed -e "s/nh/$nh/g"

echo $nh > /etc/hostname
cat /var/tmp/newhosts | sed -e "s/nh/$nh/g" > /etc/hosts

"newhosts" file:
Code:    localhost    nh

The changes seems to take effect after rebooting, however after another reboot to verify they are permanent my changes are lost and it resets /etc/hosts and /etc/hostname back to the original hostname.

I have tested this on a separate VM I have to success, so I have came to the conclusion that it may be caused by ProxMox itself. The LXC container in my VE has a hostname of LXC-Ubuntu as well and I believe this may be overwriting my script changes.

Is there any way to resolve this issue?

Any help is appreciated
  • Like
Reactions: damaged_menu


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 your own in 60 seconds.

Buy now!