スティーブジョブスに俺はなる!!

毎日全力を出し切り、自分史上最高を出し続けたい!

1からLinuxに本番環境の設定をする CentOS(3)iptable logwatch

ここまでで、サーバへの接続は以下のコマンドによるものとなっているはずである。

ssh yyy@xxx.xxx.xxx.xxx -i /Users/spacenet/.ssh/id_rsa -p zzzzz

 

yyyはサーバ上のユーザ名 xxx.xxx.xxx.xxxはサーバのIPアドレス zzzzzはssh接続用ポート番号

iptablesがインストールされている事を確認

$ yum list installed | grep iptable

iptables.x86_64                    1.4.7-14.el6                     @base       

iptables-ipv6.x86_64               1.4.7-14.el6                     @base    

target     prot opt source               destination         

 

現在の設定を確認する

$ sudo iptables -L

Chain INPUT (policy ACCEPT)

Chain FORWARD (policy ACCEPT)

target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)

target     prot opt source               destination

sudo vi /etc/sysconfig/iptables

 

以下の内容に置き換え

重要:zzzzzの部分をssh用のポート番号に変換するのを忘れずに

 

# Firewall configuration written by system-config-firewall

# Manual customization of this file is not recommended.

*filter

:INPUT   ACCEPT [0:0]

:FORWARD ACCEPT [0:0]

:OUTPUT  ACCEPT [0:0]

:RH-Firewall-1-INPUT - [0:0]

 

-A INPUT -j RH-Firewall-1-INPUT

-A FORWARD -j RH-Firewall-1-INPUT

-A RH-Firewall-1-INPUT -i lo -j ACCEPT

-A RH-Firewall-1-INPUT -p icmp --icmp-type any -j ACCEPT

-A RH-Firewall-1-INPUT -p 50 -j ACCEPT

-A RH-Firewall-1-INPUT -p 51 -j ACCEPT

-A RH-Firewall-1-INPUT -p udp --dport 5353 -d 224.0.0.251 -j ACCEPT

-A RH-Firewall-1-INPUT -p udp -m udp --dport 631 -j ACCEPT

-A RH-Firewall-1-INPUT -p tcp -m tcp --dport 631 -j ACCEPT

-A RH-Firewall-1-INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

 

# SSH, HTTP

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport zzzzz -j ACCEPT

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80    -j ACCEPT

 

-A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited

 

COMMIT

 

iptablesを再起動して設定を反映させる

$ sudo service iptables restart

iptables: Setting chains to policy ACCEPT: filter          [  OK  ]

iptables: Flushing firewall rules:                         [  OK  ]

iptables: Unloading modules:                               [  OK  ]

iptables: Applying firewall rules:

 

再度設定の確認をする

sudo iptables -L

Chain INPUT (policy ACCEPT)

target     prot opt source               destination         

RH-Firewall-1-INPUT  all  --  anywhere             anywhere            

 

Chain FORWARD (policy ACCEPT)

target     prot opt source               destination         

RH-Firewall-1-INPUT  all  --  anywhere             anywhere            

 

Chain OUTPUT (policy ACCEPT)

target     prot opt source               destination         

 

Chain RH-Firewall-1-INPUT (2 references)

target     prot opt source               destination         

ACCEPT     all  --  anywhere             anywhere            

ACCEPT     icmp --  anywhere             anywhere            icmp any

ACCEPT     esp  --  anywhere             anywhere            

ACCEPT     ah   --  anywhere             anywhere            

ACCEPT     udp  --  anywhere             224.0.0.251         udp dpt:mdns

ACCEPT     udp  --  anywhere             anywhere            udp dpt:ipp

ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:ipp

ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED

ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:zzzzz

ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:http

REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited

 

不正アクセスがあった場合に感知できるようアクセス監視ツールを入れる

$ sudo yum install logwatch

 

試しにメールを送ってみる。

$ sudo logwatch --mailto foo@example.com

 

メールが送られてこない・・・・

メールログを確認

$ sudo tail -f /var/log/maillog

 

メールの設定を確認

$ sudo alternatives --config mta

 

There is 1 program that provides 'mta'.

 

  Selection    Command

-----------------------------------------------

*+ 1           /usr/sbin/sendmail.postfix

Enter to keep the current selection[+], or type selection number:

 

Postfixが設定されている。

$ service postfix status

master is stopped

 

どうやらPostfixが止まっている。

OS起動時に起動するように設定。

$ sudo chkconfig postfix on

 

忘れずにサービス起動

$ sudo service postfix start

Starting postfix:                                          [  OK  ]

 

再度メールのテスト送信

$ sudo logwatch --mailto foo@example.com

 

OK、無事メールが送られてきた。

ただし、spamフォルダに入っているので、通常フォルダに入るようにする。

ちなみに、メールのフィルタを設定するか、連絡先に送信元を追加するとspamと認識されなくなる場合が多い(メールソフトによるが)。

logwatchメール送信先設定を追加

$ sudo vi /etc/logwatch/conf/logwatch.conf

# Local configuration options go here (defaults are in /usr/share/logwatch/default.conf/logwatch.conf)

MailTo foo@example.com

 

つづく

 

参考にしたブログ

さくらのVPS を改めて使いはじめる 3 – iptables と logwatch | アカベコマイリ

CentOS5.3でWebServer(LogWatch編)

後で設定してみたいセキュリティ

vogel.at.webry.info

 

 

1からLinuxに本番環境の設定をする CentOS

1からLinuxに本番環境の設定をする CentOS(1) 

1からLinuxに本番環境の設定をする CentOS(2)セキュリティ

1からLinuxに本番環境の設定をする CentOS(3)iptable logwatch

1からLinuxに本番環境の設定をする CentOS(4)Apache2.2を2.4にアップデートする

1からLinuxに本番環境の設定をする CentOS(5)Gitのインストールと設定

1からLinuxに本番環境の設定をする CentOS(6)gitoliteでリポジトリ運用開始

1からLinuxに本番環境の設定をする CentOS(7)tomcat7 インストール

1からLinuxに本番環境の設定をする CentOS(8)tomcat8 インストール