When I run ypdomainname somedomain, it clearly takes effect, because ypdomainname will show the state changed, before and after. I need to deploy this change via configuration management, and can't find an ansible module to do it, so the solution will likely be to use lineinfile or something similar to deploy the change; only problem is: I can't find what files on the filesystem it changes. What files does it change?

The man page mentions /etc/hostname and /etc/hosts but these remain unchanged, so I think the man page is inaccurate or incomplete.

When I create a filesystem snapshot before and after, I find no differences in /etc or any other changes that I think seem relevant. Perhaps I'm missing something...

When I run strace ypdomainname somedomain, it shows that it does not access any files; it calls the setdomainname() function from libc. This is documented here: http://man7.org/linux/man-pages/man2/setdomainname.2.html which unfortunately seems to offer no information about what it actually does.


The first hint is that strace doesn't actually show libc functions – it shows kernel syscalls. (They only happen to have similar names.) For historical reasons, the YP/NIS domain name is stored by the kernel (alongside the hostname), and although the NIS client software runs in userspace, it always gets the domain name from kernel.

So the 'ypdomainname' command indeed does not access any files – its purpose is not to make permanent changes, but rather to upload the domain name from /etc to the transient kernel memory, and it uses a dedicated kernel syscall to make that happen.

Permanent storage for the domain name is indeed a file in /etc, but you have to change it using a regular text editor and then run 'ypdomainname' to upload that change to the currently running kernel (which is also done on every reboot). Different distributions store the YP/NIS domain name in different locations; /etc/domainname is one option, but it might also be in /etc/sysconfig or /etc/defaults.

But fortunately for you, the kernel also exposes the YP/NIS domain name as an ordinary sysctl – kernel.domainname – which you can set through the virtual /proc/sys/kernel/domainname path for the running system, as well as through /etc/sysctl.d to make the change permanent, in a distro-independent manner. Ansible even appears to have a dedicated sysctl module for making such changes:

- sysctl:
    name: "kernel.domainname"
    value: "example"
    sysctl_set: yes
| improve this answer | |
  • Thanks, you nailed it. :-) Add this: For RHEL/Centos 6, 7, and 8 (and probably older versions), echo "NISDOMAIN=whatever" >> /etc/sysconfig/network and I'll accept the answer. – Edward Ned Harvey May 1 at 23:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.