iptables 防火墙练习
操作
-
禁ping 网关
-
只让srv1 ping 网关
-
开放dns 服务
-
防火墙规则备份
-
重启
-
防火墙规则还原
操作过程
开启防火墙
[root@localhost ~]# systemctl start firewalld.service
-
禁ping网关
[root@localhost ~]# iptables -t filter -I INPUT -p icmp -s 0.0.0.0/0 -j REJECT
禁ping前
禁ping后
-
只让srv1 ping 网关
[root@localhost ~]# iptables -t filter -I INPUT -p icmp -s 172.16.1.100 -j ACCEPT
添加后
-
开放dns 服务
此处禁用dns仅演示,实际操作时不禁用也无法解析dns
[root@localhost ~]# iptables -t filter -I INPUT -p udp --dport 53 -j REJECT
禁用dns后,无法解析
删除禁用dns
删除禁用服务 [root@localhost ~]# iptables -nvL --line-numbers [root@localhost ~]# iptables -t filter -D INPUT 1
开启dns服务
[root@localhost ~]# iptables -t filter -I INPUT -p udp --dport 53 -j ACCEPT
-
防火墙规则备份
[root@localhost ~]# iptables-save > /tmp/iprules_all.txt
-
重启gw
init6
-
防火墙规则还原
[root@localhost ~]# systemctl start firewalld.service [root@localhost ~]# iptables-restore < /tmp/iprules_all.txt [root@localhost ~]# iptables -nvL --line-numbers