软件防火墙和硬件防火墙
包过滤防火墙和应用层防火墙
centos 6 --> iptables 包过滤器防火墙 (底层使用netfilter)
centos7 --> filewallD 包过滤器防火墙
iptables的表和链
规则表
filter 过滤 允许哪个ip和端口
nat 网络地址转换
mangle
raw
规则链 (过滤的方向)
- INPUT OUTPUT FORWARD
- prerouting postrouting
iptables -t filter -L
iptables -t filter -nvL
iptables -nvL
iptables -t nat -nl
LANG=c man iptables
iptables -t nat -nvL
iptable -t filter -A INPUT -s 10.0.0.1 -j ACCEPT
iptables -nvL
-A 附加
-I 添加到第一条
iptables -A INPUT -s 10.0.0.2 -J ACCEPT
iptables -A INPUT -s 10.0.0.2 -J DROP
添加
iptables -I INPUT -s 10.0.0.3 -J DROP
POLICY ACCEPT
都没有匹配
POLICY DROP
iptables -P INPUT DROP
iptables -P INPUT ACCEPT
清楚规则
iptables -F
iptables -D 5
防火墙进行更规范的设置
-N -X -E
man iptables
-s 访问的ip地址
10.0.0.0/24
-s -d
进入出去的网络接口
网卡
-i -o
port
all tcp udp
-p --dprot 80
iptables -A INPUT -p tcp --dport 80 -i eth0 -s 10.00.00.00 -j ACCEPT
iptables -A INPUT -j DROP
iptables nat表的使用
iptables -t nat 命令 规则链 规则
PREROUTING 目的地址转换
POSTROUTING 源地址转换
PREROUTING 目的地址转换
iptables -t nat -A PREROUTING -i eth0 -d 110.110.110.111 -p tcp --dport 80
-j DNAT --to-destination 10.0.0.1
iptables -t nat -A POSTROUTING -s 10.0.0.0/24 -o eth1 -j SNAT --to-source 111.112.113.114
两台主机
iptables 配置文件
/etc/sysconfig/iptables
service iptables save
rpm -ql iptables-services
centos7
安装命令
yum install iptables-services
重新启动机器 规则消失
-p DROP
/usr/libexec/iptables/iptables.init
firewallD的特点
- 支持区域 “zone” 概念
systemctl start|stop |enable |disable firewalld.service
systemctl status firewalld.service
systemctl start firewalld.service
开机生效
systemctl enable firewalld.service
service iptables stop
firewall-cmd --state
firewall-cmd --list-all
services:ssh dhcpv6-client
firewall-cmd --zone=public --list-interfaces
firewall-cmd --zone=public --list-services
firewall-cmd --zone=public --list-ports
firewall-cmd --get-zones
firewall-cmd --get-default-zone
firewall-cmd --get-active-zone
port
81
firewall-cmd --zone=public --add-port=80/tcp --permanent (--permanent永久生效,没有此参数重启后失效)
service
http 服务
firewall-cmd --add-service=http //http换成想要开放的service
firewall-cmd --permanent --add-service=http
firewall-cmd --zone=public
source
限制ip访问
service iptables stop
配置文件位置
/etc/firewalld/