Set hostname using cloudinit for dhcp server: Systemd overrides cloudinit hostnameHow to register hostname via DHCP?registering hostname using DHCPHow does my DHCP server know my machine's hostname when I didn't define one in dhclient.conf?DHCP/DNS hostname changesHow to set environment variable in systemd service?Correctly setting the hostname - Fedora 20 on Amazon EC2Motorola SB6141 assigns 192.168.100.0/24 IP via DHCP when cable dies; can I prohibit systemd-networkd from using 192.168.100.0/24 addresses?systemd Using 4GB RAM After 18 Days of UptimeSSH unavailable system bootinglibvirt: set hostname using dhcp in virtual network
Is adding a new player (or players) a DM decision, or a group decision?
How would modern naval warfare have to have developed differently for battleships to still be relevant in the 21st century?
Are all instances of trolls turning to stone ultimately references back to Tolkien?
What is the legal status of travelling with methadone in your carry-on?
Why doesn't a marching band have strings?
Fedora boot screen shows both Fedora logo and Lenovo logo. Why and How?
How do I turn off a repeating trade?
Is a single radon-daughter atom in air a solid?
Vanishing of certain coefficients coming from Coxeter groups
Why do some games show lights shine thorugh walls?
Why did pressing the joystick button spit out keypresses?
Require advice on power conservation for backpacking trip
Inverse-quotes-quine
Archery in modern conflicts
Long term BTC investing
Why aren't cotton tents more popular?
Is it damaging to turn off a small fridge for two days every week?
Iterate MapThread with matrices
Going to get married soon, should I do it on Dec 31 or Jan 1?
First-year PhD giving a talk among well-established researchers in the field
Suggested order for Amazon Prime Doctor Who series
How to split an equation in two lines?
Is my Rep in Stack-Exchange Form?
Capacitors in series INTUITION
Set hostname using cloudinit for dhcp server: Systemd overrides cloudinit hostname
How to register hostname via DHCP?registering hostname using DHCPHow does my DHCP server know my machine's hostname when I didn't define one in dhclient.conf?DHCP/DNS hostname changesHow to set environment variable in systemd service?Correctly setting the hostname - Fedora 20 on Amazon EC2Motorola SB6141 assigns 192.168.100.0/24 IP via DHCP when cable dies; can I prohibit systemd-networkd from using 192.168.100.0/24 addresses?systemd Using 4GB RAM After 18 Days of UptimeSSH unavailable system bootinglibvirt: set hostname using dhcp in virtual network
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
For a testing environment, I want to connect multiple VMs using DHCP with their hostnames as DNS entrys. The troubleshooting shows that my DNS/DHCP works. But the VM got registered using ubuntu
as hostname instead of my own (k8sm
in this example):
root@k8sm:~# ping k8sm -c1
PING k8sm (192.168.2.89) 56(84) bytes of data.
64 bytes from ubuntu.k8s.home (192.168.2.89): icmp_seq=1 ttl=64 time=0.019 ms
Using my k8sm
hostname, I didn't get an IP when trying dig +short k8sm.k8s.home @192.168.2.2
(where .2.2 is my DNS server).
Cloudinit user-data
hostname: $hostname
fqdn: $hostname.k8s.home
Which is called from my Terraform config file here:
data "template_file" "k8sm-cloudinit-data"
template = "$file("$path.module/cloudinit/user-data.cfg")"
vars =
hostname = "k8sm"
According to the logs
root@k8sm:~# grep hostname /var/log/syslog
Jun 6 19:17:09 k8sm systemd-resolved[604]: Using system hostname 'ubuntu'.
Jun 6 19:17:09 k8sm systemd-networkd[581]: Not connected to system bus, not setting hostname.
Jun 6 19:17:09 k8sm systemd-resolved[604]: System hostname changed to 'k8sm'.
Jun 6 19:17:09 k8sm kernel: [ 3.526063] systemd[1]: Set hostname to <ubuntu>.
Jun 6 19:17:09 k8sm dbus-daemon[781]: [system] Activating via systemd: service name='org.freedesktop.hostname1' unit='dbus-org.freedesktop.hostname1.service' requested by ':1.0' (uid=100 pid=581 comm="/lib/systemd/systemd-networkd " label="unconfined")
Jun 6 19:17:09 k8sm dbus-daemon[781]: [system] Successfully activated service 'org.freedesktop.hostname1'
Jun 6 19:17:09 k8sm systemd-hostnamed[844]: Changed host name to 'ubuntu'
it seems that my k8sm
hostname is applyed, but got overriden by systemd. Why is this happen and what need to be done to set the hostname correctly for DHCP? The target is to reach the machine using k8sm.k8s.home
in this example.
hostnamectl
shows me the correct hostname in the VM
root@k8sm:~# hostnamectl status
Static hostname: k8sm.k8s.home
Icon name: computer-vm
Chassis: vm
Machine ID: 001637a6a5e0410f923cb082af1953d2
Boot ID: 853577fa58844d8e900c107cfb0c1dde
Virtualization: kvm
Operating System: Ubuntu 18.04.2 LTS
Kernel: Linux 4.15.0-50-generic
Architecture: x86-64
Both host and VM runs 18.04 LTS with KVM 2.11.1.
Another approach I tried
preserve_hostname: true
runcmd:
- hostnamectl set-hostname k8sm
- hostnamectl set-hostname k8sm --static
The idea was to skip cloudinits hostname setting with preserve_hostname
and set it manually (later), but the result is the same: VM got registered as ubuntu
instead of its new hostname.
ubuntu domain-name-system dhcp systemd cloud-init
add a comment |
For a testing environment, I want to connect multiple VMs using DHCP with their hostnames as DNS entrys. The troubleshooting shows that my DNS/DHCP works. But the VM got registered using ubuntu
as hostname instead of my own (k8sm
in this example):
root@k8sm:~# ping k8sm -c1
PING k8sm (192.168.2.89) 56(84) bytes of data.
64 bytes from ubuntu.k8s.home (192.168.2.89): icmp_seq=1 ttl=64 time=0.019 ms
Using my k8sm
hostname, I didn't get an IP when trying dig +short k8sm.k8s.home @192.168.2.2
(where .2.2 is my DNS server).
Cloudinit user-data
hostname: $hostname
fqdn: $hostname.k8s.home
Which is called from my Terraform config file here:
data "template_file" "k8sm-cloudinit-data"
template = "$file("$path.module/cloudinit/user-data.cfg")"
vars =
hostname = "k8sm"
According to the logs
root@k8sm:~# grep hostname /var/log/syslog
Jun 6 19:17:09 k8sm systemd-resolved[604]: Using system hostname 'ubuntu'.
Jun 6 19:17:09 k8sm systemd-networkd[581]: Not connected to system bus, not setting hostname.
Jun 6 19:17:09 k8sm systemd-resolved[604]: System hostname changed to 'k8sm'.
Jun 6 19:17:09 k8sm kernel: [ 3.526063] systemd[1]: Set hostname to <ubuntu>.
Jun 6 19:17:09 k8sm dbus-daemon[781]: [system] Activating via systemd: service name='org.freedesktop.hostname1' unit='dbus-org.freedesktop.hostname1.service' requested by ':1.0' (uid=100 pid=581 comm="/lib/systemd/systemd-networkd " label="unconfined")
Jun 6 19:17:09 k8sm dbus-daemon[781]: [system] Successfully activated service 'org.freedesktop.hostname1'
Jun 6 19:17:09 k8sm systemd-hostnamed[844]: Changed host name to 'ubuntu'
it seems that my k8sm
hostname is applyed, but got overriden by systemd. Why is this happen and what need to be done to set the hostname correctly for DHCP? The target is to reach the machine using k8sm.k8s.home
in this example.
hostnamectl
shows me the correct hostname in the VM
root@k8sm:~# hostnamectl status
Static hostname: k8sm.k8s.home
Icon name: computer-vm
Chassis: vm
Machine ID: 001637a6a5e0410f923cb082af1953d2
Boot ID: 853577fa58844d8e900c107cfb0c1dde
Virtualization: kvm
Operating System: Ubuntu 18.04.2 LTS
Kernel: Linux 4.15.0-50-generic
Architecture: x86-64
Both host and VM runs 18.04 LTS with KVM 2.11.1.
Another approach I tried
preserve_hostname: true
runcmd:
- hostnamectl set-hostname k8sm
- hostnamectl set-hostname k8sm --static
The idea was to skip cloudinits hostname setting with preserve_hostname
and set it manually (later), but the result is the same: VM got registered as ubuntu
instead of its new hostname.
ubuntu domain-name-system dhcp systemd cloud-init
add a comment |
For a testing environment, I want to connect multiple VMs using DHCP with their hostnames as DNS entrys. The troubleshooting shows that my DNS/DHCP works. But the VM got registered using ubuntu
as hostname instead of my own (k8sm
in this example):
root@k8sm:~# ping k8sm -c1
PING k8sm (192.168.2.89) 56(84) bytes of data.
64 bytes from ubuntu.k8s.home (192.168.2.89): icmp_seq=1 ttl=64 time=0.019 ms
Using my k8sm
hostname, I didn't get an IP when trying dig +short k8sm.k8s.home @192.168.2.2
(where .2.2 is my DNS server).
Cloudinit user-data
hostname: $hostname
fqdn: $hostname.k8s.home
Which is called from my Terraform config file here:
data "template_file" "k8sm-cloudinit-data"
template = "$file("$path.module/cloudinit/user-data.cfg")"
vars =
hostname = "k8sm"
According to the logs
root@k8sm:~# grep hostname /var/log/syslog
Jun 6 19:17:09 k8sm systemd-resolved[604]: Using system hostname 'ubuntu'.
Jun 6 19:17:09 k8sm systemd-networkd[581]: Not connected to system bus, not setting hostname.
Jun 6 19:17:09 k8sm systemd-resolved[604]: System hostname changed to 'k8sm'.
Jun 6 19:17:09 k8sm kernel: [ 3.526063] systemd[1]: Set hostname to <ubuntu>.
Jun 6 19:17:09 k8sm dbus-daemon[781]: [system] Activating via systemd: service name='org.freedesktop.hostname1' unit='dbus-org.freedesktop.hostname1.service' requested by ':1.0' (uid=100 pid=581 comm="/lib/systemd/systemd-networkd " label="unconfined")
Jun 6 19:17:09 k8sm dbus-daemon[781]: [system] Successfully activated service 'org.freedesktop.hostname1'
Jun 6 19:17:09 k8sm systemd-hostnamed[844]: Changed host name to 'ubuntu'
it seems that my k8sm
hostname is applyed, but got overriden by systemd. Why is this happen and what need to be done to set the hostname correctly for DHCP? The target is to reach the machine using k8sm.k8s.home
in this example.
hostnamectl
shows me the correct hostname in the VM
root@k8sm:~# hostnamectl status
Static hostname: k8sm.k8s.home
Icon name: computer-vm
Chassis: vm
Machine ID: 001637a6a5e0410f923cb082af1953d2
Boot ID: 853577fa58844d8e900c107cfb0c1dde
Virtualization: kvm
Operating System: Ubuntu 18.04.2 LTS
Kernel: Linux 4.15.0-50-generic
Architecture: x86-64
Both host and VM runs 18.04 LTS with KVM 2.11.1.
Another approach I tried
preserve_hostname: true
runcmd:
- hostnamectl set-hostname k8sm
- hostnamectl set-hostname k8sm --static
The idea was to skip cloudinits hostname setting with preserve_hostname
and set it manually (later), but the result is the same: VM got registered as ubuntu
instead of its new hostname.
ubuntu domain-name-system dhcp systemd cloud-init
For a testing environment, I want to connect multiple VMs using DHCP with their hostnames as DNS entrys. The troubleshooting shows that my DNS/DHCP works. But the VM got registered using ubuntu
as hostname instead of my own (k8sm
in this example):
root@k8sm:~# ping k8sm -c1
PING k8sm (192.168.2.89) 56(84) bytes of data.
64 bytes from ubuntu.k8s.home (192.168.2.89): icmp_seq=1 ttl=64 time=0.019 ms
Using my k8sm
hostname, I didn't get an IP when trying dig +short k8sm.k8s.home @192.168.2.2
(where .2.2 is my DNS server).
Cloudinit user-data
hostname: $hostname
fqdn: $hostname.k8s.home
Which is called from my Terraform config file here:
data "template_file" "k8sm-cloudinit-data"
template = "$file("$path.module/cloudinit/user-data.cfg")"
vars =
hostname = "k8sm"
According to the logs
root@k8sm:~# grep hostname /var/log/syslog
Jun 6 19:17:09 k8sm systemd-resolved[604]: Using system hostname 'ubuntu'.
Jun 6 19:17:09 k8sm systemd-networkd[581]: Not connected to system bus, not setting hostname.
Jun 6 19:17:09 k8sm systemd-resolved[604]: System hostname changed to 'k8sm'.
Jun 6 19:17:09 k8sm kernel: [ 3.526063] systemd[1]: Set hostname to <ubuntu>.
Jun 6 19:17:09 k8sm dbus-daemon[781]: [system] Activating via systemd: service name='org.freedesktop.hostname1' unit='dbus-org.freedesktop.hostname1.service' requested by ':1.0' (uid=100 pid=581 comm="/lib/systemd/systemd-networkd " label="unconfined")
Jun 6 19:17:09 k8sm dbus-daemon[781]: [system] Successfully activated service 'org.freedesktop.hostname1'
Jun 6 19:17:09 k8sm systemd-hostnamed[844]: Changed host name to 'ubuntu'
it seems that my k8sm
hostname is applyed, but got overriden by systemd. Why is this happen and what need to be done to set the hostname correctly for DHCP? The target is to reach the machine using k8sm.k8s.home
in this example.
hostnamectl
shows me the correct hostname in the VM
root@k8sm:~# hostnamectl status
Static hostname: k8sm.k8s.home
Icon name: computer-vm
Chassis: vm
Machine ID: 001637a6a5e0410f923cb082af1953d2
Boot ID: 853577fa58844d8e900c107cfb0c1dde
Virtualization: kvm
Operating System: Ubuntu 18.04.2 LTS
Kernel: Linux 4.15.0-50-generic
Architecture: x86-64
Both host and VM runs 18.04 LTS with KVM 2.11.1.
Another approach I tried
preserve_hostname: true
runcmd:
- hostnamectl set-hostname k8sm
- hostnamectl set-hostname k8sm --static
The idea was to skip cloudinits hostname setting with preserve_hostname
and set it manually (later), but the result is the same: VM got registered as ubuntu
instead of its new hostname.
ubuntu domain-name-system dhcp systemd cloud-init
ubuntu domain-name-system dhcp systemd cloud-init
edited Jun 6 at 20:37
Lion
asked Jun 6 at 19:49
LionLion
2584 silver badges15 bronze badges
2584 silver badges15 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
After some headaches, I realized that the problem got fixed by rebooting the VM:
power_state:
delay: now
mode: reboot
message: Reboot to apply new hostname
timeout: 10
This is working, but conflicts with my Ansible provisioning executing after the machine is created. And it also delays everything. Furthermore, I want to understand why this behaviour occurs. Since the reboot works, I assumed a timing problem instead of systemd
: DHCP got the default ubuntu
hostname, before cloudinit could apply it. Then it won't get updated automatically. Maybe on the next lease, but I want an instant solution.
Found an article that explains how to force a release and this worked manually. So I replaced the reboot using power_state
above by those shell-commands:
runcmd:
- dhclient -r
- dhclient
Now DNS works as expected without having to reboot the entire machine:
root@k8sm:~# ping k8sm
PING k8sm.k8s.home (192.168.2.48) 56(84) bytes of data.
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "2"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f970449%2fset-hostname-using-cloudinit-for-dhcp-server-systemd-overrides-cloudinit-hostna%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
After some headaches, I realized that the problem got fixed by rebooting the VM:
power_state:
delay: now
mode: reboot
message: Reboot to apply new hostname
timeout: 10
This is working, but conflicts with my Ansible provisioning executing after the machine is created. And it also delays everything. Furthermore, I want to understand why this behaviour occurs. Since the reboot works, I assumed a timing problem instead of systemd
: DHCP got the default ubuntu
hostname, before cloudinit could apply it. Then it won't get updated automatically. Maybe on the next lease, but I want an instant solution.
Found an article that explains how to force a release and this worked manually. So I replaced the reboot using power_state
above by those shell-commands:
runcmd:
- dhclient -r
- dhclient
Now DNS works as expected without having to reboot the entire machine:
root@k8sm:~# ping k8sm
PING k8sm.k8s.home (192.168.2.48) 56(84) bytes of data.
add a comment |
After some headaches, I realized that the problem got fixed by rebooting the VM:
power_state:
delay: now
mode: reboot
message: Reboot to apply new hostname
timeout: 10
This is working, but conflicts with my Ansible provisioning executing after the machine is created. And it also delays everything. Furthermore, I want to understand why this behaviour occurs. Since the reboot works, I assumed a timing problem instead of systemd
: DHCP got the default ubuntu
hostname, before cloudinit could apply it. Then it won't get updated automatically. Maybe on the next lease, but I want an instant solution.
Found an article that explains how to force a release and this worked manually. So I replaced the reboot using power_state
above by those shell-commands:
runcmd:
- dhclient -r
- dhclient
Now DNS works as expected without having to reboot the entire machine:
root@k8sm:~# ping k8sm
PING k8sm.k8s.home (192.168.2.48) 56(84) bytes of data.
add a comment |
After some headaches, I realized that the problem got fixed by rebooting the VM:
power_state:
delay: now
mode: reboot
message: Reboot to apply new hostname
timeout: 10
This is working, but conflicts with my Ansible provisioning executing after the machine is created. And it also delays everything. Furthermore, I want to understand why this behaviour occurs. Since the reboot works, I assumed a timing problem instead of systemd
: DHCP got the default ubuntu
hostname, before cloudinit could apply it. Then it won't get updated automatically. Maybe on the next lease, but I want an instant solution.
Found an article that explains how to force a release and this worked manually. So I replaced the reboot using power_state
above by those shell-commands:
runcmd:
- dhclient -r
- dhclient
Now DNS works as expected without having to reboot the entire machine:
root@k8sm:~# ping k8sm
PING k8sm.k8s.home (192.168.2.48) 56(84) bytes of data.
After some headaches, I realized that the problem got fixed by rebooting the VM:
power_state:
delay: now
mode: reboot
message: Reboot to apply new hostname
timeout: 10
This is working, but conflicts with my Ansible provisioning executing after the machine is created. And it also delays everything. Furthermore, I want to understand why this behaviour occurs. Since the reboot works, I assumed a timing problem instead of systemd
: DHCP got the default ubuntu
hostname, before cloudinit could apply it. Then it won't get updated automatically. Maybe on the next lease, but I want an instant solution.
Found an article that explains how to force a release and this worked manually. So I replaced the reboot using power_state
above by those shell-commands:
runcmd:
- dhclient -r
- dhclient
Now DNS works as expected without having to reboot the entire machine:
root@k8sm:~# ping k8sm
PING k8sm.k8s.home (192.168.2.48) 56(84) bytes of data.
answered Jun 6 at 22:05
LionLion
2584 silver badges15 bronze badges
2584 silver badges15 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Server Fault!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f970449%2fset-hostname-using-cloudinit-for-dhcp-server-systemd-overrides-cloudinit-hostna%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown