网络防火墙之HTTP控制

网络防火墙

iptables/netfilter网络防火墙:
  (1) 充当网关
  (2) 使用filter表的FORWARD链
注意的问题:
  (1) 请求-响应报文均会经由FORWARD链,要注意规则的方向性
  (2) 如果要启用conntrack机制,建议将双方向的状态为ESTABLISHED的报文直接放行
 
准备:
firewall:开启ip_forward功能
  [root@firewall ~]#vim /etc/sysctl.conf
  net.ipv4.ip_forward = 1
  [root@firewall ~]#sysctl -p
  [root@firewall ~]#sysctl -a
firewall开启转发功能后,10.0.0.108能互相ping通192.168.37.122
 
示例:

 场景:10.0.0.108 可以访问192.168.37.122 的http服务

 1 [root@firewall-121 tmp]#  iptables -A FORWARD  -s 10.0.0.0/24 -p tcp --dport 80 -j ACCEPT
 2 [root@firewall-121 tmp]#  iptables -A FORWARD  -d 10.0.0.0/24 -m state --state ESTABLISHED,RELATED -j ACCEPT
 3 [root@firewall-121 ~]# iptables -A FORWARD -j REJECT
 4 [root@firewall tmp]#iptables -Riptables -vnL --line-numbers
 5 Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 6 num   pkts bytes target     prot opt in     out     source               destination         
 7 1        0     0 ACCEPT     all  --  *      *       0.0.0.0/0            10.0.0.0/24          state RELATED,ESTABLISHED
 8 2       28  1756 ACCEPT     tcp  --  *      *       10.0.0.0/24          0.0.0.0/0            tcp dpt:80
 9 3      184 12488 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-port-unreachable
10 #/验证/
11 [root@CentOS7-108 ~]# curl 192.168.37.122
12 internet server
13 [root@CentOS7-122 ~]# curl 10.0.0.108
14 curl: (7) Failed connect to 10.0.0.108:80; Connection refused
View Code

 

posted @ 2024-08-29 08:37  起点·漫步前行  阅读(58)  评论(0)    收藏  举报