Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Debian 12, setting hostname does not persist

350 views
Skip to first unread message

David Mehler

unread,
Jun 27, 2023, 6:50:08 AM6/27/23
to
Hello,

I've got a VPS through a2hosting it was running Debian 11 specifically
11.7. Long story short I just had to reinstall it after a hard week of
work so instead of doing it all over again on 11.7 I decided to
upgrade to 12.0. I used this:

https://www.makeuseof.com/upgrade-to-debian-12-bookworm-from-debian-11/

the upgrade itself went just fine. I set my time zone that stuck and
is persisting then went for the hostname, I am doing this via ssh, in
setting the hostname it won't persist through a reboot.

In the below output I've x-d out items like the device chasis ID and
the IP I've made it a 192.168.x.x address even tthough the actual
address is public.

The one thing I see and I don't know if this is related is when I
change the hostname with set-hostname hostnamectl -f and -i gives an
error.

#hostname
server.example.com

#hostname -f
server.example.com

#hostname -i
192.168.23.195

#hostname -s
server

#cat /etc/hostname
server.example.com

#cat /etc/hosts
127.0.0.1 localhost
# Auto-generated hostname. Please do not remove this comment.
192.168.23.195 server.example.com server

#hostnamectl set-hostname bookworm

#hostname
bookworm

#hostname -f
hostname: Name or service not known

#hostname -s
bookworm

#hostname -i
hostname: Name or service not known

#cat /etc/hosts
127.0.0.1 localhost
# Auto-generated hostname. Please do not remove this comment.
192.168.23.195 server.example.com server

#perl -i -p -e 's/server/bookworm/g;' /etc/hosts

#cat /etc/hosts
127.0.0.1 localhost
# Auto-generated hostname. Please do not remove this comment.
192.168.23.195 bookworm.example.com bookworm

#cat /etc/hostname
bookworm

#reboot

#cat /etc/hosts
127.0.0.1 localhost
# Auto-generated hostname. Please do not remove this comment.
192.168.23.195 server.example.com server

#cat /etc/hostname
server.example.com

#hostname
server.example.com

#hostname -f
server.example.com

#hostname -s
server

#hostname -i
192.168.23.195

I've googled and not seen this as a problem, I am quite perplexed.
Suggestions welcome.
Thanks.
Dave.

Reco

unread,
Jun 27, 2023, 7:40:06 AM6/27/23
to
Hi.

On Tue, Jun 27, 2023 at 06:48:52AM -0400, David Mehler wrote:
> the upgrade itself went just fine. I set my time zone that stuck and
> is persisting then went for the hostname, I am doing this via ssh, in
> setting the hostname it won't persist through a reboot.

One of the possible reasons for this is "cloud-init".
Purge the package, or set "preserve_hostname: true" in
/etc/cloud/cloud.cfg.

Another one could be DHCP client. "nooption host_name" in dhcpcd.conf
should fix the issue.

Reco

David Mehler

unread,
Jun 27, 2023, 8:10:07 AM6/27/23
to
Hello,

Thank you for your reply. To your first option I do not have the
cloud-init package installed. I don't know if this matters but
hostnamectl reports that the virtualization is openvz. To your second
option I don't have a dhcpcd.conf file, though I did look for anything
dhcp on the system, here are those packages:

ii isc-dhcp-client 4.4.3-P1-2
amd64 DHCP client for automatically obtaining an IP address
ii isc-dhcp-common 4.4.3-P1-2
amd64 common manpages relevant to all of the isc-dhcp
packages
ii wide-dhcpv6-client 20080615-23
amd64 DHCPv6 client for automatic IPv6 hosts configuration

You might be on to something though here's what is in
/etc/dhcp/dhclient.conf I'm just not sure what options to comment out?

/etc/dhcp#grep -v "#" dhclient.conf

option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;

send host-name = gethostname();
request subnet-mask, broadcast-address, time-offset, routers,
domain-name, domain-name-servers, domain-search, host-name,
dhcp6.name-servers, dhcp6.domain-search, dhcp6.fqdn, dhcp6.sntp-servers,
netbios-name-servers, netbios-scope, interface-mtu,
rfc3442-classless-static-routes, ntp-servers;

Thanks.
Dave.

Reco

unread,
Jun 27, 2023, 8:30:06 AM6/27/23
to
Hi.

On Tue, Jun 27, 2023 at 08:06:17AM -0400, David Mehler wrote:
> You might be on to something though here's what is in
> /etc/dhcp/dhclient.conf I'm just not sure what options to comment out?

That's even easier. Instead of

send host-name = gethostname();
request subnet-mask, broadcast-address, time-offset, routers,
domain-name, domain-name-servers, domain-search, host-name,
dhcp6.name-servers, dhcp6.domain-search, dhcp6.fqdn, dhcp6.sntp-servers,

you should probably use:

send host-name = gethostname();
request subnet-mask, broadcast-address, time-offset, routers,
domain-name, domain-name-servers, domain-search,
dhcp6.name-servers, dhcp6.domain-search, dhcp6.fqdn, dhcp6.sntp-servers,

If it does not help - consider adding:

supersede host-name "<your hostname here>";

Reco

gene heskett

unread,
Jun 27, 2023, 9:00:07 AM6/27/23
to
I ran into a similar problem setting up some bananapi-m5's running
armbian as klipper interfaces to 3d printers. That hostname must exist
in the /etc/hosts file before it quits resetting the hostname to the
install default. It might be an armbian problem, but it does IMO rate a
check. So edit the hosts file first.
> .

Cheers, Gene Heskett.
--
"There are four boxes to be used in defense of liberty:
soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author, 1940)
If we desire respect for the law, we must first make the law respectable.
- Louis D. Brandeis
Genes Web page <http://geneslinuxbox.net:6309/>

David Mehler

unread,
Jun 27, 2023, 11:00:07 AM6/27/23
to
Hello,

Thanks for the suggestion, I tried them both and didn't work. Then I
decided to do what I probably should have checked a few hours ago
before the frustration really hit, and that is /etc/network/interfaces
and /etc/dhcp/dhclient.conf is from what I can tell not even being
used because the interface(s) are all getting there IP addresses
statically assigned.

Thanks.
Dave.

Reco

unread,
Jun 27, 2023, 11:30:06 AM6/27/23
to
Hi.

On Tue, Jun 27, 2023 at 10:54:32AM -0400, David Mehler wrote:
> used because the interface(s) are all getting there IP addresses
> statically assigned.

New plan then.

apt install auditd
echo '-a always,exit -F arch=b64 -S sethostname' \
> /etc/audit/rules.d/hostname.rules
echo '-a always,exit -F path=/proc/sys/kernel/hostname -F perm=wa' \
>> /etc/audit/rules.d/hostname.rules
service auditd restart
reboot

Whatever's trying to change the hostname should leave a trace in
/var/log/audit/audit.log.


PS Here it's customary to reply at the bottom of e-mail, not at the top.
There's no need to quote the mail you're replying to in full.

Reco

David Mehler

unread,
Jun 27, 2023, 8:40:06 PM6/27/23
to
Hello,

Thanks for your reply.

Auditd is giving me a weird error that google has shown is more common
than it should be. If the answer to this next question is what I'm
thinking it is, that very likely means a kernel issue.

The question is this, what kernel version (I believe it is 6.x?) comes
with Debian 12? The reason I ask is because of this:


#uname -a
Linux hostname.example.com 4.19.0 #1 SMP Thu Dec 15 20:31:06 MSK 2022
x86_64 GNU/Linux

#uname -r
4.19.0

#hostnamectl
Static hostname: hostname.example.com
Icon name: computer-container
Chassis: container ?
Machine ID: xxx
Boot ID: xxx
Virtualization: openvz
Operating System: Debian GNU/Linux 12 (bookworm)
Kernel: Linux 4.19.0
Architecture: x86-64

I don't think that is correct.
Thanks.
Dave.


On 6/27/23, Reco <recov...@enotuniq.net> wrote:

Greg Wooledge

unread,
Jun 27, 2023, 8:50:07 PM6/27/23
to
On Tue, Jun 27, 2023 at 08:33:21PM -0400, David Mehler wrote:
> The question is this, what kernel version (I believe it is 6.x?) comes
> with Debian 12? The reason I ask is because of this:
>
>
> #uname -a
> Linux hostname.example.com 4.19.0 #1 SMP Thu Dec 15 20:31:06 MSK 2022
> x86_64 GNU/Linux

> I don't think that is correct.

You said you were on an OpenVZ hosted VPS, right? That means you're
using the host's kernel, which is generally not going to be the same
as what you would have on a non-virtual Debian 12 system.

This is what a physical Debian 12 system currently uses:

unicorn:~$ uname -a
Linux unicorn 6.1.0-9-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.27-1 (2023-05-08) x86_64 GNU/Linux

David Mehler

unread,
Jun 27, 2023, 10:00:06 PM6/27/23
to
"You said you were on an OpenVZ hosted VPS, right?  That means you're
using the host's kernel, which is generally not going to be the same
as what you would have on a non-virtual Debian 12 system."

So, is that my problem?

Thanks.
Dave.
0 new messages