| | 188 | |
| | 189 | == パケットフィルタリング設定 == |
| | 190 | |
| | 191 | iptables は入っていて、動いていたが、肝心要の設定ファイル /etc/sysconfig/iptables が存在しなかった。移転前のサーバーからこのファイルをコピーし、それを適宜修正してから稼働させた。 |
| | 192 | |
| | 193 | 1. /etc/sysconfig/iptables-config の内容を確認。 |
| | 194 | {{{ |
| | 195 | $ sudo su - |
| | 196 | $ vim /etc/sysconfig/iptables-config |
| | 197 | |
| | 198 | # 以下の行が移転前サーバーと異なっていたが、気にせずそのままにした。 |
| | 199 | IPTABLES_MODULES="" |
| | 200 | }}} |
| | 201 | * ちなみに、移転前サーバーではこの行は以下のようになっていた。 |
| | 202 | {{{ |
| | 203 | IPTABLES_MODULES="ip_conntrack_netbios_ns" |
| | 204 | }}} |
| | 205 | * これは iptables 用に読み込むモジュールの指定で、指定できるモジュールは CentOS の場合、以下のようにすることで調べることができる。 |
| | 206 | {{{ |
| | 207 | $ ls /lib/modules/`uname -r`/kernel/net/ipv4/netfilter/ |
| | 208 | }}} |
| | 209 | * ip_conntrack モジュール (接続情報トラッキング) や ip_conntrack_ftp モジュール (ip_nat_ftp と組み合わせて FTP の PASV モードに対応?) なんかはネットで情報が出てくるが、 ip_conntrack_netbios_ns については、読み込みに失敗したから外しました、といったような情報しか出てこなかった。 Windows マシンからの通信絡みなんだろうとは思うんだが…詳細きぼん… さくらの VPN にもこのモジュールは存在するので指定してもエラーにはならないが、何に使うものかも分からないで指定するのも無意味なので外しておくことにした。 |
| | 210 | 1. /etc/sysconfig/iptables を移転前サーバーからコピーする。 |
| | 211 | * まず、移転前サーバーにて。 |
| | 212 | {{{ |
| | 213 | $ sudo cp /etc/sysconfig/iptables . |
| | 214 | $ sudo chown murachi:wheel iptables |
| | 215 | }}} |
| | 216 | * 次に、移転先サーバーにて。 |
| | 217 | {{{ |
| | 218 | $ rsync -ae ssh onaka.harapeko.jp:/home/murachi/iptables . |
| | 219 | $ sudo su - |
| | 220 | $ chown root:root /home/murachi/iptables |
| | 221 | $ mv /home/murachi/iptables /etc/sysconfig/ |
| | 222 | }}} |
| | 223 | 1. /etc/sysconfig/iptables の内容を適宜修正。 |
| | 224 | {{{ |
| | 225 | $ vim /etc/sysconfig/iptables |
| | 226 | |
| | 227 | # Firewall configuration written by system-config-securitylevel |
| | 228 | # Manual customization of this file is not recommended. |
| | 229 | *filter |
| | 230 | :INPUT ACCEPT [0:0] |
| | 231 | :FORWARD ACCEPT [0:0] |
| | 232 | :OUTPUT ACCEPT [0:0] |
| | 233 | :RH-Firewall-1-INPUT - [0:0] |
| | 234 | -A INPUT -j RH-Firewall-1-INPUT |
| | 235 | -A FORWARD -j RH-Firewall-1-INPUT |
| | 236 | -A RH-Firewall-1-INPUT -i lo -j ACCEPT |
| | 237 | -A RH-Firewall-1-INPUT -p icmp --icmp-type any -j ACCEPT |
| | 238 | -A RH-Firewall-1-INPUT -p 50 -j ACCEPT |
| | 239 | -A RH-Firewall-1-INPUT -p 51 -j ACCEPT |
| | 240 | -A RH-Firewall-1-INPUT -p udp --dport 5353 -d 224.0.0.251 -j ACCEPT |
| | 241 | #-A RH-Firewall-1-INPUT -p udp -m udp --dport 631 -j ACCEPT |
| | 242 | #-A RH-Firewall-1-INPUT -p tcp -m tcp --dport 631 -j ACCEPT |
| | 243 | -A RH-Firewall-1-INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT |
| | 244 | # DNS |
| | 245 | -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 53 -j ACCEPT |
| | 246 | -A RH-Firewall-1-INPUT -m state --state NEW -m udp -p udp --dport 53 -j ACCEPT |
| | 247 | # Service applications with TCP: ssh, SMTP, SMTP Submission port, POP3S, HTTP(S) |
| | 248 | -A RH-Firewall-1-INPUT -m state --state NEW -m multiport -p tcp --dports 22,25,587,995,80,443 -j ACCEPT |
| | 249 | # NTP |
| | 250 | -A RH-Firewall-1-INPUT -m state --state NEW -m udp -p udp --dport 123 -j ACCEPT |
| | 251 | # other (reject) |
| | 252 | -A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited |
| | 253 | COMMIT |
| | 254 | }}} |
| | 255 | * ポート 631 (=Internet Printing Protocol) なんて使わないのでコメントアウト。 |
| | 256 | * TCP でしか使わないようなサービス (ssh, SMTP (サブミッションポート含めて), POP3S, HTTP(S)) を multiport モジュールを使って 1行にまとめたらファイルがやたらとコンパクトになって良い感じ。 |
| | 257 | * セキュリティリスクにしかならない FTP と POP3 は未来永劫使う予定無いので思い切って削除。 |
| | 258 | 1. iptables を再起動する。 |
| | 259 | {{{ |
| | 260 | $ /etc/init.d/iptables restart |
| | 261 | }}} |
| | 262 | |
| | 263 | == Postfix 設定 == |
| | 264 | |
| | 265 | メールサーバーは Postfix を使用する。詳細な設定は DNS を有効にし、 SSL を組み込んでからさらに行う。ここではとりあえずインストールと |
| | 266 | |
| | 267 | 1. デフォルトで入っている Sendmail を停止し、二度と起動しないようにする。 |
| | 268 | {{{ |
| | 269 | $ /etc/init.d/sendmail stop |
| | 270 | $ chkconfig --del sendmail |
| | 271 | }}} |
| | 272 | 1. Postfix をインストール。 |
| | 273 | {{{ |
| | 274 | $ sudo su - |
| | 275 | $ yum install postfix |
| | 276 | }}} |
| | 277 | 1. SMTP-AUTH を利用する為、 SASL をインストールする。 |
| | 278 | {{{ |
| | 279 | $ yum install cyrus-sasl |
| | 280 | }}} |
| | 281 | 1. /etc/postfix/main.cf を書き換える。 |
| | 282 | {{{ |
| | 283 | $ vim /etc/postfix/main.cf |
| | 284 | |
| | 285 | # 以下は既存の項目を書き換え。 |
| | 286 | myhostname = developer.harapeko.jp |
| | 287 | inet_interfaces = all |
| | 288 | mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain |
| | 289 | mynetworks_style = host |
| | 290 | home_mailbox = Maildir/ |
| | 291 | |
| | 292 | # (こっちはコメントアウト。 X Window とか使わないし) |
| | 293 | #debugger_command = |
| | 294 | # PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin |
| | 295 | # xxgdb $daemon_directory/$process_name $process_id & sleep 5 |
| | 296 | |
| | 297 | # (こっちのコメントアウトを外す。) |
| | 298 | debugger_command = |
| | 299 | PATH=/bin:/usr/bin:/usr/local/bin; export PATH; (echo cont; |
| | 300 | echo where) | gdb $daemon_directory/$process_name $process_id 2>&1 |
| | 301 | >$config_directory/$process_name.$process_id.log & sleep 5 |
| | 302 | |
| | 303 | # SASL 関連の設定; SSL 証明書を取得するまでコメントアウト |
| | 304 | #smtpd_sasl_auth_enable = yes |
| | 305 | #smtpd_sasl_security_options = noanonymous, noplaintext |
| | 306 | #smtpd_sasl_local_domain = $myhostname |
| | 307 | #smtpd_tls_cert_file = /etc/httpd/conf/developer_harapeko_jp.crt |
| | 308 | #smtpd_tls_key_file = /etc/httpd/conf/developer.harapeko.jp.key.pk |
| | 309 | #smtpd_tls_CApath = /etc/httpd/conf/ |
| | 310 | #smtpd_use_tls = yes |
| | 311 | #smtpd_tls_auth_only = yes |
| | 312 | #smtpd_tls_session_cache_timeout = 3600s |
| | 313 | #smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination |
| | 314 | |
| | 315 | # メールサイズを 10MB に制限 |
| | 316 | message_size_limit = 10485760 |
| | 317 | }}} |
| | 318 | 1. Maildir/ 形式を利用するので、ホームディレクトリスケルトンに Maildir ディレクトリを作成する。 |
| | 319 | {{{ |
| | 320 | $ mkdir -p /etc/skel/Maildir/{new,cur,tmp} |
| | 321 | $ chmod -R 700 /etc/skel/Maildir/ |
| | 322 | }}} |
| | 323 | 1. /etc/postfix/master.cf を書き換える。 |
| | 324 | {{{ |
| | 325 | $ vim /etc/postfix/master.cf |
| | 326 | |
| | 327 | # サブミッションポートを有効にする |
| | 328 | submission inet n - n - - smtpd |
| | 329 | # -o smtpd_sasl_auth_enable=yes # あとで |
| | 330 | }}} |
| | 331 | 1. システムで使用するサーバー機能を Postfix に切り替える。 |
| | 332 | {{{ |
| | 333 | $ alternatives --config mta |
| | 334 | |
| | 335 | There are 2 programs which provide 'mta'. |
| | 336 | |
| | 337 | Selection Command |
| | 338 | ----------------------------------------------- |
| | 339 | *+ 1 /usr/sbin/sendmail.sendmail |
| | 340 | 2 /usr/sbin/sendmail.postfix |
| | 341 | |
| | 342 | Enter to keep the current selection[+], or type selection number: 2 |
| | 343 | }}} |
| | 344 | 1. Postfix を起動し、問題なければサーバー起動時に自動起動するよう設定する。 |
| | 345 | {{{ |
| | 346 | $ /etc/init.d/postfix check |
| | 347 | $ /etc/init.d/postfix start |
| | 348 | $ chkconfig --add postfix |
| | 349 | }}} |
| | 350 | |
| | 351 | |
| | 352 | |
| | 353 | |
| | 354 | 1. /usr/lib/sasl2/smtpd.conf を作成する。 |
| | 355 | {{{ |
| | 356 | $ vim /usr/lib/sasl2/smtpd.conf |
| | 357 | |
| | 358 | pwcheck_method: auxprop |
| | 359 | auxprop_plugin: sasldb |
| | 360 | mech_list: cram-md5 digest-md5 |
| | 361 | }}} |