网络防火墙之ICMP控制

网络防火墙

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.8 ping通 192.168.37.122 ,192.168.37.122 无法ping通 10.0.0.8

 法一:iptables的icmp扩展功能

 1 [root@firewall-121 ~]# iptables -A FORWARD   -d 10.0.0.0/24 -p icmp --icmp-type 0 -j ACCEPT
 2 [root@firewall-121 ~]# iptables -A  FORWARD  -s 10.0.0.0/24 -p icmp --icmp-type 8 -j ACCEPT
 3 [root@firewall-121 ~]# iptables -A FORWARD -j REJECT
 4 [root@firewall-121 ~]# iptables -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        4   336 ACCEPT     icmp --  *      *       0.0.0.0/0            10.0.0.0/24          icmptype 0
 8 2       11   924 ACCEPT     icmp --  *      *       10.0.0.0/24          0.0.0.0/0            icmptype 8
 9 3       12  1008 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-port-unreachable
10 #/验证/
11 [root@centos7-108 ~]$ping 192.168.37.122
12     64 bytes from 192.168.37.121: icmp_seq=1 ttl=64 time=0.415 ms
13 [root@CentOS7-122 ~]# ping 10.0.0.108
14     From 192.168.37.121 icmp_seq=1 Destination Port Unreachable
View Code

法二:iptables的state扩展功能

1 [root@firewall-121 ~]#iptables -R FORWARD 1 -d 10.0.0.0/24 -m state --state ESTABLISHED,RELATED -j ACCEPT
View Code

 

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