iptables使用の詳細
3484 ワード
1.iptablesのインストール
iptablesを使用した後、システムを
1.1ルール
iptablesには複数のRules(1つの条件と1つの目標値)が含まれます.条件が満たされると、ルールの目標値が実行されます.条件を満たさなければ次のRulesを判断します.
ターゲット値
iptablesは次の目標値をサポートします. ACCEPT–パケットを許可する DROP–パケットを破棄 QUEUE–パケットはユーザ空間 に移行する. RETURN–現在のチェーンの後続Rules の実行を停止
1.2規則表
ルール・テーブル間の優先順位:Raw->mangle->nat->filter
2.基本コマンド
3.高度な機能
ルールの追加 に規則を追加 3.1宛先アドレス変換(DNAT)
192.168.1.1.101:8080ポートへのアクセス、192.168.1.1.22:80ポートへのアクセスへの変換
4.一般的な基本設定
# iptables
service iptables status
# iptables
yum install -y iptables
# iptables-services
yum install iptables-services
iptablesを使用した後、システムを
firewalld
で無効にしてください.# firewalld
systemctl stop firewalld
# firewalld
systemctl mask firewalld
1.1ルール
iptablesには複数のRules(1つの条件と1つの目標値)が含まれます.条件が満たされると、ルールの目標値が実行されます.条件を満たさなければ次のRulesを判断します.
ターゲット値
iptablesは次の目標値をサポートします.
1.2規則表
ルール・テーブル間の優先順位:Raw->mangle->nat->filter
filter
表、3つのチェーン:INPUT、FOrWARD、OUTPUT作用:パケットカーネルモジュールのフィルタリング:iptables_filter. Nat
表、三つのチェーン:PREROUTING、POSTROOUTING、OUTPUT作用:ネットワークアドレス変換(IP、ポート)カーネルモジュール:iptable_nat Mangle
表、五つのチェーン:PREROUTING、POSTROOUTING、INPUT、OUTPUT、FOrWARD作用:パケットのサービスタイプ、TTLを修正し、ルートを配置してQOSカーネルモジュールを実現することができる:iptable_mangle(この時計を見ないでください.私たちは戦略を設定するときはほとんど使いません)Raw
表、2つのチェーン:OUTPUT、PREROUTING作用:パケットがステータストラッキングメカニズムでカーネルモジュールを処理するかどうかを決定する:iptable_raw 2.基本コマンド
# iptables
iptables -nvL
# 22
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
# IP,
iptables -I INPUT -s 106.54.212.96 -j DROP
# mangle/nat/raw
iptables -t mangle/nat/raw --list
3.高度な機能
ルールの追加
iptables -t -A INPUT/OUTPUT -p -d ip --dport -j
-A
尾部-I
挿入規則-D
削除規則192.168.1.1.101:8080ポートへのアクセス、192.168.1.1.22:80ポートへのアクセスへの変換
iptables -t nat -A OUTPUT -p tcp -d 192.168.1.101 --dport 8080 -j DNAT --to-destination 192.168.1.102:80
4.一般的な基本設定
#!/bin/sh
#
iptables -P INPUT ACCEPT
#
iptables -F
#
iptables -X
# 0
iptables -Z
iptables -A INPUT -i lo -j ACCEPT
# 22,21,80,443
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -p tcp --dport 21 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
# ping
iptables -A INPUT -p icmp --icmp-type 8 -j ACCEPT
# RELATED, FTP
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
#
iptables -P INPUT DROP
#
iptables -P OUTPUT ACCEPT
#
iptables -P FORWARD DROP
#
service iptables save
# iptables
systemctl restart iptables