iptables网关防火墙小项目的实施应用,实战脚本...

网关防火墙项目效果图
网关防火墙项目效果图
网关防火墙的需求及实践
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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值