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

【iptables 实战】05 iptables设置网络转发实验

一、网络架构

实验效果,通过机器B的转发功能,将机器A的报文转发到机器C
本实验准备三台机器分别配置如下网络
机器A ip:192.168.56.104
机器C ip:10.1.0.10
机器B 两张网卡,分别的ip是192.168.56.106和10.1.0.11
如图所示
在这里插入图片描述

如下图所示

二、虚拟机网卡设置

设置两个host-Only的局域网

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

机器A的网络设置如下:
在这里插入图片描述

机器B的网络设置如下:
两个网卡,分别连接两个局域网

在这里插入图片描述
在这里插入图片描述

机器C的网卡配置如下:
在这里插入图片描述

三、虚拟机网络设置

A机器
在这里插入图片描述

B机器
在这里插入图片描述

连接局域网的,实际上有两个网卡
enp0s8网卡设置如下:
在这里插入图片描述

enp0s9网卡设置如下:
在这里插入图片描述

C机器
在这里插入图片描述

配置好三台机器的网络以后,
尝试A(192.168.56.104) ping B(192.168.56.106)

[root@localhost network-scripts]# ping 192.168.56.106
PING 192.168.56.106 (192.168.56.106) 56(84) bytes of data.
64 bytes from 192.168.56.106: icmp_seq=1 ttl=64 time=1.12 ms
64 bytes from 192.168.56.106: icmp_seq=2 ttl=64 time=0.861 ms

C(10.1.0.10) ping B(10.1.0.11)

[root@localhost ~]# ping 10.1.0.11
PING 10.1.0.11 (10.1.0.11) 56(84) bytes of data.
64 bytes from 10.1.0.11: icmp_seq=1 ttl=64 time=0.933 ms
64 bytes from 10.1.0.11: icmp_seq=2 ttl=64 time=0.899 ms

可以发现 A和B ,C和B都是互通的
但是此时A和C不能互通
因此需要下面的步骤开启机器B的转发功能

四、开启作为路由机B的转发功能

/etc/sysctl.conf设置如下配置

[root@localhost ~]# cat /etc/sysctl.conf

net.ipv4.ip_forward=1
重启B机器

五、机器A和机器C的路由设置

通过手动添加路由规则,将A与机器C(10.1.0.10)的报文,都通过网关B进行处理
机器A(192.168.56.104)
注意route 设置,只在当前运行时有效,重启后就没有该路由规则了

[root@localhost network-scripts]# route add -net 10.1.0.0/16 gw 192.168.56.106
[root@localhost network-scripts]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.56.100  0.0.0.0         UG    100    0        0 enp0s8
10.1.0.0        192.168.56.106  255.255.0.0     UG    0      0        0 enp0s8
172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 docker0
192.168.56.0    0.0.0.0         255.255.255.0   U     100    0        0 enp0s8
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0

同样的,机器C(10.1.0.10)想连机器A(192.168.56.104)也得设置一下路由

[root@localhost network-scripts]# route add -net 192.168.56.0/24 gw 10.1.0.11
[root@localhost ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         10.1.0.2        0.0.0.0         UG    100    0        0 enp0s8
10.1.0.0        0.0.0.0         255.255.0.0     U     100    0        0 enp0s8
172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 docker0
192.168.56.0    10.1.0.11       255.255.255.0   UG    0      0        0 enp0s8
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0

机器A(192.168.56.104)ping 机器C(10.1.0.10)

[root@localhost network-scripts]# ping 10.1.0.10
PING 10.1.0.10 (10.1.0.10) 56(84) bytes of data.
64 bytes from 10.1.0.10: icmp_seq=1 ttl=63 time=1.51 ms
64 bytes from 10.1.0.10: icmp_seq=2 ttl=63 time=1.61 ms

机器C(10.1.0.10)ping机器A(192.168.56.104)

[root@localhost ~]# ping 192.168.56.104
PING 192.168.56.104 (192.168.56.104) 56(84) bytes of data.
64 bytes from 192.168.56.104: icmp_seq=1 ttl=63 time=1.62 ms
64 bytes from 192.168.56.104: icmp_seq=2 ttl=63 time=1.75 ms

现在,A和C机器,就可以互通了

http://www.lryc.cn/news/181004.html

相关文章:

  • pygame - 贪吃蛇小游戏
  • 基于 QT 实现 Task Timer,高效利用时间
  • 图像处理与计算机视觉--第五章-图像分割-霍夫变换
  • linux下文件操作命令
  • Golang语法、技巧和窍门
  • Grander因果检验(格兰杰)原理+操作+解释
  • Python-Flask:编写自动化连接demo脚本:v1.0.0
  • kafka客户端应用参数详解
  • Apache Doris 行列转换可以这样玩
  • 【Qt图形视图框架】自定义QGraphicsItem和QGraphicsView,实现鼠标(移动、缩放)及键盘事件、右键事件
  • C语言结构体指针学习
  • 华为云云耀云服务器L实例评测|部署在线轻量级备忘录 memos
  • 详解Avast Driver Updater:电脑驱动更新工具的利器还是多余的软件?
  • 大数据Flink(九十五):DML:Window TopN
  • 使用OKHttpClient访问网络
  • maui 开发AMD CPU踩的坑。
  • 宝塔反代openai官方API接口详细教程,502 Bad Gateway问题解决
  • 【leetocde】128. 最长连续序列
  • 【Vue3】动态 class 类
  • 【Redis】redis基本数据类型详解(String、List、Hash、Set、ZSet)
  • ubuntu源码安装aria2
  • 【多任务案例:猫狗脸部定位与分类】
  • .Net 锁的介绍
  • Office 2021 小型企业版商用办公软件评测:提升工作效率与协作能力的专业利器
  • Monkey测试
  • wzx-jmw:NFL合理,但可能被颠覆。2023-2024
  • 密码技术 (5) - 数字签名
  • php实战案例记录(10)单引号和双引号的用法和区别
  • 嵌入式Linux应用开发-基础知识-第十九章驱动程序基石②
  • trycatch、throw、throws