Docker加入自定義iptables規則鏈


Docker加入自定義iptables規則鏈,實現IP白名單。

#!/bin/bash
set -e

# 網卡名稱
InterfaceName="enp3s0"
RuleName="FIREWALL-KMS"

# 重啟服務,恢復默認的iptables規則
# systemctl restart iptables
# 系統防火牆
#systemctl restart firewalld
# Docker服務
#systemctl restart docker

# # --------------------- 6. 自定義規則鏈 -------------------
# # 自定義Chain
# iptables -t filter -N INPUT-KMS
iptables -N $RuleName
# 默認拒絕
iptables -I $RuleName -j DROP

# 加入規則鏈
iptables -I FORWARD -i docker0 -j $RuleName

# Docker容器公共管理員訪問權限(在此處插入所有允許的IP)
# iptables -I $RuleName -o $InterfaceName -d 192.168.60.26 -j ACCEPT
# iptables -I $RuleName -o $InterfaceName -d 192.168.112.25 -j ACCEPT

iptables -I $RuleName -d 192.168.60.26 -j ACCEPT
iptables -I $RuleName -d 192.168.112.25 -j ACCEPT



# ---------------- 顯示防火牆規則 ----------------------
iptables -nvL
  • 刪除自定義規則
#!/bin/bash
set -e

# 網卡名稱
InterfaceName="enp3s0"
RuleName="FIREWALL-KMS"

# 從系統規則鏈中刪除
iptables -t filter -D FORWARD -i docker0 -j $RuleName
# 清空規則鏈
iptables -t filter -F $RuleName
# 計數清零
iptables -t filter -X $RuleName

#-------------------------- 打印 ------------------
iptables -nvL FORWARD

詳細文章


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM