3流プログラマのメモ書き

元開発職→社内SE→派遣で営業支援の三流プログラマのIT技術メモ書き。 このメモが忘れっぽい自分とググってきた技術者の役に立ってくれれば幸いです。(jehupc.exblog.jpから移転中)

FCサーバ構築 二章追記

///////////ファイアウォール関連//////////////////

今回のサーバ構築においてのネットワーク要求

pingを打てる。

・内部LANからssh(ポート変更後の)でのアクセス許可

・http(ポート80)でのアクセス許可

・内部LANからのDNS(ポート53)問い合わせ許可

・外部DNS問い合わせを許可

FTP(20,21,4000-4029)へのアクセス許可

・外部FTP(20,21)へのアクセス許可

SMTP(25,465)へのアクセス許可

・外部メールサーバ(SMTP:25,POP3:110)へのアクセス許可

・POP(110,995),IMAP(143,993)へのアクセス許可

上をふまえて、@ITとパソコンおやじのWebサイトをベースに作ったのが以下のスクリプトです。

******************************************

#! /bin/sh

# ver 1.0

trusthost='192.168.0.0/24'

myhost='192.168.0.128'

any='0.0.0.0/0'

##############

#Flush & Reset

##############

iptables -F

iptables -X

##############

#Deafult Rule

##############

iptables -P INPUT DROP

iptables -P OUTPUT DROP

iptables -P FORWARD DROP

#########

#loopback

#########

iptables -A INPUT -i lo -j ACCEPT

iptables -A OUTPUT -o lo -j ACCEPT

#######################

#ICMP trusthost->myhost

#######################

iptables -A INPUT -p icmp --icmp-type echo-request -s $trusthost -d $myhost -j ACCEPT

iptables -A OUTPUT -p icmp --icmp-type echo-reply -s $myhost -d $trusthost -j ACCEPT

#######################

#ICMP myhost->trusthost

#######################\

iptables -A OUTPUT -p icmp --icmp-type echo-request -s $myhost -d $trusthost -j ACCEPT

iptables -A INPUT -p icmp --icmp-type echo-reply -s $trusthost -d $myhost -j ACCEPT

#######################

#ssh trusthost-> myhost

#######################

iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP

iptables -A INPUT -p tcp -m state --state NEW,ESTABLISHED,RELATED -s $trusthost -d $myhost --dport 55022 -j ACCEPT

iptables -A OUTPUT -p tcp -s $myhost --sport 55022 -d $trusthost -j ACCEPT

#################

#www ANY-> myhost

#################

iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP

iptables -A INPUT -p tcp -m state --state NEW,ESTABLISHED,RELATED -s $any -d $myhost --dport 80 -j ACCEPT

iptables -A OUTPUT -p tcp -s $myhost --sport 80 -d $any -j ACCEPT

#################

#dns trusthost-> myhost

#################

iptables -A INPUT -p udp -s $trusthost --dport 53 -j ACCEPT

iptables -A OUTPUT -p udp -d $trusthost --sport 53 -j ACCEPT

iptables -A INPUT -p tcp -m state --state NEW -s $trusthost --dport 53 -j ACCEPT

iptables -A OUTPUT -p tcp -s $myhost --sport 53 -d $trusthost -j ACCEPT

#################

#dns myhost-> any

#################

iptables -A OUTPUT -p udp --dport 53 -j ACCEPT

iptables -A INPUT -p udp --sport 53 -j ACCEPT

iptables -A OUTPUT -p tcp -m state --state NEW --dport 53 -j ACCEPT

iptables -A INPUT -p tcp -s $any --sport 53 -d $myhost -j ACCEPT

#################

#ftp any-> myhost

#################

iptables -A INPUT -p tcp -m state --state NEW,ESTABLISHED,RELATED -s $any -d $myhost --dport 21 -j ACCEPT

iptables -A INPUT -p tcp -m state --state NEW,ESTABLISHED,RELATED -s $any -d $myhost --dport 4000:4029 -j ACCEPT

iptables -A OUTPUT -p tcp -m state --state NEW,ESTABLISHED,RELATED -s $myhost -d $any --sport 20 -j ACCEPT

#################

#ftp myhost-> any

#################

iptables -A OUTPUT -p tcp -m state --state NEW,ESTABLISHED,RELATED -s $myhost -d $any --dport 21 -j ACCEPT

iptables -A INPUT -p tcp -m state --state NEW,ESTABLISHED,RELATED -s $any -d $myhost --sport 20 -j ACCEPT

#################

#smtp any-> myhost

#################

iptables -A INPUT -p tcp -m state --state NEW,ESTABLISHED,RELATED --dport 25 -j ACCEPT

iptables -A INPUT -p tcp -m state --state NEW,ESTABLISHED,RELATED --dport 465 -j ACCEPT

#################

#smtp myhost-> any

#################

iptables -A OUTPUT -p tcp -m state --state NEW,ESTABLISHED,RELATED --dport 25 -j ACCEPT

iptables -A OUTPUT -p tcp -m state --state NEW,ESTABLISHED,RELATED --dport 110 -j ACCEPT

#################

#smtp any(trusthost)-> myhost

#################

iptables -A INPUT -p tcp -m state --state NEW,ESTABLISHED,RELATED -s $trusthost --dport 110 -j ACCEPT

iptables -A INPUT -p tcp -m state --state NEW,ESTABLISHED,RELATED -s $trusthost --dport 143 -j ACCEPT

iptables -A INPUT -p tcp -m state --state NEW,ESTABLISHED,RELATED --dport 993 -j ACCEPT

iptables -A INPUT -p tcp -m state --state NEW,ESTABLISHED,RELATED --dport 995 -j ACCEPT

#########

#logging

#########

iptables -N LOGGING

iptables -A LOGGING -j LOG --log-level warning --log-prefix "DROP:" -m limit

iptables -A LOGGING -j DROP

iptables -A INPUT -j LOGGING

iptables -A OUTPUT -j LOGGING

******************************************

1.ファイアウォール停止

 service iptables stop

2.上記シェルスクリプトをディスクに保存して実行し、ルール適用

3設定をセーブ

./etc/init.d/iptables save

4.iptables を再起動

service iptables restart

これでたぶんできたはずかと。。。

テストあんましてないので不安です。。

まぁ違っていれば後から訂正ということでw