
Ahora pasaremos a configurar postfix[main.cf]:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 | ################################################### # Configuraciones del dominio[ESPECIFICO] ################################################### # Dominio de correo desde el cual se enviará correo, es decir, nuestro dominio mydomain = inutil.cu # Declarar FQDN del equipo usando la variable del dominio myhostname = correo.$mydomain # Declarar el dominio del cual proviene y al cual se entrega el correo myorigin = /etc/mailname # Declarar destino para el transporte local (mensajes locales y del mailserver) mydestination = $myorigin, $myhostname, localhost, localhost.$mydomain # Personalizar banner (el protocolo SMTP requiere que la primera palabra # sea el FQDN del equipo) smtpd_banner = $myhostname ESMTP $mail_name # Desactivar servicio de notificaciones de nuevo correo (mejor rendimiento) biff = no # Backguard compatibility, mandatory for Postfix 3 #compatibilizando expresiones de Postfix 2 con Postfix 3[OBLIGATORIO] compatibility_level=2 # Backguard compatibility # Prohibir direcciones de correo sin dominio append_dot_mydomain = no readme_directory = no # Plantilla personalizada para correos de error bounce_template_file = /etc/postfix/warn/bounce.msg ################################################### # Network Config [ESPECIFICO] ################################################### # Backguard compatibility #mynetworks_style = subnet mynetworks_style = host # A menos que realmente se haga de relayhost para otros MTAs, restringir la red # de confianza a las direcciones loopback mynetworks = 127.0.0.0/8 # Interfaces para escuchar peticiones inet_interfaces = all # Protocolos a utilizar inet_protocols = ipv4 # all -> for ipv4 & ipv6 # Dirección para verificar la existencia de remitentes en otro MTA address_verify_sender = mailer-daemon@$mydomain # Establecer un tiempo de vida a las verificaciones address_verify_sender_ttl = 8h ################################################### # Notificaciones [ESPECIFICO] ################################################### # Clases para errores que se reportan al postmaster notify_classes = bounce, 2bounce, delay, policy, protocol, resource, software ################################################### # Configuraciones del relayhost[ESPECIFICO] ################################################### # No se utiliza otro MTA intermedio para enviar el correo relayhost = ################################################### # Configuracion de los usuarios virtuales@MySQL[ESPECIFICO] ################################################### virtual_minimum_uid = 5000 virtual_mailbox_base = /home/vmail virtual_uid_maps = static:5000 virtual_gid_maps = static:5000 virtual_transport = dovecot virtual_alias_maps = mysql:/etc/postfix/sql/mysql_virtual_alias_maps.cf, mysql:/etc/postfix/sql/mysql_virtual_alias_domainaliases_maps.cf virtual_mailbox_domains = mysql:/etc/postfix/sql/mysql_virtual_domains_maps.cf virtual_mailbox_maps = mysql:/etc/postfix/sql/mysql_virtual_mailbox_maps.cf, mysql:/etc/postfix/sql/mysql_virtual_mailbox_domainaliases_maps.cf show_user_unknown_table_name = no # Do not set virtual_alias_domains. virtual_alias_domains = ################################################### # Save all In/Out messages [ESPECIFICO] ################################################### # Guardar copia de los correos para Seguridad Informática always_bcc = bcc@inutil.cu ################################################### # Message/Inbox config [ESPECIFICO] ################################################### #NEW, testing # Requerir que las direcciones de MAIL FROM y RCPT TO estén encerradas entre <> strict_rfc821_envelopes = yes invalid_hostname_reject_code = 554 multi_recipient_bounce_reject_code = 554 non_fqdn_reject_code = 554 relay_domains_reject_code = 554 unknown_address_reject_code = 554 unknown_client_reject_code = 554 unknown_hostname_reject_code = 554 unknown_relay_recipient_reject_code = 554 unknown_virtual_alias_reject_code = 554 unknown_virtual_mailbox_reject_code = 554 unverified_recipient_reject_code = 554 unverified_sender_reject_code = 554 # Delimitador de destinatarios recipient_delimiter = + enable_original_recipient = no ### Maximum mailbox size (0 = unlimited - is already limited by Dovecot quota) mailbox_size_limit = 0 message_size_limit = 1572864 # 1MB -> 1048576 # 1.5MB -> 1572864 # Máximo de destinatarios en un mensaje #default_destination_recipient_limit = 20 # Cantidad maxima de destinatarios para un mensaje smtpd_recipient_limit = 15 # Dovecot dovecot_destination_recipient_limit = 1 # Enviar alertas sobre correo demorado delay_warning_time = 4h smtpd_error_sleep_time = 1s # Tiempo en cola de los mensajes bounce_queue_lifetime = 4d # Tiempo maximo de vida en la cola maximal_queue_lifetime = 7d # Tiempo minimo y maximo de reconexion cuando la conexion falla minimal_backoff_time = 1000s maximal_backoff_time = 8000s # Limite de entrega simultanea a un mismo usuario local local_destination_concurrency_limit = 15 # Desactivar anuncio de comandos dependiendo de la ip del cliente smtpd_discard_ehlo_keyword_address_maps = cidr:/etc/postfix/rules/ehlo_map.cidr # Definir límite de conexiones simultáneas que un cliente puede establecer smtpd_client_connection_count_limit = 3 # Definir límite de errores que un cliente puede cometer antes de desconectarlo smtpd_hard_error_limit = 5 # # Definir límite de errores que un cliente puede cometer antes de reducir la # velocidad de su conexión smtpd_soft_error_limit = 1 # # Definir límite de comandos basura que un cliente puede realizar antes de # incrementarle el conteo smtpd_junk_command_limit = 2 ################################################### # Chequeos de mensajes[ESPECIFICO] con RE ################################################### header_checks = pcre:/etc/postfix/rules/header_checks, pcre:/etc/postfix/rules/headerchkmsg body_checks = pcre:/etc/postfix/rules/body_checks, regexp:/etc/postfix/rules/avchk, pcre:/etc/postfix/rules/avchkre mime_header_checks = pcre:/etc/postfix/rules/mime_header_checks ################################################### # Parametros de seguridad SASL/TLS[GENERALES] ################################################### # Usar como cliente el cifrado TLS, si el otro MTA lo admite smtp_tls_security_level = may # Anunciar a los clientes/servidores el soporte de cifrado TLS, pero no obligar a su uso smtpd_tls_security_level = may smtp_sasl_auth_enable = no smtpd_reject_unlisted_recipient = yes smtpd_reject_unlisted_sender = yes smtpd_sasl_authenticated_header = yes # Habilitar autenticación SASL smtpd_sasl_auth_enable = yes # Compatibilidad con clientes de correo viejos como Outlook Express 4 # o MS Exchange 5.0 broken_sasl_auth_clients = yes # Deshabilitar otros comandos que no pertenecen al protocolo SMTP smtpd_forbidden_commands = CONNECT, EXPN, GET, PASS, POST, USER # Dovecot SASL support. smtpd_sasl_type = dovecot smtpd_sasl_path = private/dovecot-auth # Reino (ámbito) de autenticación local SASL smtpd_sasl_local_domain = inutil.cu # Mecanismos de authenticación SASL que Postfix usará para sesiones TLS # (la autenticación sin TLS está deshabilitada, por lo que no hace falta # declarar smtpd_sasl_security_options) smtpd_sasl_tls_security_options = noanonymous #smtpd_sasl_security_options = noanonymous # No anunciar o soportar autenticación SASL sobre conexiones en claro smtpd_tls_auth_only = yes # Redes a las que no se ofrecerá soporte AUTH smtpd_sasl_exceptions_networks = !10.10.0.0/16 smtpd_enforce_tls = yes smtpd_use_tls = yes smtp_use_tls = yes smtp_enforce_tls = no smtp_tls_note_starttls_offer = yes smtpd_tls_received_header = yes smtpd_tls_session_cache_timeout = 3600s ############################################################################ # Config TLS/SSL protocols[ESPECIFICO] ############################################################################ smtpd_tls_CAfile = /etc/postfix/certs/postfix.pem smtpd_tls_cert_file = /etc/postfix/certs/postfix.pem smtpd_tls_key_file = /etc/postfix/certs/postfix.pem tls_random_source = dev:/dev/urandom smtpd_tls_protocols = !SSLv2 !SSLv3 smtp_tls_protocols = !SSLv2 !SSLv3 lmtp_tls_protocols = !SSLv2 !SSLv3 smtpd_tls_mandatory_protocols = !SSLv2 !SSLv3 smtp_tls_mandatory_protocols = !SSLv2 !SSLv3 lmtp_tls_mandatory_protocols = !SSLv2 !SSLv3 # Good bye SSLv3 and fuck you POODLE!!! ############################################################################ # Config TLS/SSL Fix Lockjam attack [ESPECIFICO] ############################################################################ # Archivo de cache para las sesiones TLS de los clientes smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache # # Archivo de cache para las sesiones TLS de Postfix como cliente smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache # Dejar en las trazas un sumario de la sesión TLS y los niveles # de negociación smtpd_tls_loglevel = 2 smtp_tls_loglevel = 2 smtpd_tls_eecdh_grade = strong smtpd_tls_ciphers = high tls_ssl_options = NO_COMPRESSION # Excluir cifrados nulos (o sea, autenticación sin cifrado) smtpd_tls_exclude_ciphers = aNULL, eNULL, EXPORT, DES, RC2, IDEA, SEED, LOW, RC4, MD5, PSK, aECDH, EDH-DSS-DES-CBC3-SHA, EDH-RSA-DES-CDC3-SHA, KRB5-DE5, CBC3-SHA # Usar cifrados medios o superiores para TLS mandatorio smtpd_tls_mandatory_ciphers = medium # Adicionalmente, excluir cifrados bajos para TLS mandatorio smtpd_tls_mandatory_exclude_ciphers = aNULL, MD5, DES smtpd_tls_dh1024_param_file = /etc/postfix/certs/dh_2048.pem smtpd_tls_dh512_param_file = /etc/postfix/certs/dh_1024.pem smtp_tls_exclude_ciphers = EXPORT, LOW, MD5, aDSS, kECDHe, kECDHr, kDHd, kDHr,SEED, IDEA, RC2 tls_preempt_cipherlist = yes ################################################### # Parametros de seguridad[GENERALES] ################################################### # Disable the SMTP VRFY command. This stops some techniques used to # harvest email addresses. disable_vrfy_command = yes ################################################### # EVITAR SUPLANTACION DE IDENTIDAD AL ENVIAR ################################################### smtpd_sender_login_maps = mysql:/etc/postfix/sql/mysql_sender_login_maps.cf ################################################### # Restricciones de envio[n/i]/recepcion/suplantacion ################################################### #smtpd_restriction_classes = cu-in, cu-out, int-in, int-out #cu-in = check_sender_access regexp:/etc/postfix/rules/cu, reject #cu-out = check_recipient_access regexp:/etc/postfix/rules/cu, reject #int-in = check_sender_access regexp:/etc/postfix/rules/int, reject #int-out = check_recipient_access regexp:/etc/postfix/rules/int, reject ################################################### # Parametros de seguridad[RESTRICCIONES] ################################################### # Requerir que el cliente se presente con el comando HELO/EHLO antes de entregar smtpd_helo_required = yes # Esperar al comando RCPT TO antes de evaluar $smtpd_client_restrictions, # $smtpd_helo_restrictions y $smtpd_sender_restrictions smtpd_delay_reject = yes # Restricciones para el equipo del cliente smtpd_client_restrictions = permit_mynetworks, permit_sasl_authenticated, check_client_access cidr:/etc/postfix/rules/local_network.cidr, reject_unknown_client_hostname, permit # Restricciones para la identificación del cliente smtpd_helo_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_non_fqdn_helo_hostname, reject_invalid_helo_hostname, reject_unknown_helo_hostname, reject_unknown_sender_domain, reject_invalid_hostname, check_helo_access pcre:/etc/postfix/rules/helo_checks, check_client_access cidr:/etc/postfix/rules/local_network.cidr permit # Restricciones para los remitentes smtpd_sender_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_sender_login_mismatch, reject_unknown_sender_domain, reject_non_fqdn_sender, reject_unlisted_sender, check_sender_access hash:/etc/postfix/rules/spamaddress, #check_recipient_access hash:/etc/postfix/rules/access-in, # Restricciones para destinatarios y relay smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unknown_sender_domain, reject_unknown_recipient_domain, reject_unlisted_recipient, reject_non_fqdn_recipient, #check_sender_access hash:/etc/postfix/rules/access-out, reject_unauth_destination, check_policy_service unix:private/policy-spf, check_sender_mx_access cidr:/etc/postfix/rules/bogus_mx, reject_rbl_client dsn.rfc-ignorant.org, reject_rbl_client dul.dnsbl.sorbs.net, reject_rbl_client list.dsbl.org, reject_rbl_client sbl-xbl.spamhaus.org, reject_rbl_client bl.spamcop.net, reject_rbl_client dnsbl.sorbs.net, reject_rbl_client cbl.abuseat.org, reject_rbl_client ix.dnsbl.manitu.net, reject_rbl_client combined.rbl.msrbl.net, reject_rbl_client rabl.nuclearelephant.com # Tiempo de espera para SPF policy-spf_time_limit = 3600s smtpd_data_restrictions = reject_unauth_pipelining, reject_multi_recipient_bounce, permit smtpd_etrn_restrictions = reject # Drop connections if other server is sending too quickly postscreen_greet_action = drop ### DNS blocklists postscreen_dnsbl_threshold = 2 postscreen_dnsbl_sites = ix.dnsbl.manitu.net*2 zen.spamhaus.org*2 postscreen_dnsbl_action = drop # Tras poner en cola, entregar el contenido a un transporte (Amavis) #content_filter = smtp-amavis:[127.0.0.1]:10024 ################################################### # Configuracion de ID en los mensajes[ESPECIFICO] ################################################### enable_long_queue_ids = yes ################################################### # Configuracion de SMTP[GENERALES] ################################################### smtp_mx_address_limit = 5 # from 0 to 5 smtp_connect_timeout = 30 smtp_helo_timeout = 60s smtp_rcpt_timeout = 240s smtp_quit_timeout = 240s smtp_rset_timeout = 20s ################################################### # # Configuraciones de alias+mailman[ESPECIFICO] # ################################################### # Mapeo de alias alias_database = hash:/etc/aliases alias_maps = hash:/etc/aliases #, hash:/var/lib/mailman/data/aliases # Mailman transport_maps = hash:/etc/postfix/transport mailman_destination_recipient_limit = 1 owner_request_special = no ################################################### # Otras configuraciones[ESPECIFICO] ################################################### queue_directory = /var/spool/postfix command_directory = /usr/sbin daemon_directory = /usr/lib/postfix/sbin data_directory = /var/lib/postfix setgid_group = postdrop mail_owner = postfix default_privs = nobody unknown_local_recipient_reject_code = 550 local_recipient_maps = $alias_maps, proxy:unix:passwd.byname in_flow_delay = 1s home_mailbox = Maildir/ mail_spool_directory = /var/spool/mail # Debug debugger_command = PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin xxgdb $daemon_directory/$process_name $process_id & sleep 5 # Definir para quienes incrementar el nivel de información en las trazas debug_peer_list = $mydomain # Nivel de información en las trazas (el valor predeterminado es 2) # Descomentar y aumentar hasta 4 solo para diagnosticar, pero preferiblemente # no para producción debug_peer_level = 4 sendmail_path = /usr/sbin/sendmail newaliases_path = /usr/bin/newaliases mailq_path = /usr/bin/mailq # Comando externo opcional a usar para la entrega local del correo mailbox_command = /usr/lib/dovecot/deliver # Disable the rewriting of "site!user" into "user@site". swap_bangpath = no # Disable the rewriting of the form "user%domain" to "user@domain". allow_percent_hack = no # Allow recipient address start with '-'. allow_min_user = no |
</main.cf>
En el archivo master.cf añadir:
1 2 3 4 5 6 7 8 9 10 11 12 | # Dovecot dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/lib/dovecot/deliver -d ${recipient} # Mailman mailman unix - n n - - pipe flags=FR user=list argv=/usr/lib/mailman/bin/postfix-to-mailman.py ${nexthop} ${user} # SPF policy-spf unix - n n - - spawn user=nobody argv=/usr/sbin/postfix-policyd-spf-perl |
Los demás archivos de configuración por ser demasiado grandes van incluidos en el compactado adjunto.
Al terminar todos los cambios en el server, reiniciar los servicios y revisar los log para
chequear que todo está funcionando como debe ser…
1 2 3 4 5 | # /etc/init.d/nginx restart # /etc/init.d/mysql restart # /etc/init.d/saslauthd restart # /etc/init.d/dovecot restart # /etc/init.d/postfix restart |
Para probar el certificado:
1 | # openssl s_client -starttls smtp -connect mail.inutil.cu:25 |
Para debuguear posibles errores:
1 2 | # postfix check # egrep '(reject|warning|error|fatal|panic):' /var/log/postfix/mail.log |
Revisamos con estas 2 líneas la salida de los posibles errores en el postfix.
Ahora bien, adjunto la configuración completa para que se la estudien y la puedan modificar a su antojo. Espero es sea útil.
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36
hola alguien x aki tengo problemas con el servidor smtp
Mozilla/5.0 (X11; Linux x86_64; rv:56.0) Gecko/20100101 Firefox/56.0 Waterfox/56.3
No pusiste la duda…
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36
Exista alguna manera de crear diferentes restricciones para cada usuario de correo en mime_header_checks.
Es decir para mi usuario1 que no pueda enviar archivos adjuntos pero que mi usuario 2 si.
Y un tercero que mi usuario 3 pueda enviar algunos tipos de archivos adjuntos.