Iptables防火墙常见的典型应用场景

Iptables防火墙常见的典型应用场景

1、场景一

需求如下:

  • 公司员工可以在192.168.20.0/24、192.168.30.0/24网段访问服务器上的任何服务。
  • 当员工出差时,通过VPN也可以连接到公司所有的服务器,操作所有的服务。
  • 公司的门户网站服务器,只允许公网用户访问80和443协议端口。
  • 非已建立连接的数据包禁止通过。

防火墙配置规则如下:

[root@jxl-1 ~]# iptables -t filter -I INPUT -s 192.168.20.0/24,192.168.30.0/24 -j ACCEPT 
[root@jxl-1 ~]# iptables -t filter -A INPUT -m state --state "ESTABLISHED" -j ACCEPT
[root@jxl-1 ~]# iptables -t filter -A INPUT -p tcp -m multiport --dports 80,443 -j ACCEPT 
[root@jxl-1 ~]# iptables -A INPUT -j DROP

查看设置的防火墙规则:
在这里插入图片描述

2、场景二

1.对所有的地址开放本机的tcp(80、22、8080-9090)端口的访问。
2.允许对所有的地址开放本机的基于ICMP协议的数据包访问。
3.其他未被允许的端口禁止访问。

#INPUT
[root@jxl-1 ~]# iptables -I INPUT -p tcp -m multiport --dports 22,80,8080:9090 -m state --state NEW,ESTABLISHED -j ACCEPT
[root@jxl-1 ~]# iptables -I INPUT -p icmp -j ACCEPT
[root@jxl-1 ~]# iptables -A INPUT -j DROP

#OUTPUT
[root@jxl-1 ~]# iptables -I OUTPUT -p tcp -m multiport --sport 80,22,8080:9090 -m state --state ESTABLISHED,RELATED -j ACCEPT
[root@jxl-1 ~]# iptables -I  OUTPUT -p icmp -j ACCEPT
[root@jxl-1 ~]# iptables -A OUTPUT -j DROP

猜你喜欢

转载自blog.csdn.net/weixin_44953658/article/details/125714698