(实验环境:CentOS7.3)
iptables
firewalld
netfilter / iptables --iptables 的全名 2.4版本内核后都集成有这个组件
# yum install iptables\*
# rpm -qa |grep iptables
iptables-services-1.4.21-17.el7.x86_64
iptables-utils-1.4.21-17.el7.x86_64
iptables-devel-1.4.21-17.el7.x86_64
iptables-1.4.21-17.el7.x86_64
# systemctl start iptables.service
# systemctl status iptables.service
iptables 基本概念
四张表: 表里有链 (chain )
filter: 用来进行包过滤: INPUT OUTPUT FORWARD
nat: 用来网络地址转换: network address translation ,允许一个内网地址块,通过NAT转换成公网IP,实现对公网的访问,解决IP地址不足
PREROUTING INPUT POSTROUTING OUTPUT
mangle :用来对数据包标记
PREROUTING INPUT OUTPUT FORWARD POSTROUTING
raw:对原始数据包的处理
PREROUTING OUTPUT
iptables
例1,列规则
iptables -L --默认看的就是filter表
iptables -L -t filter
iptables -L -t nat
iptables -L -t mangle
iptables -L -t raw
# iptables -t filter -F
# iptables -t nat -F
# iptables -t mangle -F --这三张表有些默认的规则,我们把规则都清掉
例2,控制ping
172.16.25.0/24网段ping本机,会被拒绝(客户端会收到拒绝信息)
# iptables -t filter -A INPUT -p icmp -s 172.16.25.0/24 -j REJECT
# iptables -t filter -D INPUT -p icmp -s 172.16.25.0/24 -j REJECT --删除上一条规则
# iptables -t filter -A INPUT -p icmp -s 172.16.25.0/24 -j DROP
# iptables -t filter -D INPUT -p icmp -s 172.16.25.0/24 -j DROP
# iptables -t filter -A OUTPUT -p icmp -d 172.16.25.0/24 -j REJECT
# iptables -t filter -D OUTPUT -p icmp -d 172.16.25.0/24 -j REJECT
# iptables -t filter -A OUTPUT -p icmp -d 172.16.25.0/24 -j DROP
# iptables -t filt
iptables/firewall防火墻詳解
最新推荐文章于 2024-08-01 17:51:50 发布