vps上にメールサーバ構築
webサービスのアカウント登録などに使うための捨てアドレスが欲しかったので自前でメールサーバ構築。
以下の環境で構築開始。
サーバ | Serversman@vps |
OS | CentOS7.0 |
サーバの設定
本題に入る前にvpsの設定をいじる。
userアカウント作成
sshでrootログイン禁止
SELINUX Disabled
ホスト名変更
iptables設定変更
INPUT DROP
sshのポート穴あけ
Postfixを設定
設定自体はwebに沢山あるので調べながら進める。
今回参考にさせてもらったのは以下のサイト。
centossrv.com
vi /etc/postfix/main.cf ※左の数字は行番号 75 #myhostname = host.domain.tld 76 #myhostname = virtual.domain.tld 77 myhostname = duck-dz.kazika.net ※追記 85 #mydomain = domain.tld 86 mydomain = kazika.net ※追記 101 #myorigin = $myhostname 102 #myorigin = $mydomain 103 myorigin = $mydomain ※追記 117 #inet_interfaces = all 118 #inet_interfaces = $myhostname 119 #inet_interfaces = $myhostname, localhost 120 inet_interfaces = localhost ↓ に変更 117 inet_interfaces = all 118 #inet_interfaces = $myhostname 119 #inet_interfaces = $myhostname, localhost 120 #inet_interfaces = localhost 168 mydestination = $myhostname, localhost.$mydomain, localhost 169 #mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain 170 #mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain, 171 # mail.$mydomain, www.$mydomain, ftp.$mydomain ↓ に変更 168 #mydestination = $myhostname, localhost.$mydomain, localhost 169 mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain 170 #mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain, 171 # mail.$mydomain, www.$mydomain, ftp.$mydomain 422 #home_mailbox = Mailbox 423 #home_mailbox = Maildir/ 424 home_mailbox = Maildir/ ※追記 577 #smtpd_banner = $myhostname ESMTP $mail_name 578 #smtpd_banner = $myhostname ESMTP $mail_name ($mail_version) 579 smtpd_banner = $myhostname ESMTP unknown ※追記
master.cfを編集 #smtp inet n - n - - smtpd ※コメントアウト submission inet n - n - - smtpd ※コメントアウト解除 # -o syslog_name=postfix/submission # -o smtpd_tls_security_level=encrypt -o smtpd_sasl_auth_enable=yes ※コメントアウト解除
各種サービス起動 sasl起動 systemctl start saslauthd systemctl enable saslauthd.service Postfix起動 systemctl restart postfix.service systemctl enable postfix.service ln -s '/usr/lib/systemd/system/postfix.service' '/etc/systemd/system/multi-user.target.wants/postfix.service'
とりあえず以上でサーバからメール送信することはできる。
はまった箇所
サーバから自分のgmailにメール送信したときに遅れない問題
→解決:alternatives --config mta コマンドでデフォルトmailコマンドを変更
- dnsで名前解決ができていなかった
→iptablesでINPUTに53ポートが許可されていなかった
これが原因でyumやcurlが出来なかった
sshでログインする際も遅かった。これはアクセス元のIPアドレスを逆引きしようとしていて、
名前解決できずにタイムアウトしてから次の処理に進むためだった。
ログインしたときに、"Last login: Mon Jul 17 21:24:44 2017 from xxxxx.jp"
これを表示するときのやつ。
- logにipv6関連のメッセージが記載してあった。
→IPv6に対応していないサーバ環境で出るメッセージだった模様。
postfixのmain.cfの"inet_protocols = all"を"inet_protocols = ipv4"に変更