LoginSignup
1
3

More than 5 years have passed since last update.

iptablesでサーバから外部(他のサーバ)への接続を遮断する

Posted at

セキュリティの関係上、特定のサーバもしくは特定のセグメントへ接続させたくない場合が多々ある。
LANを抜ければそれだけで解決なのだが、運用中のサーバでそれを実現するのはなかなかリスキーである。

iptablesで孤立させるのが手っ取り早い。

事前確認

iptables -L

前提条件

localhostから以下のサーバへの通信を止める

192.168.1.1
192.168.1.2
10.*.*.*

local -> outbound を制御

iptables -A OUTPUT -d 192.168.1.1/32 -o eth0 -j DROP
iptables -A OUTPUT -d 192.168.1.2/32 -o eth0 -j DROP
iptables -A OUTPUT -d 10.0.0.0/8 -o eth0 -j DROP

outbound -> localを制御

iptables -A INPUT -d 192.168.1.1/32 -j DROP
iptables -A INPUT -d 192.168.1.2/32 -j DROP
iptables -A INPUT -d 10.0.0.0/8 -j DROP

確認

iptables -L

解放

すべてのiptablesが真っ白になる

iptables -F
1
3
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
1
3