linux 防火墙
介绍
【千锋】Linux视频教程-4小时弄懂什么是防火墙
https://www.bilibili.com/video/BV197411b7Ve?p=1
共4个小时,15集
20210228 study
第一集:iptables & firewald
控制服务器与网络流量的
iptables : centOS6 中
firewald: centOS6 , centOS7 中都有 新一代的防火墙
网络防火墙: 思科ASA5550/ 华为USG6650 (报价40K)
应用安全防火墙:WAF(WebApplicationFirewall)
防毒墙:趋势科技、国信冠群YORTON-2000
上网行为管理器: 精细的区别流量来源,区分游戏与工作,
入侵检测: IDS,IPS (供应商有 绿盟、华为、天融信、启明星辰)
传输安全: VPN 虚拟专用网 (使用到了 隧道技术----通信被加密了)
举例:
公司老板要请保镖,此老板到中南海开会还需要保镖吗?不需要!!
计算机内部不要开启防火墙,因为网络设备会有更高级的防护,不需要自己设置!!
如果服务器出于外网,需要开启防火墙!
iptables:主机型、网络型
主机型: 此机器为服务器,开启防火墙是为了保护我自己
网络型:允许和放行经过它的数据。
防火墙有netfilter / iptables ,可以有效控制进出服务器的流量,和流经服务器的流量。
/sbin/iptables 可以配置iptables防火墙。
第三集
应表会传网链物
7 6 5 4 3 2 1
四表五列:
四表,五列,多条策略
表像安保小队, 列像安保队员。
一个表有多个链条,一个链条有多个策略。
四表:filter (过滤) / nat (装换) / mangle(碾压) / raw (生的)
主机型用filter , 网络型 用 nat ,其他的很少用
五列:input, output, forward , preRouting , postRouting
链条: 链安防员
策略:
----192.168.0.100 drop
----192.168.0.100 accept
第四章
表应用顺序:
raw–> mangle --> nat --> filter
链表的顺序:
PREROUTING --> INPUT --> OUTPUT --> POSTROUTING
PREROUTING --> FORWARD --> POSTROUTING
iptables
语法:
表 – 链 – 策略
表是小队,链式队员,队员还要有策略的处理事情方式 。
iptables -t 表名 管理选项 [链名] [匹配条件] [-j 控制类型]
-t 表名:四个表(raw mangle nat filter) 中的一个,不写 默认是filter表。
管理选项:操作方式 如 插入(I)、删除(D)、查看等。
链名: INPUT / FORWARD / OUTPUT 等
匹配条件:数据包特征 ip , port ,p (协议) 等
控制类型:数据包的处理方式 , ACCEPT允许,REJECT拒绝,DROP丢弃,等(拒绝会说一声,有返回值, 丢弃就是不理,没有返回值)
示例:
iptables -t 表名 管理选项 [链名] [匹配条件] [-j 控制类型]
本机: IPv4 地址 . . . . . . . . . . . . : 192.168.1.16
虚拟主机: inet 192.168.121.31
示例 查看
iptables -L 查阅当前iptables所有表 ,默认filter 表
iptables -L == iptables -L -t filter
iptables -L -t nat
示例 : 安装 http网站服务 ftp 文件传输服务
--安装 sftp
[root@firewall01 ~]# yum install -y vsftpd
---启动 ftp http
[root@firewall01 ~]# systemctl status httpd
[root@firewall01 ~]# systemctl status vsftpd
--- 安装 http
root@firewall01 opt]# yum install -y httpd
--- 启动 http
[root@firewall01 opt]# systemctl status httpd
[root@firewall01 opt]# systemctl start httpd
[root@firewall01 opt]# systemctl status httpd
--- 测试 http
[root@firewall01 opt]# curl http://192.168.121.31
基础示例: 清空
[root@firewall01 ~]# iptables -X
[root@firewall01 ~]# iptables -F
[root@firewall01 ~]# iptables -Z
[root@firewall01 ~]# iptables -L -n
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
示例2:配置不被ping
禁止自己被别人PING
《 icmp协议定义了ping这个命令 》
root@firewall01 opt]# iptables -t filter -I INPUT -p icmp -j REJECT
root@firewall01 opt]# iptables -L -t filter
再用 其他机器ping 看能否ping通
示例3:删除规则
禁止自己被别人PING
《 icmp协议定义了ping这个命令 》
root@firewall01 opt]# iptables -t filter -D INPUT -p icmp -j REJECT
root@firewall01 opt]# iptables -L -t filter
再用 其他机器ping 看能否ping通
第七章
细化匹配条件: ip port protocol
原因是,腾讯有 学习,有娱乐,要区分,不能只区分ip port ,一禁都禁不好。
示例4:开启一个网站,指定某台机器不可以访问
配置机器 192.168.121.3