24
23

More than 3 years have passed since last update.

iptablesで特定のIPの通信を遮断する

Last updated at Posted at 2016-01-05

状況次第にでは一切の通信ができなくなりますので、注意して実行してください。

作業前のiptablesを確認

command
iptables -L

iptablesで特定のIPの通信を遮断する(localhost->OUT)

以下のサーバ の通信を止める
192.168.10.8
192.168.10.9
10...*

eht0から特定セグメントへの通信を遮断する。

command
iptables -A OUTPUT -d 192.168.10.8/32 -o eth0 -j DROP
iptables -A OUTPUT -d 192.168.10.9/32 -o eth0 -j DROP
iptables -A OUTPUT -d 10.0.0.0/8 -o eth0 -j DROP

iptablesで特定のIPからの通信を遮断する(OUT->localhost)

以下のサーバ から の通信を止める
192.168.10.8
192.168.10.9
10...*

特定セグメントからの通信を遮断する。

command
iptables -A INPUT -s 192.168.10.8/32 -j DROP
iptables -A INPUT -s 192.168.10.9/32 -j DROP
iptables -A INPUT -s 10.0.0.0/8 -j DROP

作業後のiptablesを確認

command
iptables -L

全設定削除

iptablesが真っ白になる
(環境次第では一切の通信ができなくなりますので擬似環境で十分に実施をしてから実行してください)

command
iptables -F

再読み込み

/etc/sysconfig/iptables の設定も踏まえ再読み込みをする。

command
/etc/init.d/iptables restart
24
23
3

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
24
23