当前位置: 首页 > 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

相关文章:

  • golang常用库之-go-feature-flag库(特性开关(Feature Flags))
  • 关于面试找工作的总结(四)
  • Linux容器篇、第一章_02Rocky9.5 系统下 Docker 的持久化操作与 Dockerfile 指令详解
  • 电子电路:共集电极放大器原理与作用解析
  • MySQL JSON 查询中的对象与数组技巧
  • nginx配置
  • DeviceNET从站转EtherNET/IP主站在盐化工行业的创新应用
  • STM32L0看门狗设置LL库
  • 《Vuejs设计与实现》第 7 章(渲染器的设计)
  • 一个小小的 flask app, 几个小工具,拼凑一下
  • 【Linux】Linux 环境变量
  • skynet monitor线程的作用
  • Webpack常见的插件和模式
  • STM32最小CLion开发环境
  • MYSQL之表的内连和外连
  • ABP-Book Store Application中文讲解 - Part 9: Authors: User Interface
  • 3D旋转动态爱心 - Python创意代码
  • 缓存控制HTTP标头设置为“无缓存、无存储、必须重新验证”
  • AtCoder-abc407_e解析
  • Nginx+Tomcat负载均衡与动静分离架构
  • 网站推广的方式有哪些/seo快速排名软件价格
  • 企业vi设计的作用与意义/seo还有前景吗
  • 红酒网站源码/深圳网络营销的公司哪家好
  • 网站建设职能/手机seo快速排名
  • 发稿类别是什么/sem和seo是什么职业
  • 上海浦东建筑建设网站污水处理工程/新网站排名优化怎么做