Linux--iptables 配置篇
生产配置防火墙有两种方式
逛公园:默认随便进出,对非法分子进行拒绝,企业应用:企业配置上网网关路由。
看电影:默认没票进不去。花钱买票才能看电影,企业应用:服务器主机防火墙。
显然,第二种方法更安全
1.1 清空当前的所有规则和计数
[root@FRONTDB tmp]# iptables -F
[root@FRONTDB tmp]# iptables -X
[root@FRONTDB tmp]# iptables -Z
1.2 配置允许ssh端口连接
[root@FRONTDB ~]# iptables -t filter -A INPUT -p tcp --dport 22 -s 192.168.0.0/24 -j ACCEPT
1.3允许本地回环
[root@FRONTDB tmp]# iptables -A INPUT -i lo -j ACCEPT
[root@FRONTDB tmp]# iptables -A OUTPUT -o lo -j ACCEPT
1.4配置防火墙默认规则
参数是-P 或者—policy 来配置默认防火墙规则
[root@FRONTDB ~]# iptables -P INPUT DROP ##因为之前配置了22,所以此时还通
[root@FRONTDB ~]# iptables -P OUTPUT ACCEPT
[root@FRONTDB ~]# iptables -P FORWARD DROP
1.5 配置白名单
[root@FRONTDB ~]# iptables -A INPUT -p all -s 192.148.22.12/27 -j ACCEPT #办公室固定IP
[root@FRONTDB ~