首页 > 系统相关 >14.ansible模块之 selinux firewalld iptables

14.ansible模块之 selinux firewalld iptables

时间:2022-10-05 18:44:59浏览次数:58  
标签:iptables 14 webservers selinux destination state ansible 1.1

1.1 selinux官方示例

EXAMPLES:

- name: Enable SELinux
  selinux:
    policy: targeted
    state: enforcing

- name: Put SELinux in permissive mode, logging actions that would be blocked.
  selinux:
    policy: targeted
    state: permissive

- name: Disable SELinux
  selinux:
    state: disabled

selinux 防火墙模块ad-hoc:

ansible webservers -m selinux -a 'state=disabled'

2.1 firewalld

官方示例

EXAMPLES:

- firewalld:
    service: https
    permanent: yes
    state: enabled

- firewalld:
    port: 8081/tcp
    permanent: yes
    state: disabled

firewalld防火墙模块:
args:

	zone:		要操作的区域  默认public
	source:	来源地址
        service: 	 服务名称 http,https,sshd,......
	port:		端口
        permanent:	永久生效,但不会立即生效
	immediate:	临时生效;
        state: 		规则启用和关闭;
		disabled
		enabled
2.1.让被控端都放行80端口;
ansible webservers -m systemd -a 'name=firewalld state=started'
ansible webservers -m firewalld -a 'port=80/tcp immediate=yes state=enabled'
2.2.让被控端都放行https端口;
ansible webservers -m systemd -a 'name=firewalld state=started'
ansible webservers -m firewalld -a 'service=https immediate=yes state=present'

3.iptables 防火墙模块:

官方示例:

EXAMPLES:

- name: Block specific IP
  iptables:
    chain: INPUT
    source: 8.8.8.8
    jump: DROP
  become: yes

- name: Forward port 80 to 8600
  iptables:
    table: nat
    chain: PREROUTING
    in_interface: eth0
    protocol: tcp
    match: tcp
    destination_port: 80
    jump: REDIRECT
    to_ports: 8600
    comment: Redirect web traffic to port 8600
  become: yes
3.2 iptables:

args:

    table: 					表
    chain: 					链
    source: 				来源IP
	destination				目标IP
	destination_port		目标端口
	protocol	协议
        jump: DROP	动作
	action		如何添加规则
		insert:插入
		append:追加
3.1.来源IP是192.168.1.1 目标地址 1.1.1.1 目标端口 80 协议 tcp 则拒绝; 规则要写入第一行;
ansible webservers -m iptables -a 'table=filter chain=INPUT source=192.168.1.1/32 destination=1.1.1.1 destination_port=80 protocol=tcp jump=DROP action=insert'
3.2.NAT:SNAT和DNAT:

示例1: DNAT: 如果请求1.1.1:80端口,则DNAT到2.2.2.2:8800

ansible webservers -m iptables -a 'table=nat chain=PREROUTING protocol=tcp destination=1.1.1.1 destination_port=80 jump=DNAT to_destination="2.2.2.2:8800"'

示例2:DNAT: 如果请求1.1.1:81端口,则DNAT到3.3.3.3:8800

ansible webservers -m iptables -a 'table=nat chain=PREROUTING protocol=tcp destination=1.1.1.1 destination_port=81 jump=DNAT to_destination="3.3.3.3:8800"'

示例3:SNAT:
POSTROUTING
iptables -t nat -I POSTROUTING -s 172.16.1.0/24 -j SNAT --to-source 5.5.5.5

ansible webservers -m iptables -a 'table=nat chain=POSTROUTING source=172.16.2.0/24 jump=SNAT to_source=6.6.6.6'
ansible webservers -m iptables -a 'table=nat chain=POSTROUTING source=172.16.3.0/24 jump=SNAT to_source=7.7.7.7 action=insert'

标签:iptables,14,webservers,selinux,destination,state,ansible,1.1
From: https://www.cnblogs.com/yangtao416/p/16756107.html

相关文章

  • AtCoder Regular Contest 149
    ARC149A-RepdigitNumber符合条件的数一共只有\(9N\)个,随便怎么做都行。ACCodeARC149B-TwoLISSum这个操作相当于我们可以将\(A\)任意排列,然后对\(B\)进行......
  • 题解【CF1149C Tree Generator】
    CF1149CTreeGenerator™不一定更好的阅读体验。牛逼题&ZROIDay3数据结构选讲。来一波详细的题解。当时和\(\texttt{ys}\),\(\texttt{hy}\)还有小猴子讨论了半......
  • 1014 福尔摩斯的约会
     题目: 大侦探福尔摩斯接到一张奇怪的字条:我们约会吧!3485djDkxh4hhGE2984akDfkkkkggEdsbs&hgsfdkd&Hyscvnm 大侦探很快就明白了,字条上奇怪的乱码实际上就......
  • 小学数学学习:神奇的走马灯数 142857
    现在的小朋友,能看到走马灯实物的机会恐怕不多了。走马灯是我国传统节日装饰玩具之一,常见于元宵中秋等传统节日。灯内点上蜡烛,燃烧产生的热力造成气流,带动轮轴转动。烛光将灯......
  • 【国家统计局】2013年6月份-2014年5月份70个大中城市住宅销售价格变动情况
    2014年5月份70个大中城市住宅销售价格变动情况​​​http://www.stats.gov.cn/tjsj/zxfb/201406/t20140618_569655.html​​​(一)与上月相比,70个大......
  • 20146月份到2015年5月份70个大中城市住宅销售价格变动情况
    2015年5月份70个大中城市住宅销售价格变动情况​​​http://www.stats.gov.cn/tjsj/zxfb/201506/t20150618_1170358.html​​​(一)与上月相比,70个大中城市中,价格下降的......
  • 【笨方法学python】ex14 - 提示和传递
    代码如下:点击查看代码#-*-coding:utf-8--*-#提示和传递fromsysimportargvscript,user_name=argvprompt='>'print"Hi%s,I'mthe%sscript."%(u......
  • 14_Java中的抽象类
    Java中的抽象类一、抽象类的概述例如我们前面使用的动物类,并不是一个具体的事物,在这个类中我们是不应该给出方法的具体实现的,应当只是声明在Java中,一个没有......
  • AtCoder Regular Contest 149(持续更新)
    Preface最近国庆在外面玩的有点high啊,欠了一篇AT和两篇CF没写,今天先浅浅写一下这场当时10.2号在外面玩得有点晚了,到寝室刚好比赛开始,晚饭都没吃就开干了主要是C写的太久......
  • iptables
    ACL拒绝进入防火墙的所有ICMP数据凶包iptables-tfilter-IINPUT-picmp-jREJECT拒绝转发来自192.168.1.10主机的数据iptables-tfilter-AFORWARD-s192.168......