网关防火墙项目效果图
网关防火墙的需求及实践
1、实现 相关的 SNAT 的功能,代理公司内部的客户机上网,;但是限制在上班期间访问京东淘宝和天猫网站
2、实现 DNAT 功能 。将内部服务器 172.16.10.10 映射到网关,允许外部主机访问到公司提供的 web 服务
3、内部 的 10.10.1.0 网段主机, 只能通过网关访问内部服务器 web 服务, 但是管理员 10.10.1.10 不受限制,并绑定MAC
4、网关主机本身,仅允许 内部 IP 访问自己的 web服务,仅允许 10.1.1.10 ssh 连接自己
5、防御 外部 主机,主动 连接 内部主机, 仅仅让外部主机能够 访问 172.16.100.99 的 web 服务
[root@deng- order]# vim iptables.sh
#!/bin/bash
admin="10.10.1.100"
mac="00:0c:29:cb:74:f8"
amstart="01:00"
amstop="04:00"
pmstart="06:00"
pmstop="10:00"
###########清空规则##############
iptables -F
iptables -t nat -F
iptables -X
iptables -t nat -X
iptables -Z
iptables -t nat -Z
############# 全局策略 ################
iptables -t filter -P INPUT DROP
iptables -t filter -P FORWARD ACCEPT
iptables -t filter -P FORWARD ACCEPT
############# SNAT 实现公司内部上网 ##############
iptables -t nat -A POSTROUTING -o ens33 -j MASQUERADE
############# DNAT 实现外网访问公司web服务 ###############
iptables -t nat -A PREROUTING -i ens33 -p tcp --dport 80 -d 192.168.10.10 -j DNAT --to 172.16.10.10
############### 允许访问网关的web服务 ###############
iptables -t filter -A INPUT -p tcp --dport 80 -i ens38,ens39 -j ACCEPT
iptables -t filter -A INPUT -p icmp -j ACCEPT
############## 允许 管理员 远程管理 httpd service ###################
iptables -t filter -A INPUT -p tcp --dport 22 -s $admin -m mac --mac-source $mac -j ACCEPT
#################### DROP new、invalid ;ACCEPT established、related #############
iptables -t filter -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -t filter -A INPUT -i ens38 -p tcp --dport 53 -j ACCEPT
iptables -t filter -A INPUT -i ens38 -p udp --dport 53 -j ACCEPT
############ 允许访问公司内部的web 允许管理员的任何操作 ####################
iptables -t filter -A FORWARD -i ens38 -o ens39 -s $admin -m mac --mac-source $mac -j ACCEPT
iptables -t filter -A FORWARD -i ens38 -o ens39 -p tcp ! --dport 80 -j REJECT
###################### 在上班时间拒绝访问京东、淘宝、天猫 ######################
iptables -t filter -A FORWARD -o ens33 -m time --timestart $amstart --timestop $amstop -m string --algo kmp --string "taobao" -j DROP
iptables -t filter -A FORWARD -o ens33 -m time --timestart $pmstart --timestop $pmstop -m string --algo kmp --string "taobao" -j DROP
iptables -t filter -A FORWARD -o ens33 -m time --timestart $amstart --timestop $amstop -m string --algo kmp --string "jd" -j DROP
iptables -t filter -A FORWARD -o ens33 -m time --timestart $pmstart --timestop $pmstop -m string --algo kmp --string "jd" -j DROP
iptables -t filter -A FORWARD -o ens33 -m time --timestart $amstart --timestop $amstop -m string --algo kmp --string "tmall" -j DROP
iptables -t filter -A FORWARD -o ens33 -m time --timestart $pmstart --timestop $pmstop -m string --algo kmp --string "tmall" -j DROP
########################## 防止黑客向外发送数据 ################################
iptables -t filter -A OUTPUT -p tcp --sport 31337:31340 -j DROP
iptables -t filter -A OUTPUT -p tcp --sport 31337:31340 -j DROP
####################### 保存规制 ####################
service iptables save
########## 保存前要做的步骤,不做此步骤是无法进行保存工作 ###########
#cp /usr/libexec/iptables/iptables.init /etc/rc.d/init.d/iptables
上述就是模仿公司的内部的防火墙所做的小项目需求以及实践应用,通过这个小项目来熟悉防火墙的用途。
具体的防火墙知识点请参考一下连接内容…
https://blog.csdn.net/weixin_42867972/article/details/82260479