無法在 Postfix 上中繼從外部 IP 訪問它
我認為對於 postfix 專家來說,這個問題是小菜一碟,但是在花了幾天時間嘗試為私人使用者使用我自己的伺服器之後,我沒有想法了。
我可以在我的網路中:
從 LAN -> DMZ -> WAN 發送電子郵件 從 WAN -> DMZ -> LAN 接收電子郵件
例子:
在 LAN 上,我可以連接 DMZ 內的郵件伺服器,將郵件發送到 Gmail、Yahoo、Hotmail 等…
我可以將電子郵件發送到我擁有的其他域,例如 domain2、domain3 等…
我可以接收所有電子郵件。
我可以回复所有電子郵件。
我無法從外部來源發送電子郵件,例如:
4G -> WAN -> DMZ(從這一點我可以閱讀電子郵件)但是,當我嘗試發送時,出現很多關於拒絕訪問、禁止中繼等的錯誤……
在我的內部網路之外,在第二種情況下使用 4G 智能手機進行連接,我得到:
我可以接收所有電子郵件。
我無法回復電子郵件。
我無法發送電子郵件。
從我目前的設置中,訪問 LAN / DMZ 之外的錯誤(例如從智能手機連接和驗證 4G)是:
Oct 17 06:06:04 mail postfix/submission/smtpd[20879]: connect from unknown[138.0.151.15]:52395 Oct 17 06:06:04 mail postfix/submission/smtpd[20879]: NOQUEUE: reject: RCPT from unknown[138.0.151.15]:52395: 554 5.7.1 <someone@gmail.com>: Recipient address rejected: Access denied; from=<teste@mywebsite.com> to=<someone@gmail.com> proto=ESMTP helo=<[100.64.250.167]> Oct 17 06:06:24 mail postfix/submission/smtpd[20879]: lost connection after DATA from unknown[138.0.151.15]:52395 Oct 17 06:06:24 mail postfix/submission/smtpd[20879]: disconnect from unknown[138.0.151.15]:52395 ehlo=2 starttls=1 mail=1 rcpt=0/1 data=0/1 commands=4/6
我目前的 master.cf 是:
# # Postfix master process configuration file. For details on the format # of the file, see the master(5) manual page (command: "man 5 master" or # on-line: http://www.postfix.org/master.5.html). # # Do not forget to execute "postfix reload" after editing this file. # # ========================================================================== # service type private unpriv chroot wakeup maxproc command + args # (yes) (yes) (no) (never) (100) # ========================================================================== smtp inet n - n - - smtpd -o receive_override_options=no_address_mappings # -o smtpd_client_connect_count_limit=100 # -o smtpd_sasl_auth_enable=yes -o smtp_tls_security_level=may # SSL 465 smtps inet n - n - - smtpd # -o smtpd_client_connect_count_limit=10 -o smtpd_tls_wrappermode=yes -o smtpd_sasl_auth_enable=yes -o smtpd_relay_restrictions=permit_mynetworks,permit_sasl_authenticated,reject -o smtpd_client_restrictions=permit_sasl_authenticated,permit_auth_destinations,reject #smtp inet n - n - 1 postscreen #smtpd pass - - n - - smtpd dnsblog unix - - n - 0 dnsblog tlsproxy unix - - n - 0 tlsproxy # TLS 587 submission inet n - n - - smtpd -o syslog_name=postfix/submission -o smtpd_tls_security_level=encrypt -o smtpd_etrn_restrictions=reject -o smtpd_sasl_auth_enable=yes -o receive_override_options=no_address_mappings -o smtpd_relay_restrictions=permit_mynetworks,permit_sasl_authenticated,reject -o smtpd_recipient_restrictions=permit_mynetworks,permit_sasl_authenticated,permit_auth_destination,reject # -o smtpd_tls_security_level=encrypt # -o smtpd_sasl_auth_enable=yes # -o smtpd_tls_auth_only=yes # -o smtpd_reject_unlisted_recipient=no # -o smtpd_client_restrictions=$mua_client_restrictions # -o smtpd_helo_restrictions=$mua_helo_restrictions # -o smtpd_sender_restrictions=$mua_sender_restrictions # -o smtpd_recipient_restrictions= # -o smtpd_relay_restrictions=permit_sasl_authenticated,reject -o milter_macro_daemon_name=ORIGINATING #smtps inet n - n - - smtpd # -o syslog_name=postfix/smtps # -o smtpd_tls_wrappermode=yes # -o smtpd_sasl_auth_enable=yes # -o smtpd_reject_unlisted_recipient=no # -o smtpd_client_restrictions=$mua_client_restrictions # -o smtpd_helo_restrictions=$mua_helo_restrictions # -o smtpd_sender_restrictions=$mua_sender_restrictions # -o smtpd_recipient_restrictions= # -o smtpd_relay_restrictions=permit_sasl_authenticated,reject # -o milter_macro_daemon_name=ORIGINATING #628 inet n - n - - qmqpd pickup unix n - n 60 1 pickup cleanup unix n - n - 0 cleanup qmgr unix n - n 300 1 qmgr #qmgr unix n - n 300 1 oqmgr tlsmgr unix - - n 1000? 1 tlsmgr rewrite unix - - n - - trivial-rewrite bounce unix - - n - 0 bounce defer unix - - n - 0 bounce trace unix - - n - 0 bounce verify unix - - n - 1 verify flush unix n - n 1000? 0 flush proxymap unix - - n - - proxymap proxywrite unix - - n - 1 proxymap smtp unix - - n - - smtp relay unix - - n - - smtp # -o smtp_helo_timeout=5 -o smtp_connect_timeout=5 showq unix n - n - - showq error unix - - n - - error retry unix - - n - - error discard unix - - n - - discard local unix - n n - - local virtual unix - n n - - virtual lmtp unix - - n - - lmtp anvil unix - - n - 1 anvil scache unix - - n - 1 scache # # ==================================================================== # Interfaces to non-Postfix software. Be sure to examine the manual # pages of the non-Postfix software to find out what options it wants. # # Many of the following services use the Postfix pipe(8) delivery # agent. See the pipe(8) man page for information about ${recipient} # and other message envelope options. # ==================================================================== # # maildrop. See the Postfix MAILDROP_README file for details. # Also specify in main.cf: maildrop_destination_recipient_limit=1 # #maildrop unix - n n - - pipe # flags=DRhu user=vmail argv=/usr/local/bin/maildrop -d ${recipient} # # ==================================================================== # # Recent Cyrus versions can use the existing "lmtp" master.cf entry. # # Specify in cyrus.conf: # lmtp cmd="lmtpd -a" listen="localhost:lmtp" proto=tcp4 # # Specify in main.cf one or more of the following: # mailbox_transport = lmtp:inet:localhost # virtual_transport = lmtp:inet:localhost # # ==================================================================== # # Cyrus 2.1.5 (Amos Gouaux) # Also specify in main.cf: cyrus_destination_recipient_limit=1 # #cyrus unix - n n - - pipe # user=cyrus argv=/cyrus/bin/deliver -e -r ${sender} -m ${extension} ${user} # # ==================================================================== # # Old example of delivery via Cyrus. # #old-cyrus unix - n n - - pipe # flags=R user=cyrus argv=/cyrus/bin/deliver -e -m ${extension} ${user} # # ==================================================================== # # See the Postfix UUCP_README file for configuration details. # #uucp unix - n n - - pipe # flags=Fqhu user=uucp argv=uux -r -n -z -a$sender - $nexthop!rmail ($recipient) # # ==================================================================== # # Other external delivery methods. # #ifmail unix - n n - - pipe # flags=F user=ftn argv=/usr/lib/ifmail/ifmail -r $nexthop ($recipient) # #bsmtp unix - n n - - pipe # flags=Fq. user=bsmtp argv=/usr/local/sbin/bsmtp -f $sender $nexthop $recipient # #scalemail-backend unix - n n - 2 pipe # flags=R user=scalemail argv=/usr/lib/scalemail/bin/scalemail-store # ${nexthop} ${user} ${extension} # #mailman unix - n n - - pipe # flags=FR user=list argv=/usr/lib/mailman/bin/postfix-to-mailman.py # ${nexthop} ${user} dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/local/libexec/dovecot-lda -f ${sender} -a ${recipient} -d ${user}@{nexthop} amavisd-new unix - - n - 2 lmtp -o lmtp_data_done_timeout=1200s -o lmtp_send_xforward_command=yes -o disable_dns_lookups=yes -o max_use=20 127.0.0.1:10025 inet n - n - - smtpd -o content_filter= -o local_recipient_maps= -o relay_recipient_maps= -o smtpd_restriction_classes= -o smtpd_delay_reject=no -o smtpd_client_restrictions=permit_mynetworks,reject -o smtpd_helo_restrictions= -o smtpd_sender_restrictions= -o smtpd_recipient_restrictions=permit_mynetworks,reject -o smtpd_data_restrictions=reject_unauth_pipelining -o mynetworks=127.0.0.0/8 -o strict_rfc821_envelopes=yes
我目前的 main.cf 是:
compatibility_level = 2 queue_directory = /var/spool/postfix command_directory = /usr/local/sbin daemon_directory = /usr/local/libexec/postfix data_directory = /var/db/postfix mail_owner = postfix myhostname = mail.$mydomain mydomain = mywebsite.com myorigin = $mydomain inet_interfaces = all mydestination = $myhostname, localhost.$mydomain, localhost unknown_local_recipient_reject_code = 550 mynetworks = 127.0.0.0/8, 10.0.0.0/24, 192.168.0.0/24 alias_maps = hash:/etc/aliases recipient_delimiter = + mail_spool_directory = /usr/local/vhosts smtpd_banner = $myhostname ESMTP $mail_name debug_peer_level = 3 sendmail_path = /usr/local/sbin/sendmail newaliases_path = /usr/local/bin/newaliases mailq_path = /usr/local/bin/mailq setgid_group = maildrop html_directory = no manpage_directory = /usr/local/man sample_directory = /usr/local/etc/postfix readme_directory = no inet_protocols = all # Authentication smtpd_sasl_auth_enable = yes #smtp_sasl_mechanism_filter = plain, login # Forbids anonymous and plaintext authentication mechanisms over an # unencrypted transport layer smtp_sasl_security_options = noanonymous, noplaintext, noactive, nodictionary # Allows plaintext mechanisms when talking to the server with TLS smtpd_sasl_tls_security_options = noanonymous smtpd_sasl_local_domain = $myhostname broken_sasl_auth_clients = yes smtpd_sasl_type = dovecot smtpd_sasl_path = private/auth smtpd_sasl_authenticated_header = yes smtpd_sender_login_maps = proxy:mysql:/usr/local/etc/postfix/mysql-sender-logins-maps.cf lmtp_tls_fingerprint_digest = sha1 local_header_rewrite_clients = permit_mynetworks permit_sasl_authenticated # Virtual mailboxes local_transport = virtual virtual_alias_maps = proxy:mysql:/usr/local/etc/postfix/mysql-virtual-alias-maps.cf virtual_mailbox_base = /usr/local/vhosts virtual_mailbox_domains = proxy:mysql:/usr/local/etc/postfix/mysql-virtual-mailbox-domains.cf virtual_mailbox_maps = proxy:mysql:/usr/local/etc/postfix/mysql-virtual-mailbox-maps.cf virtual_minimum_uid = 5000 virtual_transport = lmtp:unix:private/dovecot-lmtp virtual_gid_maps = static:5000 virtual_uid_maps = static:5000 mailbox_size_limit = 0 virtual_mailbox_limit = 0 # The maximal size in bytes of a message, including envelope # information. message_size_limit = 104857600 # The maximal number of recipients per message for the smtp message # delivery transport. smtp_destination_recipient_limit = 10 # How many simultaneous connections any remote SMTP client is # allowed to have smtpd_client_connection_count_limit = 10 # The maximal number of message delivery requests that any client is # allowed to make to this server per time unit. smtpd_client_message_rate_limit = 25 # Limit the number of times RSET can be used smtpd_junk_command_limit = 1 # Limit number of destination address per message smtpd_recipient_limit = 50 # Decrease the client limit for sending the HOor EHLO command smtp_helo_timeout = 60s always_add_missing_headers = yes biff = no enable_long_queue_ids = yes ###### Restrictions 2 # Require HELO or EHLO before commencing a MAIL transaction - RFC 821 smtpd_helo_required = yes # Disable the SMTPD VRFY command # Reduces chance of spammer look for valid address postscreen_disable_vrfy_command = yes disable_vrfy_command = yes # Disable rewrite from user%domain to user@domain allow_percent_hack = no # Disable rewrite from site!user to user@site swap_bangpath = no ###### Slowdown Bad Clients # The maximal number of errors code 500 a remote client is allowed to # make without delivering mail. smtpd_hard_error_limit = 3 # The maximal number or errors code 400, server will delay all responses # using the value from smtpd_error_sleep_time smtpd_soft_error_limit = 1 # Server response delay in seconds after errors smtpd_error_sleep_time = 20 # Mime Header Checks mime_header_checks = pcre:${config_directory}/mime_header_checks # Amavis content_filter = amavisd-new:[127.0.0.1]:10024 ###### Restrictions smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated reject_unauth_destination defer_unauth_destination permit smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_non_fqdn_recipient, reject_non_fqdn_sender, reject_unknown_sender_domain, reject_unknown_recipient_domain, # check_recipient_access pcre:${config_directory}/recipient_checks.pcre, reject_unauth_destination, reject_unauth_pipelining, # Old versions of Microsoft Outlook only send local hostname. reject_non_fqdn_hostname, reject_invalid_hostname, check_helo_access pcre:${config_directory}/helo_checks.pcre, check_sender_mx_access cidr:${config_directory}/bogus_mx, # reject_rbl_client zen.spamhaus.org, reject_rbl_client bl.spamcop.net, # Blocking Google Mails. # reject_rbl_client dnsbl.sorbs.net, #DNS StUFF site # reject_unverified_sender, permit smtpd_data_restrictions = reject_multi_recipient_bounce # reject_unauth_pipelining # permit masquerade_domains = $mydomain masquerade_exceptions = root mailer-daemon notify_classes = data protocol resource software show_user_unknown_table_name = no smtp_dns_support_level = enabled # TLS Settings smtp_enforce_tls = yes smtpd_use_tls = yes smtpd_tls_auth_only = yes smtp_tls_note_starttls_offer = yes # Mandatory (high-grade) TLS encryption #smtp_tls_security_level = encrypt # Allow servers from Internet without encryption devliver mail # Configurado no master.cf smtpd_tls_security_level = may smtp_tls_mandatory_protocols = TLSv1.2 TLSv1.1 smtpd_tls_protocols = TLSv1.2 smtp_tls_ciphers = high smtpd_tls_ciphers = high smtp_tls_mandatory_ciphers = high smtpd_tls_mandatory_ciphers = high smtpd_tls_eecdh_grade = ultra tls_eecdh_strong_curve = prime256v1 tls_eecdh_ultra_curve = secp384r1 smtp_tls_exclude_ciphers = CAMELLIA SEED IDEA RC2 RC4 kSRP kGOST kECDHr kECDHe kDHr kDHd aDSS aPSK aNULL aECDH eNULL EDH-DSS-DES-CBC3-EDH-RSA-DES-CBC3-SHA KRB5-DES CBC3-SHA SHA MEDIUM LOW EXPORT DES MD5 PSK smtp_tls_mandatory_exclude_ciphers = CAMELLIA SEED IDEA RC2 RC4 kSRP kGOST kECDHr kECDHe kDHr kDHd aDSS aPSK aNULL aECDH eNULL EDH-DSS-DES-CBC3-EDH-RSA-DES-CBC3-SHA KRB5-DES CBC3-SHA SHA MEDIUM LOW EXPORT DES MD5 PSK smtpd_tls_exclude_ciphers = CAMELLIA SEED IDEA RC2 RC4 kSRP kGOST kECDHr kECDHe kDHr kDHd aDSS aPSK aNULL aECDH eNULL EDH-DSS-DES-CBC3-EDH-RSA-DES-CBC3-SHA KRB5-DES CBC3-SHA SHA MEDIUM LOW EXPORT DES MD5 PSK smtpd_tls_mandatory_exclude_ciphers = CAMELLIA SEED IDEA RC2 RC4 kSRP kGOST kECDHr kECDHe kDHr kDHd aDSS aPSK aNULL aECDH eNULL EDH-DSS-DES-CBC3-EDH-RSA-DES-CBC3-SHA KRB5-DES CBC3-SHA SHA MEDIUM LOW EXPORT DES MD5 PSK smtpd_tls_dh1024_param_file = ${config_directory}/dh_2048_params.pem smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache smtpd_tls_session_cache_timeout = 6h smtp_tls_fingerprint_digest = sha1 smtpd_tls_fingerprint_digest = sha1 smtp_tls_verify_cert_match = hostname, nexthop, dot-nexthop smtp_tls_secure_cert_match = nexthop smtp_tls_loglevel = 0 smtpd_tls_loglevel = 0 smtpd_client_port_logging = yes smtp_tls_CAfile = /etc/ssl/cert.pem smtpd_tls_CAfile = /etc/ssl/cert.pem smtpd_tls_cert_file = /usr/local/etc/postfix/mail.mywebsite.com.crt smtpd_tls_key_file = /usr/local/etc/postfix/mywebsite.com.privatekey smtpd_tls_received_header = yes openssl_path = /usr/local/bin/openssl tls_daemon_random_bytes = 64 tls_high_cipherlist = ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA tls_medium_cipherlist = EECDH+ECDSA+CHACHA20 EECDH+CHACHA20 EECDH+ECDSA+AESGCM EECDH+AESGCM EECDH+ECDSA+AES256 EECDH+AES256 EECDH+ECDSA+AES128 EECDH+AES128 EECDH+ECDSA+3DES EECDH+3DES EDH+CHACHA20 EDH+AESGCM EDH+AES256 EDH+AES128 EDH+3DES tls_preempt_cipherlist = yes tls_random_bytes = 64 tls_random_source = dev:/dev/random tls_ssl_options = NO_COMPRESSION
我在 FreeBSD 10.3 上,對設置郵件伺服器一無所知,買了一本舊書:No Starch Press - The Book of Postfix,但它太過時了……然後經過許多教程,幾乎完成了我的電子郵件伺服器。
我的第二個問題是在類似郵件的情況下內部傳遞失去,例如:
contact@domain1.com contact@domain2.com
只有一個域收到消息…
我也有鴿舍設置,差不多,呵呵
如果有人能幫我指出正確的方向,我將不勝感激,已經嘗試過 stackExchange 的解決方案但沒有運氣。
如果我在 relay_domains 上使用 SQL 設置我的域,我的伺服器在線上測試中失敗,說現在是一個開放的中繼……
例如,更改 main.cf:
relay_domains = proxy:mysql:/usr/local/etc/postfix/ntsql-virtual-domains.cf
然後我可以從我的 4G 智能手機發送郵件,日誌只是警告不要使用相同的域名兩次,在
relay_domains
和virtual_mailbox_domains
.
看起來您至少嘗試過使 SASL 工作,但看起來產生錯誤的客戶端並沒有嘗試進行身份驗證。我建議確保 smtp 身份驗證工作,確認客戶端配置為進行身份驗證,然後從那裡開始。
您可以通過使用 openssl 客戶端連接到 smtp 送出埠並發送
auth login
命令來手動測試 smtp 身份驗證。openssl s_client -connect localhost:587 -starttls smtp -ign_eof ..... 250 SMTPUTF8 auth login (<-- send login command) 334 VXNlcm5hbWU6 ABCDEF01234 (<-- base64 encoded username) 334 UGFzc3dvcmQ6 ABCDEF01234 (<-- base64 encoded password) 235 2.7.0 Authentication successful quit (<-- disconnect) 221 2.0.0 Bye