当前位置: 首页 > news >正文

防火墙iptables项目实战

目录

一、网络规划

三、环境准备与检测

1、firewall

(1)配置防火墙各大网卡ip并禁用firewalld和selinux

(2)打开firewall路由转发

2、PC1(内网)

(1)配置ip并禁用firewalld和selinux

(2)配置网关

3、PC2(外网)

(1)配置ip并禁用firewalld和selinux

4、服务器S1(内网)

(1)配置ip并禁用firewalld和selinux

(2)配置网关

(3)下载nginx,并开通服务

5、环境检测

(1)内网连接

(2)外网连接

四、防火墙配置及测试


一、网络规划

二、主机规划

  • 内部PC1位于内网区域,地址段为: 192.168.1.0/24,pc1地址为:192.168.1.1/24,网关地址为:192.168.1.254/24

  • 服务器S1位于服务器区域,地址段为: 192.168.2.0/24,pc1地址为:192.168.2.1/24,网关地址为:192.168.2.254/24

  • PC2位于互联网区域,模拟外部互联网,地址段为:10.0.0.0/8,pc2地址为:10.0.0.1/8

  • Linux防火墙的三块网卡为别连接不同的网络区域,地址分别为 :ens33 192.168.1.254/24;ens34 10.0.0.100/8;ens35 192.168.2.254/24

三、环境准备与检测

1、firewall

(1)配置防火墙各大网卡ip并禁用firewalld和selinux

[root@SF1 ~] systemctl stop firewalld.service 
[root@SF1 ~] setenforce 0
[root@SF1 ~] ifconfig ens160 192.168.1.254/24
[root@SF1 ~] ifconfig ens192 10.0.0.100/8
[root@SF1 ~] ifconfig ens224 192.168.2.254

(2)打开firewall路由转发

[root@SF1 ~] sysctl -p
net.ipv4.ip_forward = 1

2、PC1(内网)

(1)配置ip并禁用firewalld和selinux

[root@PC1 ~] systemctl stop firewalld.service 
[root@PC1 ~] setenforce 0
[root@PC1 ~] ifconfig ens160 192.168.1.1/24

(2)配置网关

[root@PC1 ~] route add -net 0/0 gw 192.168.1.254
[root@PC1 ~] route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.1.254   0.0.0.0         UG    0      0        0 ens160
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 ens160
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0

3、PC2(外网)

(1)配置ip并禁用firewalld和selinux

[root@PC2 ~] systemctl stop firewalld.service 
[root@PC2 ~] setenforce 0
[root@PC2 ~] ifconfig ens160 10.0.0.1/8

4、服务器S1(内网)

(1)配置ip并禁用firewalld和selinux

[root@S1 ~] systemctl stop firewalld.service 
[root@S1 ~] setenforce 0
[root@S1 ~] ifconfig ens160 192.168.2.1/24

(2)配置网关

[root@S1 ~] route add -net 0/0 gw 192.168.2.254
[root@S1 ~] route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.2.254   0.0.0.0         UG    0      0        0 ens160
192.168.2.0     0.0.0.0         255.255.255.0   U     0      0        0 ens160
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0

(3)下载nginx,并开通服务


[root@S1 yum.repos.d] yum -y install nginx
[root@S1 yum.repos.d] systemctl restart nginx[root@S1 yum.repos.d] echo 2025 > /usr/share/nginx/html/index.html

5、环境检测

(1)内网连接

[root@PC1 ~] ping 192.168.2.1
PING 192.168.2.1 (192.168.2.1) 56(84) bytes of data.
64 bytes from 192.168.2.1: icmp_seq=1 ttl=63 time=0.784 ms
64 bytes from 192.168.2.1: icmp_seq=2 ttl=63 time=0.836 ms[root@PC1 ~] ping 10.0.0.100
PING 10.0.0.100 (10.0.0.100) 56(84) bytes of data.
64 bytes from 10.0.0.100: icmp_seq=1 ttl=64 time=0.498 ms
64 bytes from 10.0.0.100: icmp_seq=2 ttl=64 time=0.689 ms[root@PC1 ~] ping 192.168.1.254
PING 192.168.1.254 (192.168.1.254) 56(84) bytes of data.
64 bytes from 192.168.1.254: icmp_seq=1 ttl=64 time=6.42 ms
64 bytes from 192.168.1.254: icmp_seq=2 ttl=64 time=0.651 ms

(2)外网连接

[root@PC1 ~] ping 10.0.0.1
PING 10.0.0.1 (10.0.0.1) 56(84) bytes of data.
^C
--- 10.0.0.1 ping statistics ---
3 packets transmitted, 0 received, 100% packet loss, time 2086ms

##环境搭建之初,内网PC1无法访问外网PC2

四、防火墙配置及测试

1、内部网络中的pc1采用SNAT访问外部互联网,但是无法ping到内部网关

配置
[root@SF1 ~] iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -j MASQUERADE
[root@SF1 ~] iptables -t filter -A INPUT -p icmp --icmp-type 8 -j DROP外网测试
[root@PC1 ~] ping 10.0.0.1
PING 10.0.0.1 (10.0.0.1) 56(84) bytes of data.
64 bytes from 10.0.0.1: icmp_seq=1 ttl=63 time=1.19 ms
64 bytes from 10.0.0.1: icmp_seq=2 ttl=63 time=0.934 ms内部网关测试
[root@PC1 ~] ping 192.168.1.254
PING 192.168.1.254 (192.168.1.254) 56(84) bytes of data.
^C
--- 192.168.1.254 ping statistics ---
2 packets transmitted, 0 received, 100% packet loss, time 1007ms

2、内部网络服务器s1通过DNAT发布服务到互联网。

[root@SF1 ~] iptables -t nat -A PREROUTING -i ens192 -d 10.0.0.100 -p tcp --dport 80 -j DNAT --to-destination 192.168.2.1[root@PC2 ~] curl 10.0.0.100
2025

3、互联网主机pc2能够访问DMZ区域的服务器,但是不能够进行ping和ssh连接。

[root@SF1 ~] iptables -t filter -A INPUT -p icmp --icmp-type 8 -j DROP
[root@SF1 ~] iptables -t filter -A INPUT -p tcp --dport 22 -j DROP[root@PC2 ~] ping 10.0.0.100
PING 10.0.0.100 (10.0.0.100) 56(84) bytes of data.[root@PC2 ~] ssh root@10.0.0.100
ssh: connect to host 10.0.0.100 port 22: Connection timed out

http://www.xdnf.cn/news/871021.html

相关文章:

  • Java 二维码
  • ROS2性能狂飙:C++11移动语义‘偷梁换柱’实战
  • CSP严格模式返回不存在的爬虫相关文件
  • C#和C++在编译过程中的文件区分
  • 树莓派上遇到插入耳机后显示“无输入设备”问题
  • 格恩朗椭圆齿轮流量计 精准计量 赋能工业
  • 探索花语的奥秘:全新花语网站上线啦!
  • Elasticsearch中的地理空间(Geo)数据类型介绍
  • PostgreSQL配置文件修改及启用方法
  • ubutu修改网关
  • 将多个分段btsnoop文件合并为一个
  • 低空城市场景下的多无人机任务规划与动态协调!CoordField:无人机任务分配的智能协调场
  • HTML转EXE最新版本2.1.0新功能介绍 - 附CSDN免费下载链接
  • 数据结构与算法:动态规划中根据数据量猜解法
  • 在java 项目 springboot3.3 中 调用第三方接口(乙方),如何做到幂等操作(调用方为甲方,被调用方为乙方)? 以及啥是幂等操作?
  • 【ArcGIS微课1000例】0148:Geographic Imager6.2使用教程
  • Sentry 项目简介
  • 【Zephyr 系列 8】构建完整 BLE 产品架构:状态机 + AT 命令 + 双通道通信实战
  • dxf、dwg中文字矩阵变换
  • Django核心知识点全景解析
  • 网络攻防技术十三:网络防火墙
  • 企业私有化部署DeepSeek实战指南:从硬件选型到安全运维——基于国产大模型的安全可控落地实践
  • Redis命令使用
  • SpringAI(GA):Nacos2下的分布式MCP
  • shell:基础
  • 磐云P10 P057-综合渗透测试-使用反弹木马进行提权获取主机Shell
  • STM32学习之看门狗(理论篇)
  • 10.MySQL索引特性
  • dify中解决docx上传文件报错问题
  • 泰迪杯特等奖案例深度解析:基于量子启发优化与多尺度时空建模的港口物流智能调度系统