2010/08/05 13:58
iptablesの設定は再起動で消えてしまう為、設定用シェルスクリプトを作成してシステム起動時に実行する。ただし、今回はサーバ運用を想定しての設定。
# /sbin/chkconfig --level 2345 iptables on
# vi /root/iptables.sh
#!/bin/bash # 設定をクリア iptables -F # 受信を全て破棄 iptables -P INPUT DROP # 送信を全て許可 iptables -P OUTPUT ACCEPT # 通過を全て破棄 iptables -P FORWARD DROP # ICMPを許可 iptables -A INPUT -p icmp -j ACCEPT # ローカルホストからの通信を許可 iptables -A INPUT -i lo -j ACCEPT # ローカルエリアからの通信を許可 iptables -A INPUT -s (ローカルエリアのアドレス) -j ACCEPT # 自分が出したリクエストに対して戻ってきた通信は許可 iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT # ブロードキャストアドレス,マルチキャストアドレス宛のパケットを破棄 iptables -A INPUT -d 255.255.255.255 -j DROP iptables -A INPUT -d 224.0.0.1 -j DROP # SSHの許可 iptables -A INPUT -p tcp --dport 22 -j ACCEPT # ローカルエリアからのNetBIOS(Samba)の許可 iptables -A INPUT -d (ローカルエリアのアドレス) -p tcp --dport 139 -j ACCEPT iptables -A INPUT -d (ローカルエリアのアドレス) -p udp --dport 137 -j ACCEPT iptables -A INPUT -d (ローカルエリアのアドレス) -p udp --dport 138 -j ACCEPT # HTTPの許可 iptables -A INPUT -p tcp --dport 80 -j ACCEPT # HTTPSの許可 iptables -A INPUT -p tcp --dport 443 -j ACCEPT # 上記のルールにマッチしなかったパケットをログに記録して破棄 iptables -A INPUT -m limit --limit 1/s -j LOG --log-prefix "[IPTABLES INPUT] : " iptables -A INPUT -j DROP iptables -A FORWARD -m limit --limit 1/s -j LOG --log-prefix "[IPTABLES FORWARD] : " iptables -A FORWARD -j DROP # 設定の保存 service iptables save # iptablesの再起動 service iptables restart
# chmod 700 /root/iptables.sh
# vi /etc/rc.d/rc.local
#起動時に iptables を設定 sh /root/iptables.sh
2010/08/05 13:11
# mkdir /ssl
# cd /etc # openssl md5 * > /ssl/rand.dat
※ここでは/etcのmd5ハッシュ値付きファイル一覧を乱数データとして使用
# openssl genrsa -des3 -out /ssl/server.key -rand /ssl/rand.dat 1024
Generating RSA private key, 1024 bit long modulus ........++++++ ......++++++ e is 65537 (0x10001) Enter pass phrase for /ssl/server.key:(サーバ鍵用のパスフレーズを入力) Verifying - Enter pass phrase for /ssl/server.key:(サーバ鍵用のパスフレーズを入力)
※CA鍵(ca.key)作成時のパスワードとは異なるものにする
# openssl req -new -key /ssl/server.key -out /ssl/server.csr
Enter pass phrase for /etc/httpd/conf/ssl/server.key:(サーバ鍵用のパスフレーズを入力) 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) [GB]:(国コード) State or Province Name (full name) [Berkshire]:(都道府県名) Locality Name (eg, city) [Newbury]:(市町村名) Organization Name (eg, company) [My Company Ltd]:(組織名) Organizational Unit Name (eg, section) []:(組織でのユニット名) Common Name (eg, your name or your server's hostname) []:(ドメイン名またはIPアドレス) Email Address []:(管理者のメールアドレス) Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []:(入力せずEnter) An optional company name []:(入力せずEnter)
# openssl genrsa -des3 -out /ssl/ca.key -rand /ssl/rand.dat 1024
Generating RSA private key, 1024 bit long modulus ........++++++ ......++++++ e is 65537 (0x10001) Enter pass phrase for /ssl/ca.key:(CA鍵用のパスフレーズを入力) Verifying - Enter pass phrase for /ssl/ca.key:(CA鍵用のパスフレーズを入力)
※サーバ鍵(server.key)作成時のパスワードとは異なるものにする
# openssl req -new -x509 -days 365 -key /ssl/ca.key -out /ssl/ca.crt
Enter pass phrase for ca.key:(CA鍵用のパスフレーズを入力) 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) [GB]:(国コード) State or Province Name (full name) [Berkshire]:(都道府県名) Locality Name (eg, city) [Newbury]:(市町村名) Organization Name (eg, company) [My Company Ltd]:(組織名) Organizational Unit Name (eg, section) []:(組織でのユニット名) Common Name (eg, your name or your server's hostname) []:(ドメイン名またはIPアドレス) Email Address []:(管理者のメールアドレス)
wget (mod_sslのURL)
# tar xvzf mod_ssl-(バージョン).tar.gz # cp /ssl/mod_ssl-(バージョン)/pkg.contrib/sign.sh /ssl # rm -rf /ssl/mod_ssl-(バージョン) # rm -rf /ssl/mod_ssl-(バージョン).tar.gz
# sh /ssl/sign.sh /ssl/server.csr
CA signing: server.csr -> server.crt: Using configuration from ca.config Enter pass phrase for ./ca.key:(CA鍵用のパスフレーズを入力) Check that the request matches the signature Signature ok The Subject's Distinguished Name is as follows countryName :PRINTABLE:'(国コード)' stateOrProvinceName :PRINTABLE:'(都道府県名)' localityName :PRINTABLE:'(市町村名)' organizationName :PRINTABLE:'(組織名)' organizationalUnitName:ASN.1 12:'(組織でのユニット名)' commonName :PRINTABLE:'(ドメイン名またはIPアドレス)' emailAddress :IA5STRING:'(管理者のメールアドレス)' Certificate is to be certified until (有効期限の日時) GMT (365 days) Sign the certificate? [y/n]:(y) 1 out of 1 certificate requests certified, commit? [y/n](y) Write out database with 1 new entries Data Base Updated CA verifying: server.crt <-> CA cert server.crt: OK
# cd /ssl # chmod -c -R 400 server.* ca.* rand.dat
# mkdir /etc/httpd/ssl.key # cp -r /ssl/* /etc/httpd/ssl.key
# yum -y install mod_ssl # vi /etc/httpd/conf.d/ssl.conf
SSLCertificateFile /etc/httpd/ssl.key/server.crt SSLCertificateKeyFile /etc/httpd/ssl.key/server.key
# cp /ssl/server.key /ssl/server.key.org # openssl rsa -in /ssl/server.key.org -out /ssl/server.key
# /sbin/service httpd restart
※今回の作成方法では有効期限はそれぞれ1年間であり、1年後に同様の作業を行う必要がある
2010/08/05 09:46
標準のリポトロジにはClamAVのrpmが用意されていないので、
を参考にしてDAG(rpmforge)リポトロジを追加しておく。
yum --enablerepo=dag -y install clamd
vi /etc/clamd.conf
ClamAVをroot権限で実行,ウイルス定義ファイルを日本のサーバから入手
#User clamav DatabaseMirror db.jp.clamav.net
/etc/rc.d/init.d/clamd start
chkconfig clamd on
sed -i 's/Example/#Example/g' /etc/freshclam.conf
freshclam
2010/08/05 09:41
wget http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt
rpm --import RPM-GPG-KEY.dag.txt
rm -f RPM-GPG-KEY.dag.txt
vi /etc/yum.repos.d/dag.repo
[dag] name=Dag RPM Repository for Red Hat Enterprise Linux baseurl=http://apt.sw.be/redhat/el5/en/i386/dag/ gpgcheck=1 enabled=0
yum --enablerepo=dag install (パッケージ名)
2010/05/04 18:58