ernestas-poskus.iptables
ansible-iptables 用于内部和外部网络防火墙配置
安装
ansible-galaxy install ernestas-poskus.iptables
要求
无。
依赖
无。
角色变量
---
# ansible-iptables 的默认配置文件
##########################
# IPv4 配置
##########################
# 默认操作::INPUT DROP
iptables_initial_input_action: DROP
# 默认操作::FORWARD ACCEPT
iptables_initial_forward_action: ACCEPT
# 默认操作::OUTPUT ACCEPT
iptables_initial_output_action: ACCEPT
# 允许回环接口(本地主机)
iptables_allow_loopback: true
# 允许已建立和相关的连接
iptables_allow_established_connections: true
# 允许 DNS 解析
iptables_allow_dns: false
# 允许 NTP 流量以进行时间同步
iptables_allow_ntp: true
# 允许 ICMP ping 请求
iptables_allow_icmp: true
# 内部网络支持列表:
# - IP 地址
# - HOSTS(iptables_internal_ips_from_hosts 应该启用)
iptables_internal_network: []
# 从给定主机解析内部 IP
iptables_internal_ips_from_hosts: false
# 内部主机接口
iptables_internal_hosts_interface: "{{ ansible_default_ipv4.interface }}"
# 内部网络配置
iptables_internal_ports:
- '1024:65535'
- '111' # 端口映射
- '161:162' # 简单网络管理协议(SNMP)
- '22' # ssh
# 内部网络协议
iptables_internal_protocols:
- 'tcp'
- 'udp'
# 外部网络配置
iptables_external_ports:
- '22' # ssh
# 外部网络协议
iptables_external_protocols:
- 'tcp'
# iptables 的附加规则
iptables_additional_rules: []
# 记录丢弃的数据包
iptables_log_dropped_packets: false
# 丢弃的数据包的记录限制(分钟)
iptables_log_dropped_limit: 15
# 丢弃的数据包的日志记录级别
iptables_log_logging_level: 4
##########################
# IPv6 配置
##########################
# 默认操作::INPUT DROP
iptables6_initial_input_action: DROP
# 默认操作::FORWARD ACCEPT
iptables6_initial_forward_action: ACCEPT
# 默认操作::OUTPUT ACCEPT
iptables6_initial_output_action: ACCEPT
# 允许回环接口(本地主机)
iptables6_allow_loopback: true
# 允许已建立和相关的连接
iptables6_allow_established_connections: true
# 允许 DNS 解析
iptables6_allow_dns: false
# 允许 NTP 流量以进行时间同步
iptables6_allow_ntp: true
# 允许 ICMP ping 请求
iptables6_allow_icmp: true
# 内部网络支持列表:
# - IP 地址
# - HOSTS(iptables6_internal_ips_from_hosts 应该启用)
iptables6_internal_network: []
# 从给定主机解析内部 IP
iptables6_internal_ips_from_hosts: false
# 内部主机接口
iptables6_internal_hosts_interface: "{{ ansible_default_ipv4.interface }}"
# 内部网络配置
iptables6_internal_ports:
- '1024:65535'
- '111' # 端口映射
- '161:162' # 简单网络管理协议(SNMP)
- '22' # ssh
# 内部网络协议
iptables6_internal_protocols:
- 'tcp'
- 'udp'
# 外部网络配置
iptables6_external_ports:
- '22' # ssh
# 外部网络协议
iptables6_external_protocols:
- 'tcp'
# iptables 的附加规则
iptables6_additional_rules: []
# 记录丢弃的数据包
iptables6_log_dropped_packets: false
# 丢弃的数据包的记录限制(分钟)
iptables6_log_dropped_limit: 15
# 丢弃的数据包的日志记录级别
iptables6_log_logging_level: 4
# NAT
iptables_nat_prerouting: ACCEPT
iptables_nat_output: ACCEPT
iptables_nat_postrouting: ACCEPT
iptables4_nat_additional_rules: []
iptables6_nat_additional_rules: []
示例剧本
从给定主机创建内部网络
- name: 配置 iptables
hosts: all
sudo: yes
roles:
- role: ernestas-poskus.iptables
iptables_internal_network: "{{ groups['all'] }}"
iptables_internal_ips_from_hosts: true # 使用主机时必须启用
iptables_log_dropped_packets: true
iptables_log_dropped_limit: 1
从给定 IP 列表创建内部网络
- name: 配置 iptables
hosts: all
sudo: yes
roles:
- role: ernestas-poskus.iptables
iptables_internal_network:
- 192.168.0.1
- 192.168.0.2
- 192.168.0.3
iptables_log_dropped_packets: true
iptables_log_dropped_limit: 1
许可证
版权 (c) 2016, Ernestas Poskus 保留所有权利。
在符合以下条件的情况下,允许在源代码和二进制形式中重新分发和使用,无论是否修改:
源代码的重新分发必须保留上述版权声明、此 条件清单和以下免责声明。
二进制形式的重新分发必须在分发中提供的文档和/或其他材料中 重现上述版权声明、此条件列表和以下免责声明。
除非获得书面许可,否则不得使用 ansible-iptables 的名称或其 贡献者的名称来支持或促进源自该软件的产品。
本软件由版权持有者和贡献者按“原样”提供, 并不承担任何明示或暗示的担保,包括但不限于, 对适销性和特定用途的隐含担保不予承认。在任何情况下,版权持有者或贡献者均不对任何直接、间接、附带、特殊、示范性或后果性 损害(包括但不限于采购替代商品或服务;使用、数据或利润损失;或商业中断)承担责任,甚至已经警告此类损害的可能性。
作者信息
推特: @ernestas_poskus