Host name does not include name (or domain name not set)

I’ve run one form or anothe of Linux for over 10 years and openSUSE for a large part of this. I recently upgraded one of my home PCs from openSUSE 13.2 to leap 42.2 - eventually by running a new install onto a newly formatted system disk, keeping my data didks unchanged. (Don’t laugh at how old the system was - when I get this one sprted, I’ve got a 12.3 system to rebuild as well). These are all home computers, which should not be visible to the internet.

My local mail system uses postfix and I’m trying to use a minimal configuration for the new system to forward nearly all mail to the old box (this has worked well under the old systems for some time) by using postfix’s built-in defaults for myhostname & mydomain. Now it fails.

BTW This problem doesn’t look to me like one jusrt form postfix …

According to postfix documentation, $myhostname defaults to "use the fully-qualified domain name (FQDN) from gethostname(), or to use the non-FQDN result from gethostname() and append “.$mydomain”.

Similarly, $mydomain default is to use $myhostname minus the first component, or “localdomain” (Postfix 2.3 and later). OK, so postfix is now at 2.11.8, so i may not be able to use this default any longer :-(. But it started me playing …

I wrote the following:

#define _GNU_SOURCE 1

#include <stdio.h>
#include <unistd.h>

main(int argc, char *argv])
{
char buffer[64];
int i;

i = gethostname(buffer, sizeof(buffer));    
printf("The host name is %s (%d)

", buffer, i);

i = getdomainname(buffer, sizeof(buffer));    
printf("The domain name is %s (%d)

", buffer, i);
return 0;
}

My /etc/hostname contains “pc2015.greymoon.com” (without the quotes!).

This program outputs:

richard@pc2015:/mnt/md0/richard-home-2015/tmp> ./hostname
The host name is pc2015 (0)
The domain name is (none) (0)
richard@pc2015:/mnt/md0/richard-home-2015/tmp>

Now, reading the man page fro gethostname, it could mean gethostname() returns the unqualified host name. However, getdomainname() should return the domain name, but returns that strintg “(null)” (or is it a null pointer?).

So … how should I be setting the domain name at all? I understood that /etc/hostname should do it, and can’t find anywhere else. I can see the hostname appear in the log (journal), but without the domain.

I remain confused …

Apologies if this is a bit long, but I’m trying to put as much information in as I can.

Richard “greymoon”

This might not help much, since I don’t use “postfix” (I use “sendmail”).

My shell prompt includes the hostname.

On systems where I use “wicked”, the shell prompt is just the plain name.
On systems where I use “NetworkManager”, the shell prompt is the fully qualified name.

So maybe you can “solve” your problem by switching to “NetworkManager”.

That said, I mostly prefer to use “wicked”. The “domainname” command returns “(none)” and the “hostname” command returns the unqualified name. But sendmail manages to work it out anyway. That mainly because it does a hostname lookup of the unqualified name, and finds a fully qualified name among the aliases. I manage that with an entry in “/etc/hosts”, though it would probably work anyway because my home router provides some sort of DNS emulation (using what the router takes to be the domainname).

My understanding is that the “domainname” command is supposed to return the NIS domain (or YP domain). Since I am not using NIS/YP, the “(none)” is arguably correct for that. The NIS domain name need not be related to the internet domain name.

Instead of relying on your script, have you tried just returning the value of your variables using echo?

eg

echo $myhostname
echo $mydomain

Of course, for this to work at some time those variables have to be set, and that might not be the case until a script somewhere has run.
But, once that script has run, the values should be set and you can verify those using “echo.”
In the same way, if you know what script should be setting the values, you can modify to print the values to stdout.

TSU