2013/08/18

centos 6 設定 postfix

環境:Centos 6.4 ×86_64
目標:SSLを使用してメーラーからメールサーバまでの経路暗号化を行う
目標:SMTPSIMAPSを使用して送受信を行う
参考:http://morizyun.github.io/blog/postfix-centos-sakura-vps-aws/参考:http://ascii.jp/elem/000/000/431/431263/
postfixインストール
#yum install postfix 
自己署名証明書の作成(SSL用)
key 秘密鍵
csr 証明書要求(証明書と所有者情報)
crt 電子証明書
# cd /etc/pki/tls/certs/秘密鍵を作成
# make server.key
umask 77 ; \
/usr/bin/openssl genrsa -aes128 2048 > server.key
Generating RSA private key, 2048 bit long modulus
………………………………………………………………………………………….+++
………………………………………………………………………………………+++
e is 65537 (0x10001)
Enter pass phrase: 秘密鍵のパスワード設定
Verifying – Enter pass phrase: 秘密鍵のパスワード設定再入力
# openssl rsa -in server.key -out server.key
Enter pass phrase for server.key: 秘密鍵のパスワード入力
writing RSA key

# make server.csr

umask 77 ; \
/usr/bin/openssl req -utf8 -new -key server.key -out server.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter ‘.’, the field will be left blank.
—–
Country Name (2 letter code) [XX]: 空白エンター
State or Province Name (full name) : 空白エンター
Locality Name (eg, city) [Default City]: 空白エンター
Organization Name (eg, company) [Default Company Ltd]: 空白エンター
Organizational Unit Name (eg, section)
: 空白エンター
Common Name (eg, your name or your server’s hostname) :example.com
Email Address
: 空白エンター
Please enter the following ‘extra’ attributes
to be sent with your certificate request
A challenge password : 空白エンター
An optional company name
: 空白エンター
# openssl x509 -in server.csr -out server.crt -req -signkey server.key -days 3650
Signature ok
subject=/C=XX/L=Default City/O=Default Company Ltd/CN=example.com
Getting Private key
# chmod 400 server.*
postfixの設定
# vi /etc/postfix/main.cf myhostname = mail.example.commydomain = example.commyorigin = $mydomainhome_mailbox = Maildir/smtpd_banner = $myhostname ESMTP unknown
message_size_limit = 10485760
SMTP-Auth系の設定
disable_vrfy_command = yes
smtpd_sasl_auth_enable = yes
broken_sasl_auth_clients = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostnamesmtpd_sender_restrictions = reject_unknown_sender_domain
smtpd_client_restrictions = permit_mynetworks,reject_unknown_client,permit
smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination
TLS を利用するために自己証明書を指定 smtpd_tls_cert_file = /etc/pki/tls/certs/server.crt smtpd_tls_key_file = /etc/pki/tls/certs/server.key smtpd_use_tls = yes # 外部からのメール受信を許可
inet_interfaces = all
# ipv4に限定
inet_protocols = ipv4
# 自ドメイン宛メールを受信できるようにするmydestination = $myhostname, localhost.$mydomain, localhost$mydomain
smtps(465)を使用するために#を外す
# vi /etc/postfix/master.cf
smtps inet n – n – – smtpd
-o smtpd_tls_wrappermode=yes
-o smtpd_sasl_auth_enable=yes
-o smtpd_client_restrictions=permit_sasl_authenticated,reject
-o milter_macro_daemon_name=ORIGINATING
smtp-authの設定で下記に書き換え
# vi /etc/sasl2/smtpd.conf 
pwcheck_method: auxprop
auxprop_plugin: sasldb
mech_list: plain login
saslauthd起動
# /etc/rc.d/init.d/saslauthd start
saslauthd を起動中: [ OK ]
# chkconfig saslauthd on
# chkconfig –list saslauthd

saslauthd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
dovecotのインストール
# yum install dovecot 
SSLの設定 
# vi /etc/dovecot/conf.d/10-ssl.conf
 
ssl_cert = ssl_key = ssl = yesssl_key_password = “証明書作成時のPASSWORD”
認証設定
# vi /etc/dovecot/conf.d/10-auth.conf
auth_mechanisms = plain login
ポート設定
# vi /etc/dovecot/conf.d/10-master.confservice imap-login {  inet_listener imap {    port = 143  }  inet_listener imaps {    port = 993    ssl = yes  }}
メールの保存場所を設定
# vi /etc/dovecot/conf.d/10-mail.conf
 
mail_location = maildir:~/Maildirvalid_chroot_dirs = /home
プロトコルの設定
# vi /etc/dovecot/dovecot.conf
protocols = imap lmtp
listen = * 
・新規ユーザーのメールボックス作成
# mkdir -p /etc/skel/Maildir/{new,cur,tmp} # chmod -R 700 /etc/skel/Maildir/ 
新規ユーザーの追加# useradd -s /sbin/nologin ユーザー名# passwd ユーザー名
DBへの登録とSMTPパスワード設定
# saslpasswd2 -u mail.example.com ユーザー名
DBから削除する場合
# saslpasswd2 -u mail.example.com -d ユーザー名
設定の確認# sasldblistusers2  > ユーザー名@mail.example.com: ユーザーパスワード
認証DBの所有権変更
# chgrp postfix /etc/sasldb2 
既存ユーザーのメールボックスの設定# mkdir /home/ユーザー名/Maildir# chmod 700 /home/ユーザー名/Maildir# chown ユーザー名:ユーザーグループ /home/ユーザー名/Maildir
postfix起動# /etc/rc.d/init.d/postfix start# chkconfig postfix on# chkconfig –list postfix   > postfix 0:off 1:off 2:on 3:on 4:on 5:on 6:off
dovecot起動
# /etc/rc.d/init.d/dovecot start
Dovecot Imap を起動中: [ OK ]
# chkconfig dovecot on
# chkconfig –list dovecot

dovecot 0:off 1:off 2:on 3:on 4:on 5:on 6:off
iptablesでメールが送受信出来るように設定
SMTP:TCP:25
SMTPS:TCP:465
IMAPS:TCP:993 
・STARTTLSとover SSLの違い
TARTTLSSMTPPOP3で通信を始めて途中でSSLに切り換える方式
SMTPPOP3 over SSLは最初からSSLによって
SMTPPOP3を「くるんだ」状態で通信を始める方式
DNS設定
宛先がXXX@example.comのメールはmail.example.comサーバへ送るように設定
#vi /var/named/chroot/var/named/XXXX.zone
         IN MX 10 mail.example.com.
mail IN A         XXX.XXX.XXX.XXX
mail.example.comでもexample.comでもメールが送れる理由
メールは複数のメールサーバを経由して目的のユーザーのメールボックスに送られる。
中継するサーバは配送先のメールサーバを宛先のメールアドレスから判断する。
DNSを使用して配送先のメールサーバを検索する。
DNSのMXレコードを利用して、
メールアドレスの[@]よりも後ろのドメイン名をキーにして
MXレコードを検索して配送先のメールサーバを知ることが出来る。
下記の場合は、mail.example.comのメールサーバへ転送する
example.comをキーにしてMXレコードを引く。
②MXレコードに含まれているサーバのAレコードとネームサーバのAレコードを引く。
③そのAレコードを頼りに配送先のサーバへ転送する。

2013/08/16

メールのメモ

メール送受信の概念を自分なりにちょっとしたまとめ
各Agentの説明
MUA
メールを送信したり受信したりするクライアントソフト
ex:outlook,thunderbirdなど
MSA
MUAからメールの送信を受け取る前に認証するプログラム
ex:SMTP-AUTH,POP before SMTP
MTA
メールを実際に転送(送受信)するプログラム
MSAや他のMTAからのメールを受取って、他のMTAやMDAへ転送するプログラム
DNSで提供されるMXの情報を用いて宛先を決定する
ex:postfix,qmail,sendmail
MDA
MTAからメールを受取ってユーザーそれぞれのメールボックスに保存するプログラム
ex:postfix,qmail.sendmail,procmail,maildrop
MRA
MUAがメールボックスからメールを読み出すときに接続するプログラム
ex:POPサーバ,IMAPサーバ,Dovecot
※submissionポートについて
スパム対策として各ISPsmtpポートを25番から587番に変更。
同じISP内でのメール送信はポート25番でも587番へ送信でもok。
送信元のISPと転送先や宛先のISPが違う場合はポート587番へ送信。
転送元と転送先のISPが別でもMTAからMTAの転送はポート25番を使用。
例1:ISP1のカツオのMUAからISP4のポート25番へメールの転送はブロックされる。
例2:ISP4のサザエのMUAからISP4のポート25番へのメール送信は出来る。
例3:ISP4のMTAからISP5のMTAへのメール転送は出来る。







フネ->波平
①フネから波平へMUAを使ってメールを送る
②MSAでフネの認証を行う
③宛先はこのISP4内のサーバのためMDAへ転送する
④波平のメールボックスに入れる
フネ->ワカメ
①フネからワカメ宛にMUAを使ってメールを送る
②MSAでフネの認証を行う
③宛先がISP5内のサーバのためそのMTAへ転送する。
MDAへ転送してワカメのメールボックスに入れる
波平
MUAを使ってMRAへ接続する
②新着メールをメールボックスから取り出す
③フネからのメールを読む
ワカメ
MUAを使ってMRAへ接続する
②新着メールをメールボックスから取り出す
③フネからのメールを読む


SSLのメモ

SSL/TLSの概念を自分なりにちょっとしたまとめ
・インターネット上で情報を暗号化して送受信するプロトコルの1つ









①クライアントからサーバへ接続要求を出す
②サーバは公開鍵を含むサーバ証明証をクライアントに送る
サーバ証明書を確認する
④CA電子署名Webブラウザ内蔵の公開鍵で復号化して
 サーバの身元保証と公開鍵の改ざんがないことを確認する
⑤自己署名であればWebブラウザ内蔵の公開鍵がないので
 サーバの身元保証と公開鍵の改ざんがないかわからないので警告が出る
⑥暗号化通信用の共通鍵を作成する
⑦サーバの公開鍵で⑥の共通鍵を暗号化する
⑧暗号化した共通鍵を送る
⑨サーバの秘密鍵で送られてきた共通鍵を復号化する
⑩共通鍵で暗号化通信開始
⑪通信終了後は共通鍵を破棄する
※ハイブリッド暗号化方式
秘密鍵と共通鍵を組み合わせた方法で暗号化すること

2013/08/15

電子証明書のメモ

証明書の概念を自分なりにちょっとしたまとめ
・証明書でできること
Aさん本人が送ったことを証明し
そのデータが偽造・改ざんされていないことを証明する 。















電子証明書の作成
①Aさんが秘密鍵と公開鍵のペアを作成する
②③認証局(CA)にAさんの公開鍵とAさんの情報を提出する
認証局がAさんの情報が正しいか確認する
⑤Aさんの情報に問題なければ認証局秘密鍵
 Aさんの公開鍵とAさんの所有者情報にそれぞれ電子署名する
 Aさんの電子証明書の完成
データ送信
送りたいデータをハッシュ関数を使ってハッシュ値を出す
Aさんの秘密鍵を使用してハッシュ値を暗号化して署名する
データとAさんの証明書との署名をセットで送信する
データを受信
認証局電子署名認証局の公開鍵を使って
 Aさんの公開鍵と所有者情報の有用性を確認。
有用性が確認できたらAさんの公開鍵を使って
 データの電子署名を復号化してハッシュ値を取り出す
受信したデータをハッシュ関数ハッシュ値を出して
ハッシュ値を比較して一致するか確認する
電子署名とは
データをハッシュ関数を 使ってハッシュ値を出して
それを秘密鍵で暗号化したもの
・ハッシュとは
データをハッシュ関数という 変換アルゴリズムを使って
一定の長さに変換したもの。
データ内容が変わると 大幅にハッシュ値が変わるため
改ざんされているかどうか確認ができる

2013/06/24

centos 6 設定 netflowanalyzer

1812Jの監視のため無料版をインストール

・Netflow Analyzer
NetFlow Analyzerを登録してダウンロード
http://www.manageengine.jp/products/NetFlow_Analyzer/ 
NetFlow Analyzerをインストール
#mv ./ManageEngine_NetFlowAnalyzer_9800_64bit.bin /usr/loca/bin/
#cd /usr/local/bin
#chmod +x ManageEngine_NetFlowAnalyzer_9800_64bit.bin
#./ManageEngine_NetFlowAnalyzer_9800_64bit.bin 
ウィザードに従って進めていく(E-mailは必須)
起動確認
#cd /opt/ManageEngine/NetFlow/bin
#./run.sh
サービス登録
#./linkAsService.sh
#/etc/rc.d/init.d/netflowanalyzer start
iptablesの設定
TCP:9996,8080 UDP:9996
webブラウザから、http://localhost:8080へアクセス
パスワードを変更する
・1812J側の設定
Dialer1のinterfaceを有効
1812J(config)#interface Dialer 1
1812J(config-if)#ip route-cache flow
1812J(config-if)#ip flow ingress
1812J(config-if)#ip flow egress
Fa1のinterfaceを有効
1812J(config)#interface fastEthernet 1
1812J(config-if)#ip route-cache flow
1812J(config-if)#ip flow ingress
1812J(config-if)#ip flow egress
送信元インターフェース設定
1812J(config)#ip flow-export source FastEthernet1送信先のnetflowanalyzerのIPとポートを指定
1812J(config)#ip flow-export destination 192.168.1.XXX 9996netflowのバージョンを指定
1812J(config)#ip flow-export version 5長時間のフローを1分刻みに分割する
1812J(config)#ip flow-cache timeout active 1
インターフェース名が正しく表示される様にsnmpを指定する
1812J(config)#snmp-server ifindex persist
1812J(config)#snmp-server community public RO
グラフに表示される□□□を日本語に表示させる
# cd /opt/ManageEngine/NetFlow/jre/lib/fonts/
# mkdir fallback/
# cd fallback/
# ln -s /usr/share/fonts/vlgothic/VL-Gothic-Regular.ttf ./

2013/06/23

centos 6 設定 zabbix-server agent

環境:CentOS 6.4 ×86_64
参考:http://kodai74.blogspot.jp/2013/03/zabbix.html
zabbix SIAからインストール
・zabbix-serverインストール
#rpm -ivh http://repo.zabbix.com/zabbix/2.0/rhel/6/x86_64/zabbix-release-2.0-1.el6.noarch.rpm#yum install zabbix-agent zabbix-server-mysql zabbix-web-mysql zabbix-web-japanese
#yum install mysql-server#vi /etc/my.cnf  以下5つを[mysqld]以下に追加
[mysqld]
innodb_file_per_table
innodb_buffer_pool_size=512M
innodb_log_file_size=64M
default-character-set = utf8
skip-character-set-client-handshake
#service mysqld start
#mysqld -u root
mysql> create database zabbix character set utf8;
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by ‘パスワード’;
mysql>exit
# mysql -u root zabbix < /usr/share/doc/zabbix-server-mysql-2.0.6/create/schema.sql
# mysql -u root zabbix < /usr/share/doc/zabbix-server-mysql-2.0.6/create/images.sql
# mysql -u root zabbix < /usr/share/doc/zabbix-server-mysql-2.0.6/create/data.sql 
#vi /etc/zabbix/zabbix_server.conf
DBPassword=パスワード
#service zabbix-server start
#service zabbix-agent  start 
#vi /etc/httpd/conf.d/zabbix.conf  コメント外してAsia/Tokyoに変更
php_value date.timezone Asia/Tokyo
# service httpd start 
Webブラウザからhttp://localhost/zabbixへアクセス
ウィザードにしたがって進めていく
Sign in  ->  Username:admin Password:zabbix
Profileからパスワードと言語を変更する 
あとはzabbix-serverをweb上で有効にして監視開始。

centos 6 設定 ssh iptables selinux

環境:CentOS6.4 ×86_64
SSH
sshのポート番号変更とPassword認証不可とRootlogin不可に設定
#vi /etc/ssh/sshd_configPort 22 -> Port 任意の番号(10022)
PasswordAuthentication yes -> no
PermitRootLogin no -> yes
#service sshd restart
authorized_keysを設定
$mkdir .ssh
$chmod 700 .ssh
$vi .ssh/authorized_keys

クライアントで作成したid_rsa.pubを転送して中身をコピペ
$chmod 600 .ssh/authorized_keys
 
iptables
iptablesを設定
#vi iptables-set.sh#!/bin/bash
# フィルタリングルールを消去する
/sbin/iptables -F
# デフォルトポリシーを設定(最初にすべてのポリシーをDROPに設定)
/sbin/iptables -P INPUT DROP
/sbin/iptables -P FORWARD DROP
/sbin/iptables -P OUTPUT DROP
# ループバックを許可する
/sbin/iptables -A INPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT
/sbin/iptables -A OUTPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT
# プライベートアドレスが使われているパケットを破棄
/sbin/iptables -A INPUT -i eth0 -s 10.0.0.0/8 -j DROP
/sbin/iptables -A INPUT -i eth0 -d 10.0.0.0/8 -j DROP
/sbin/iptables -A INPUT -i eth0 -s 172.16.0.0/12 -j DROP
/sbin/iptables -A INPUT -i eth0 -d 172.16.0.0/12 -j DROP
# 基本サービスを許可, SSH
/sbin/iptables -A INPUT -p tcp -m state –state NEW -m tcp –dport 10022 -j ACCEPT
# すでにコネクションを確立しているものは許可
/sbin/iptables -A INPUT -m state –state RELATED,ESTABLISHED -j ACCEPT
# Ping of Death対策
/sbin/iptables -A INPUT -p icmp –icmp-type echo-request -m limit –limit 1/s -j ACCEPT
# 外への接続は全て許可
/sbin/iptables -P OUTPUT ACCEPT
# 保存 + iptables再起動
/etc/init.d/iptables save
/etc/init.d/iptables restart
# 設定が適用されているか確認
/sbin/iptables -L
iptablesの確認
#iptables -L Chain INPUT (policy DROP)
target prot opt source destination
ACCEPT all — localhost localhost
DROP all — 10.0.0.0/8 anywhere
DROP all — anywhere 10.0.0.0/8
DROP all — 172.16.0.0/12 anywhere
DROP all — anywhere 172.16.0.0/12
ACCEPT tcp — anywhere anywhere state NEW tcp dpt:10022
ACCEPT all — anywhere anywhere state RELATED,ESTABLISHED
ACCEPT icmp — anywhere anywhere icmp echo-request limit: avg 1/sec burst 5
Chain FORWARD (policy DROP)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all — localhost localhost
iptablesのfilterテーブルは、
chainがINPUT,OUTPUT,FORWARDの3つあって
それぞれに全体のポリシー(ACCEPT/DROP)を指定して
必要があれば個別にACCEPT/DROPをする。 

selinux
一時設定(Enforcing:有効/Permissive:警告のみ/disabled:無効)
#getenforce
Enforcing
#setenforce 0
# getenforce

Permissive
設定
# vi /etc/selinux/config
SELINUX=disabled

L2TP/IPSEC-VPN IX2025 リモートアクセス.

リモートアクセス VPN テスト シナリオ 想定1:インターネット VPN を使用したリモートアクセス VPN 想定2: VPN 構築後に iphone からインターネットに接続する 機器: NEC  IX2025(8.11.11) と iphone 目標1: LTE 通信の i...