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
```
[原创文章](https://www.cnblogs.com/jiftle/p/13821394.html)
https://www.cnblogs.com/jiftle/p/13821394.html