Instalación de Sendmail
De Wiki Educalibre
Tabla de contenidos |
[editar] Preparativos
NOTA: Instalación basada en CentOS 4.x (También sirve en FC/RH9)
Para poder instalar y configurar un servidor de correos con Sendmail necesitamos los siguientes paquetes:
- sendmail
- sendmail-cf
- m4
- make
[editar] Instalando paquetes necesarios
Usando apt:
# apt-get install sendmail sendmail-cf m4 make
Usando yum:
yum -y install sendmail sendmail-cf m4 make
[editar] Archivos de Configuración
Los archivos de configuración de Sendmail se encuentran todos en /etc/mail
[root@mail mail]# ls -l total 344 -rw-r--r-- 1 root root 4734 sep 3 12:44 access -rw-r----- 1 root root 12288 sep 3 12:44 access.db -rw-r--r-- 1 root root 0 feb 21 2005 domaintable -rw-r----- 1 root root 12288 ago 23 11:42 domaintable.db -rw-r--r-- 1 root root 5588 feb 21 2005 helpfile -rw-r--r-- 1 root root 147 ago 23 13:03 local-host-names -rw-r--r-- 1 root root 0 feb 21 2005 mailertable -rw-r----- 1 root root 12288 ago 23 11:42 mailertable.db -rw-r--r-- 1 root root 1035 feb 21 2005 Makefile -rw-r--r-- 1 root root 58572 ago 23 13:01 sendmail.cf -rw-r--r-- 1 root root 58074 ago 23 11:42 sendmail.cf.bak -rw-r--r-- 1 root root 6748 ago 23 13:01 sendmail.mc -rw-r--r-- 1 root root 40277 ago 23 13:01 submit.cf -r--r--r-- 1 root root 41343 feb 21 2005 submit.cf.bak -rw-r--r-- 1 root root 952 feb 21 2005 submit.mc -rw-r--r-- 1 root root 127 feb 21 2005 trusted-users -rw-r--r-- 1 root root 0 feb 21 2005 virtusertable -rw-r----- 1 root root 12288 ago 23 11:42 virtusertable.db [root@mail mail]#
[editar] sendmail.mc
Este archivo es el que contiene la configuración del servidor de correos. Por defecto sendmail esta configurado para mandar mails desde la interfaz loopback 127.0.0.1 y eso lo podrán notar en esta línea.
[editar] Activando Interfaces de Red
DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl
Aquí tenemos dos opciones para configurar, conmentamos esta línea y sendmail asumira que podrá enviar mails por cualquier interfaz, o declaramos cada una de las interfaces que queremos dejar escuchando el servicio de correo.
Ejemplo 1: Dar acceso a todas las interfaces de red para enviar correo.
dnl DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl
Ejemplo 2: Dar acceso solo a algunas interfaces o direcciones IP para enviar correo.
DAEMON_OPTIONS(`Port=smtp,Addr=192.168.0.1, Name=MTA')dnl DAEMON_OPTIONS(`Port=smtp,Addr=172.16.0.10, Name=MTA')dnl
[editar] Filtrado de dominios válidos
Sendmail por defecto acepta mails con dominios no resueltos y el FEATURE que lo define es este:
FEATURE(`accept_unresolvable_domains')dnl
Es muy recomendable configurar sendmail para recibir correo solo de dominios resueltos si queremos dar la cara a internet. Asi mitigamos bastante el spam.
Ejemplo 3: Denegar el acceso a mails con dominios no válidos o no resueltos.
dnl FEATURE(`accept_unresolvable_domains')dnl
[editar] Enmascarar dominios
Si el servidor es de una empresa y quieres mandar correo solo con un dominio, lo conveniente es enmascarar todo los mails emitidos desde el servidor con el dominio de tu empresa. En este ejemplo ocuparemos empresa.cl. La línea que nos permite esta opción es esta:
dnl MASQUERADE_AS(`mydomain.com')dnl
Ahora bien si queremos enmascarar el correo saliente lo dejamos como en este ejemplo.
Ejemplo 4: Enmascarando correo emitido con empresa.cl
MASQUERADE_AS(`empresa.cl')dnl
Ahora todos los correos emitidos por nuestros usuarios serán del tipo usuario@empresa.cl
Nota: Cuidado con las comillas!!
[editar] Archivo original de sendmail.mc
Nota: Este es el archivo original que instala sendmail para ser configurado (no usar)
divert(-1)dnl dnl # dnl # This is the sendmail macro config file for m4. If you make changes to dnl # /etc/mail/sendmail.mc, you will need to regenerate the dnl # /etc/mail/sendmail.cf file by confirming that the sendmail-cf package is dnl # installed and then performing a dnl # dnl # make -C /etc/mail dnl # include(`/usr/share/sendmail-cf/m4/cf.m4')dnl VERSIONID(`setup for Red Hat Linux')dnl OSTYPE(`linux')dnl dnl # dnl # default logging level is 9, you might want to set it higher to dnl # debug the configuration dnl # dnl define(`confLOG_LEVEL', `9')dnl dnl # dnl # Uncomment and edit the following line if your outgoing mail needs to dnl # be sent out through an external mail server: dnl # dnl define(`SMART_HOST',`smtp.your.provider') dnl # define(`confDEF_USER_ID',``8:12'')dnl dnl define(`confAUTO_REBUILD')dnl define(`confTO_CONNECT', `1m')dnl define(`confTRY_NULL_MX_LIST',true)dnl define(`confDONT_PROBE_INTERFACES',true)dnl define(`PROCMAIL_MAILER_PATH',`/usr/bin/procmail')dnl define(`ALIAS_FILE', `/etc/aliases')dnl define(`STATUS_FILE', `/var/log/mail/statistics')dnl define(`UUCP_MAILER_MAX', `2000000')dnl define(`confUSERDB_SPEC', `/etc/mail/userdb.db')dnl define(`confPRIVACY_FLAGS', `authwarnings,novrfy,noexpn,restrictqrun')dnl define(`confAUTH_OPTIONS', `A')dnl dnl # dnl # The following allows relaying if the user authenticates, and disallows dnl # plaintext authentication (PLAIN/LOGIN) on non-TLS links dnl # dnl define(`confAUTH_OPTIONS', `A p')dnl dnl # dnl # PLAIN is the preferred plaintext authentication method and used by dnl # Mozilla Mail and Evolution, though Outlook Express and other MUAs do dnl # use LOGIN. Other mechanisms should be used if the connection is not dnl # guaranteed secure. dnl # Please remember that saslauthd needs to be running for AUTH. dnl # dnl TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl dnl define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl dnl # dnl # Rudimentary information on creating certificates for sendmail TLS: dnl # cd /usr/share/ssl/certs; make sendmail.pem dnl # Complete usage: dnl # make -C /usr/share/ssl/certs usage dnl # dnl define(`confCACERT_PATH',`/usr/share/ssl/certs') dnl define(`confCACERT',`/usr/share/ssl/certs/ca-bundle.crt') dnl define(`confSERVER_CERT',`/usr/share/ssl/certs/sendmail.pem') dnl define(`confSERVER_KEY',`/usr/share/ssl/certs/sendmail.pem') dnl # dnl # This allows sendmail to use a keyfile that is shared with OpenLDAP's dnl # slapd, which requires the file to be readble by group ldap dnl # dnl define(`confDONT_BLAME_SENDMAIL',`groupreadablekeyfile')dnl dnl # dnl define(`confTO_QUEUEWARN', `4h')dnl dnl define(`confTO_QUEUERETURN', `5d')dnl dnl define(`confQUEUE_LA', `12')dnl dnl define(`confREFUSE_LA', `18')dnl define(`confTO_IDENT', `0')dnl dnl FEATURE(delay_checks)dnl FEATURE(`no_default_msa',`dnl')dnl FEATURE(`smrsh',`/usr/sbin/smrsh')dnl FEATURE(`mailertable',`hash -o /etc/mail/mailertable.db')dnl FEATURE(`virtusertable',`hash -o /etc/mail/virtusertable.db')dnl FEATURE(redirect)dnl FEATURE(always_add_domain)dnl FEATURE(use_cw_file)dnl FEATURE(use_ct_file)dnl dnl # dnl # The following limits the number of processes sendmail can fork to accept dnl # incoming messages or process its message queues to 12.) sendmail refuses dnl # to accept connections once it has reached its quota of child processes. dnl # dnl define(`confMAX_DAEMON_CHILDREN', 12)dnl dnl # dnl # Limits the number of new connections per second. This caps the overhead dnl # incurred due to forking new sendmail processes. May be useful against dnl # DoS attacks or barrages of spam. (As mentioned below, a per-IP address dnl # limit would be useful but is not available as an option at this writing.) dnl # dnl define(`confCONNECTION_RATE_THROTTLE', 3)dnl dnl # dnl # The -t option will retry delivery if e.g. the user runs over his quota. dnl # FEATURE(local_procmail,`',`procmail -t -Y -a $h -d $u')dnl FEATURE(`access_db',`hash -T<TMPF> -o /etc/mail/access.db')dnl FEATURE(`blacklist_recipients')dnl EXPOSED_USER(`root')dnl dnl # dnl # The following causes sendmail to only listen on the IPv4 loopback address dnl # 127.0.0.1 and not on any other network devices. Remove the loopback dnl # address restriction to accept email from the internet or intranet. dnl # DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl dnl # dnl # The following causes sendmail to additionally listen to port 587 for dnl # mail from MUAs that authenticate. Roaming users who can't reach their dnl # preferred sendmail daemon due to port 25 being blocked or redirected find dnl # this useful. dnl # dnl DAEMON_OPTIONS(`Port=submission, Name=MSA, M=Ea')dnl dnl # dnl # The following causes sendmail to additionally listen to port 465, but dnl # starting immediately in TLS mode upon connecting. Port 25 or 587 followed dnl # by STARTTLS is preferred, but roaming clients using Outlook Express can't dnl # do STARTTLS on ports other than 25. Mozilla Mail can ONLY use STARTTLS dnl # and doesn't support the deprecated smtps; Evolution <1.1.1 uses smtps dnl # when SSL is enabled-- STARTTLS support is available in version 1.1.1. dnl # dnl # For this to work your OpenSSL certificates must be configured. dnl # dnl DAEMON_OPTIONS(`Port=smtps, Name=TLSMTA, M=s')dnl dnl # dnl # The following causes sendmail to additionally listen on the IPv6 loopback dnl # device. Remove the loopback address restriction listen to the network. dnl # dnl DAEMON_OPTIONS(`port=smtp,Addr=::1, Name=MTA-v6, Family=inet6')dnl dnl # dnl # enable both ipv6 and ipv4 in sendmail: dnl # dnl DAEMON_OPTIONS(`Name=MTA-v4, Family=inet, Name=MTA-v6, Family=inet6') dnl # dnl # We strongly recommend not accepting unresolvable domains if you want to dnl # protect yourself from spam. However, the laptop and users on computers dnl # that do not have 24x7 DNS do need this. dnl # FEATURE(`accept_unresolvable_domains')dnl dnl # dnl FEATURE(`relay_based_on_MX')dnl dnl # dnl # Also accept email sent to "localhost.localdomain" as local email. dnl # LOCAL_DOMAIN(`localhost.localdomain')dnl dnl # dnl # The following example makes mail from this host and any additional dnl # specified domains appear to be sent from mydomain.com dnl # dnl MASQUERADE_AS(`mydomain.com')dnl dnl # dnl # masquerade not just the headers, but the envelope as well dnl # dnl FEATURE(masquerade_envelope)dnl dnl # dnl # masquerade not just @mydomainalias.com, but @*.mydomainalias.com as well dnl # dnl FEATURE(masquerade_entire_domain)dnl dnl # dnl MASQUERADE_DOMAIN(localhost)dnl dnl MASQUERADE_DOMAIN(localhost.localdomain)dnl dnl MASQUERADE_DOMAIN(mydomainalias.com)dnl dnl MASQUERADE_DOMAIN(mydomain.lan)dnl MAILER(smtp)dnl MAILER(procmail)dnl
[editar] Archivo modificado
Nota: Este archivo se ve mas pequeño que el anterior ya que se han omitido las lineas que estan comentadas.
divert(-1)dnl include(`/usr/share/sendmail-cf/m4/cf.m4')dnl VERSIONID(`setup for Red Hat Linux')dnl OSTYPE(`linux')dnl define(`confDEF_USER_ID',``8:12'')dnl dnl define(`confAUTO_REBUILD')dnl define(`confTO_CONNECT', `1m')dnl define(`confTRY_NULL_MX_LIST',true)dnl define(`confDONT_PROBE_INTERFACES',true)dnl define(`PROCMAIL_MAILER_PATH',`/usr/bin/procmail')dnl define(`ALIAS_FILE', `/etc/aliases')dnl define(`STATUS_FILE', `/var/log/mail/statistics')dnl define(`UUCP_MAILER_MAX', `2000000')dnl define(`confUSERDB_SPEC', `/etc/mail/userdb.db')dnl define(`confPRIVACY_FLAGS', `authwarnings,novrfy,noexpn,restrictqrun')dnl define(`confAUTH_OPTIONS', `A')dnl define(`confTO_IDENT', `0')dnl FEATURE(`no_default_msa',`dnl')dnl FEATURE(`smrsh',`/usr/sbin/smrsh')dnl FEATURE(`mailertable',`hash -o /etc/mail/mailertable.db')dnl FEATURE(`virtusertable',`hash -o /etc/mail/virtusertable.db')dnl FEATURE(redirect)dnl FEATURE(always_add_domain)dnl FEATURE(use_cw_file)dnl FEATURE(use_ct_file)dnl FEATURE(local_procmail,`',`procmail -t -Y -a $h -d $u')dnl FEATURE(`access_db',`hash -T<TMPF> -o /etc/mail/access.db')dnl FEATURE(`blacklist_recipients')dnl EXPOSED_USER(`root')dnl LOCAL_DOMAIN(`localhost.localdomain')dnl MASQUERADE_AS(`empresa.cl')dnl MAILER(smtp)dnl MAILER(procmail)dnl
[editar] local-host-names
Este archivo contiene los nombres de la máquina, sin ellos el servidor de mail no sabe si aceptar o no los mails.
# local-host-names - include all aliases for your machine here.
empresa.cl
mail.empresa.cl
webmail.empresa.cl
smtp.empresa.cl
www.empresa.cl
Nota: Si tienes dominios virtuales tambien deben ser incluidos aquí.
[editar] access
Este archivo es muy importante ya que es el encargado de darnos permiso para enviar mail y para denegar a los spammers. Para dar permiso a enviar correo ocupamos la palabra RELAY y para denegar el acceso con la palabra REJECT
# Check the /usr/share/doc/sendmail/README.cf file for a description # of the format of this file. (search for access_db in that file) # The /usr/share/doc/sendmail/README.cf is part of the sendmail-doc # package. # # by default we allow relaying from localhost... localhost.localdomain RELAY localhost RELAY 127.0.0.1 RELAY empresa.cl RELAY mail.empresa.cl RELAY webmail.empresa.cl RELAY smtp.empresa.cl RELAY www.empresa.cl RELAY # damos acceso a nuestras ip's # reemplazar las x por los mueros ip's xxx.xxx.xxx.xx1 RELAY xxx.xxx.xxx.xx2 RELAY xxx.xxx.xxx.xx3 RELAY # si tenemos una red interna le damos # acceso al segmento de red 192.168.0 RELAY 192.168.0. RELAY # denegar acceso a las direcciones de correos spammers cragetlinsont@yyhmail.com REJECT cdvilbasj@hotmail.com REJECT support_refnum_2836@charteronebank.com REJECT # denegar acceso a dominios de spam dominio.spam.org REJECT dominio.spam.net REJECT
[editar] Poniendo en marcha el servidor
Ahora solo nos falta crear las tablas de hash y el archivo generado por las macros m4 que es el resultado de la configuración de sendmail.mc ahora en toda su extensión llamado sendmail.cf.
Ejemplo 5: Generar el archivo sendmail.cf
# make -C /etc/mail
Ejemplo 6: Crear tabla de hash del archivo access
# cd /etc/mail # makemap hash access.db < access
Ejemplo 7: Crear tabla de hash del archivo virtusertable
# cd /etc/mail # makemap hash virtusertable.db < virtusertable
[editar] Reiniciando el servicio
Ahora ponemos en marcha el servidor con estos comandos.
# /etc/init.d/sendmail restart
Si aparece algo como esto, estamos OK
Apagando sendmail: [ OK ] Desactivación de sm-client: [ OK ] Iniciando sendmail: [ OK ] Inicio de sm-client: [ OK ]
[editar] Dejar sendmail activo luego de reiniciar
En este caso dejaremos sendmail activo en los niveles 3,4 y 5 (init)
# chkconfig --level 345 sendmail on

