LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   How to set the name of a computer for postfix / mail? (http://www.linuxquestions.org/questions/linux-software-2/how-to-set-the-name-of-a-computer-for-postfix-mail-4175429289/)

JZL240I-U 09-27-2012 06:34 AM

How to set the name of a computer for postfix / mail?
 
The smartmontools daemon (smartd) can send mails to e.g. root, if and when a warning or error for a hard disk occurred. One sets the mail address like "root@linux" in /etc/smartd.conf. When a real mail is sent, the mail agent appends "site" to the above denominator like so root@linux.site and the mail is duly sent and received.

How can I change "linux" to something more meaningful? I know that I set this up (possibly during installation), but I want to change it now.

<edit> It is not set from "/etc/HOSTNAME", remarcably... </edit>

And while we are at it: can I change "site" too?

tronayne 09-27-2012 08:07 AM

Take a look at man smartd.conf, particularly the -m and -M options for background and detailed information; I suspect, though, that you can simply edit the e-mail address(es) in /etc/smartd.conf then stop and restart the daemon:
Code:

su -
ps -ef | grep smartd          <to get the PID>
kill -HUP <PID of smartd>      <stop the daemon>

Then you can test your change by starting the daemon with the -M test option (which will send mail). Be sure to read the section on this in man smartd first.

Hope this helps some.

JZL240I-U 09-27-2012 08:27 AM

Quote:

Originally Posted by tronayne (Post 4790709)
Take a look at man smartd.conf, particularly the -m and -M options...

Did that already, but thanks anyhow.

Quote:

Originally Posted by tronayne (Post 4790709)
...I suspect, though, that you can simply edit the e-mail address(es) in /etc/smartd.conf then stop and restart the daemon....

No, you can't change an addressee arbitrarily. In real life you send your letter either toTom (root) in New York or in Boston and there is a difference. Postfix thinks my machine is called "linux.site" (New York). I want to change that denomination into "netbook" (Boston). I even tried it and get the error "Host or domain name not found. Name service error for name=netbook.site"

I suspect that this is hidden in some .conf file, like HOSTNAME is. That's what I am looking for, to rename my machine in the eyes of postfix.

<edit> In /etc/postfix/main.cf is a line like this: "myhostname = linux.site". Put there probably by the "SuSEconfig.postfix" program. Which is parameterized how? :rolleyes: </edit>

tronayne 09-27-2012 09:12 AM

Oh. Well, OK...

Just for grins, what does
Code:

uname -n
show you? It ought to be what's in /etc/HOSTNAME without the domain. Are you running fixed IP and, if so, what's in /etc/hosts; if not, what's embedded in your "inet1.conf" (do you have DHCP_HOSTNAME defined)?

This might seem like overkill but you more or less know that linux.site has got to be buried somewhere in some blasted file, so why not
Code:

su -
find / -type f | xargs grep -i 'linux.site' 2>/dev/null

Then, you know, go change 'em all to what you want and reboot the thing.

JZL240I-U 09-27-2012 09:37 AM

Code:

uname -n
shows
Code:

netbook
And that is exactly what is in /etc/HOSTNAME without the domain, right.


I am not running fixed IP. In /etc/hosts is
Code:

127.0.0.1.  localhost
192.168.1.69  my.desktop.PC  linux-jdoc
{some IPv6 statements}


DHCP_HOSTNAME is not defined as far as I can see. How to check it outside of YAST?
Code:

su -
find / -type f | xargs grep -i 'linux.site' 2>/dev/null

Is running now.

JZL240I-U 09-27-2012 09:40 AM

Code:

uname -n
shows
Code:

netbook
And that is exactly what is in /etc/HOSTNAME without the domain, right.


I am not running fixed IP. In /etc/hosts is
Code:

127.0.0.1.  localhost
192.168.1.69  my.desktop.PC  linux-jdoc
{some IPv6 statements}


DHCP_HOSTNAME is not defined as far as I can see. How to check it outside of YAST?
Code:

su -
find / -type f | xargs grep -i 'linux.site' 2>/dev/null

Is running now.

<edit> In /var/log/mail I found
Code:

Networkmanager: <info> Setting system hostname to 'linux.site' (from system configuration)
What is that telling us? --- Uups, I clicked on quote instead of edit </edit>

tronayne 09-27-2012 10:46 AM

Are you running KDE? Maybe take a look at the system configuration options? Probably need to be root when you do anything with it (I'm running Xfce but I can look at the KDE System Settings from it).

Other place to look is /etc/mail, maybe in local-host-names and helpfile.

Gotta be there someplace

catkin 09-27-2012 05:53 PM

One solution which I have used with both postfix and sendmail (but I think it is picked up by the mail-generating program, not the MTA) is to change root's line in /etc/paswd, setting the 5th field to root@<hostname> (where <hostname> is the hostname you want).

JZL240I-U 09-28-2012 01:44 AM

Quote:

Originally Posted by tronayne (Post 4790819)
Are you running KDE? Maybe take a look at the system configuration options?

I am and I did that, but didn't find anything. Probably looked at the wrong places.

Quote:

Originally Posted by tronayne (Post 4790819)
Other place to look is /etc/mail, maybe in local-host-names and helpfile.

/etc/mail and /local-hos-names don't exist in openSuSE :(.

Quote:

Originally Posted by tronayne (Post 4790819)
Gotta be there someplace

Indeed. That b@stard.

P.S.: I had to break off the systemwide search yesterday. It's just restarted (after I umounted all unnecessary partitions ;)). But
Code:

ps ax | grep find
results in
Code:

2361 pts/0  S+  0:00  find / -type f
Does that mean the job sleeps??? Or has it stopped (abnormally)? <edit> Spleeps. Lazy guy. When and how will it wake?</edit>

JZL240I-U 09-28-2012 01:54 AM

Quote:

Originally Posted by catkin (Post 4791074)
...change root's line in /etc/paswd, setting the 5th field to root@<hostname> (where <hostname> is the hostname you want).

Ummf. My root entry in /etc/passwd reads
Code:

root:x:0:0:root:/root:/bin/bash
Should that be
Code:

root:x:0:0:root@netbook:/root:/bin/bash
??? But where stems the current "linux" from?

tronayne 09-28-2012 06:49 AM

You should probably try to kill that find (if it's still running)
Code:

su -
ps -ef | grep find
kill -9 2361        <the PID of the running find>

Kinda looks like a zombie, maybe.

Trying to remember where the mail files used to be, I think in /var somewhere, maybe in /var/spool; if you've got sendmail those configuration files are someplace. Look for aliases, aliases.db, sendmail.cf; e.g.,
Code:

find /var -type f -name 'aliases*'

JZL240I-U 10-08-2012 11:33 AM

Been away for a week, back to work now ;).

I already killed the "find", no problem there.

"/etc/aliases" in SuSE systems holds mappings for users like lp: root or postgres: root. There are no machine names in there, I checked. There is also an aliases.db, with what would I open that? "sendmail*" does not exist, though. Any more ideas?

tronayne 10-08-2012 01:50 PM

No sendmail, huh? Well, who knew.

Anyway, have you tried simply setting the system name and domain in /etc/HOSTNAME and reboot the thing?

Take a look at the manual page for hostname; simply typing
Code:

hostname
should tell you what it is (sans domain name). You can set the name of the system with hostname with
Code:

hostname sysname
where sysname is the name you want set. You typically can't set the domain name that way (see the hostname manual page).

It's usual that you can set the host and domain in /etc/rc.d/rc.inet1 or /etc/init.d/boot and look at /etc/host.conf (if you don't have one or more of those files; e.g., in /etc/rc.d, look for a file of that name somewhere in the /etc directory). Note that, if the system name is not set in one of those you probably don't want to mess with it; if the system name is set in one of those files and it's the wrong one, change it and reboot.

Most every system I've ever worked with, both Unix and Linux, takes the system name setting from /etc/HOSTNAME (or some variant of that). Whatever is overriding your system name is going to be found in some configuration file somewhere and you should find that and either comment out the "wrong" name or simply change it with an editor.

Whatever file that network manager uses for configuration (and I have no idea what that might be) is probably where you'll find the problem; might be worth a look-see at the manual page for the network manager? I dunno.

Hope this helps some.

JZL240I-U 10-09-2012 06:47 AM

Quote:

Originally Posted by tronayne (Post 4800540)
...Anyway, have you tried simply setting the system name and domain in /etc/HOSTNAME and reboot the thing?

That doesn't work, as this is not the HOSTNAME (see the <edit> in my thread starting post #1 ;)).

I tried
Code:

hostname test
after which a simple "hostname" returns "test" (not anymore "netbook"). /etc/HOSTNAME was not changed and the system variable "$HOSTNAME" still is "netbook".

There is no /etc/rc.d/rc.inet1.

There is an /etc/init.d/boot.localnet which loads the system variable $HOSTNAME with the content of /etc/HOSTNAME (i.e. "netbook").

/etc/host.conf is the "resolver conofiguration file" with two lines
Code:

order hosts, bind
multi on

Quote:

Originally Posted by tronayne (Post 4800540)
...Most every system I've ever worked with, both Unix and Linux, takes the system name setting from /etc/HOSTNAME (or some variant of that). Whatever is overriding your system name is going to be found in some configuration file somewhere and you should find that and either comment out the "wrong" name or simply change it with an editor...

Yes. YES. But I can't find that blasted configuration file responsible for this.

I used
Code:

find / -type f -newer /root/timestamp > op
with "timestamp created immediately before a "hostname test" command. 1.8 MB output but no luck. Nor did I find anything in the network manager connected files :(. The man page says, that network manager uses the same "gethostname(2)" to get the hostname :rolleyes:...

tronayne 10-09-2012 08:31 AM

I don't know if this will help but here's an example program that will print your host and domain name using the gethostname() and getdomainname() functions.
Code:

/***********************************************************************
 * File    :  gethostname.c
 * Author  :  Saurabh Gupta
 * Desc    :  Demonstrate gethostname(2)
 *              gethostname example
 *              gethostname example c
 *              gethostname example linux
 *              gethostname function linux
 * Source  :  http://saurabhgupta0527.blogspot.com/2011/07/socket.html
 * Created  :  AM 10:27 22 August 2011
 * Note    :
 ************************************************************************/ 
 #include <stdio.h> 
 #include <unistd.h> 
 #include <stdlib.h> 
 #include <errno.h> 
 #include <string.h> 
 #include <sys/types.h> 
 #include <sys/stat.h> 
 #include <sys/socket.h> 
 #include <sys/un.h> 
 #include <netinet/in.h> 
 #include <arpa/inet.h> 
 
  int main(int argc,char **argv) { 
    int z; 
    char buf[32]; 
 
    z = gethostname(buf,sizeof buf); 
 
    if ( z == -1 ) { 
        fprintf(stderr, "%s: gethostname(2)\n", 
        strerror(errno)); 
        exit(1); 
    } 
 
    printf("host name = '%s'\n",buf); 
 
    z = getdomainname(buf,sizeof buf); 
 
    if ( z == -1 ) { 
        fprintf(stderr,"%s: getdomainname(2)\n", 
        strerror(errno)); 
        exit(1); 
    } 
 
    printf("domain name = '%s'\n",buf); 
 
    return 0; 
  }

If you save the above as gethostname.c in a convenient directory then enter
Code:

make gethostname
you should be able to execute the program and see what your system name and domain are set to; might help chase something down.

The above example comes from http://www.ccplusplus.com/2011/11/ge...example-c.html.

Note that (from the getdomainname manual page):
Quote:

Since Linux 1.0, the limit on the length of a domain name, including the terminating
null byte, is 64 bytes. In older kernels, it was 8 bytes.

On most Linux architectures (including x86), there is no getdomainname() system
call; instead, glibc implements getdomainname() as a library function that returns a
copy of the domainname field returned from a call to uname(2).
See what this tells you, eh?


All times are GMT -5. The time now is 09:37 AM.