LoginSignup
0
0

More than 1 year has passed since last update.

録画サーバーのファイアーウォール設定

Posted at

はじめに

この記事は録画サーバー on archlinux でファイアーウォールの設定をする手順紹介(備忘録)です。
中身としては普通のiptablesを使った設定手順です。
※元作業の関係上、基本的にルートユーザーで作業を行っています。

やりたいこと

  • 不正なアクセスを防ぐためにファイアーウォールを設定したい
  • Mirakurun、EPGStation、SAMBA等のコンポーネントに関する通信は遮断したくない

ファイアーウォールの設定

iptablesの有効化・起動

# サービスの起動と自動起動の設定をする
systemctl start iptables
systemctl enable iptables
systemctl status iptables

iptablesの設定

サーバーにssh接続している場合などは、sshの接続の許可を入れておかないと、諸々の設定を有効化した際に突然遮断される場合もあるので注意が必要です。(そうなってしまったら、サーバーに直に接続して作業しましょう)

# 現在の設定状況の確認→何も設定されてないはず
iptables -nvL --line-numbers

# ルールをリセットする(一応)
iptables -F

## 設定をする
# FORWARD チェインのデフォルトポリシーを ACCEPT から DROP に変更する(ルーターならACCEPTにするっぽい)
iptables -P FORWARD DROP

# ローカルからの通信を許可する
iptables -A INPUT -i lo -j ACCEPT

# sshの設定
iptables -A INPUT -p tcp --dport ssh -j ACCEPT
iptables -A OUTPUT -p tcp --dport ssh -j ACCEPT

# http, httpsの設定
iptables -A OUTPUT -p tcp -m state --state NEW --dport http -j ACCEPT
iptables -A OUTPUT -p tcp -m state --state NEW --dport https -j ACCEPT

# EPGStationが使っているポートを開ける
iptables -A INPUT -p tcp --dport 8888 -j ACCEPT

# Mirakurunが使っているポートを開ける
iptables -A INPUT -p tcp --dport 40772 -j ACCEPT

# SAMBAが使っているポートを開ける
iptables -A INPUT -p udp --dport 137 -j ACCEPT
iptables -A INPUT -p udp --dport 138 -j ACCEPT
iptables -A INPUT -p tcp --dport 139 -j ACCEPT
iptables -A INPUT -p tcp --dport 445 -j ACCEPT

# 任意へのDNSアクセスの戻りパケットを受け付ける
iptables -A INPUT -p udp --sport 53 -j ACCEPT

# 確立済みの通信は、ポート番号に関係なく許可する
iptables -A INPUT -p tcp -m state --state ESTABLISHED,RELATED -j ACCEPT

# icmp(ping)の設定
iptables -A INPUT -p icmp --icmp-type echo-request -m hashlimit --hashlimit-name t_icmp --hashlimit 1/m --hashlimit-burst 10 --hashlimit-mode srcip --hashlimit-htable-expire 120000 -j ACCEPT

# INPUT チェインのデフォルトポリシーも ACCEPT から DROP に変更する
iptables -P INPUT DROP

# ルールの確認
iptables -nvL --line-numbers


## 設定内容の反映
# 設定内容をファイルに書き出す
iptables-save > /etc/iptables/iptables.rules
# 有効化する
systemctl reload iptables
systemctl restart iptables

以上

関連記事

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0