BUPT 计网实践不完全指北

2965 字
15 分钟
BUPT 计网实践不完全指北
  1. 1BUPT计科专业生存不完全指北
  2. 2BUPT 计网实践不完全指北本文

写在前面#

计算机网络实践这门课每个老师使用的仿真器并不相同,如果你有幸选了zhy老师的课,那么恭喜你,你将穿越回 2007 年,和 BUPT 的历届计算机学子一起,使用原本在 Windows XP 系统上构建的仿真器 Dynamips 进行实验,由于年代久远,实验中发生不稳定现象也是常有的事。

这篇文章主要是记录一下实验过程(前三次实验应该不用交报告,所以这里只是不正式的记录一下)。

实验环境配置#

简介#

  • Dynamips 是一个 Cisco 路由器模拟软件。它可以模拟 Cisco 2600,2691,3620,3640,3660,3725,3745 和 Cisco7206 硬件平台,而且可以运行标准的 Cisco IOS 文件。
  • Dynagen 是 Dynamips 的一个基于文本的前端控制系统,它采用“Hypervisor”超级监控模式和 Dynamips 通信。Dynagen 简化了虚拟网络的创建和工作,主要用于模拟网络拓扑。

你可以简单理解为后端和前端的区别,以下是我的实验环境,之后在老师退休前的若干年使用的仿真器也大抵如此:

配置项参数
操作系统Windows 10 22H2 (OS Build 19045.2965)
网络模拟器Dynamips 0.2.7 By N.L.F.E(后端)
Dynagen 0.11.0(前端)

为了不污染本地环境,我装了个 Windows 10 的虚拟机,网卡选择的是桥接模式,这样不用额外配置端口映射等,便于远程连接。另外如果你在后续操作中找不到 telnet 命令,请通过以下方式启用 Windows 内置 Telnet 客户端

  1. 在 Windows 里打开 控制面板 → 程序和功能 → 启用或关闭 Windows 功能
  2. 勾选 Telnet 客户端
  3. 确定后等待安装完成

安装 WinPcap#

WinPcap,一个底层驱动,用于捕捉数据包和绕过协议栈方式来进行数据传输,通过运行 setup 目录下的 1.安装Win_Pcap.cmd 是无法直接在 Windows10 系统上进行安装的,你可以运行老师发的 WinPcap_4_1_3.exe,或者将脚本中的可执行文件版本替换成以下内容再通过脚本安装:

Terminal window
@echo off
call ../bin/script/copyright.cmd
echo * 按任意键开始安装WinPcap *
echo *=============================================================================*
cd ..
cd bin
cd winpcap
WinPcap_4_1_3.exe
exit

安装过程一路 next 就行。

设置网卡参数#

这步直接在 setup 目录下运行 2.修改网卡参数.cmd 大概率得不到输出的网卡参数,通过该脚本得知其通过调用 /bin/script/get_para.php 获取网卡参数,而 get_para.php 又是通过调用 bin/dynamips/dynamips-wxp.exe 获取网卡信息并通过正则表达式提取的。

直接运行 bin/dynamips/dynamips-wxp.exe 可以正确得到网卡信息:

问题大概率是在正则表达式上,但是尝试修改仍有问题,所以干脆直接把上面的信息复制下来,即 \Device\NPF_{xxxxxx} 就是网卡参数,你也可以通过在终端运行:

Terminal window
getmac

得到:

将上面内容中的 Tcpip 改为 NPF 也还是一样的。

实验一:基本交换机配置#

启动前后端#

  1. 运行 0.虚拟服务XP&2003.exe 启动后端;

    其中有用的事实上就以下 2 句:

    Terminal window
    cd tmp
    start /belownormal /B /wait "Dynamips" "../bin/dynamips/dynamips-wxp.exe" -H 7200

    其中:

    • tmp 一般用来存放 Dynamips 的临时文件或运行环境,比如 idlepc 数据库;
      • 启动 dynamips-wxp.exe 程序:
      • H 7200 表示 Dynamips 将监听 7200端口,用于和前端软件(如 Dynagen)通信;
      • /belownormal 让进程以较低优先级运行,避免占用过多 CPU;
      • /B 表示不打开新的命令窗口,在后台运行;
      • /wait 表示等待进程结束后才返回;
      • "Dynamips" 是启动窗口的标题;

  2. 运行 bupt_sw.cmd 启动交换机实验环境(前端);

    该脚本有用的内容也只有以下内容:

    Terminal window
    cd tmp
    "../bin/dynagen/dynagen.exe" ..\net\bupt_sw.net

    即 运行 dynagen.exe 并把 ..\net\bupt_sw.net 作为输入拓扑文件。

实验用拓扑#

bupt_sw.net 文件内容如下:

autostart = False
[localhost]
port = 7200
udp = 10000
workingdir = ..\tmp\
[[router SW1]]
image = ..\ios\unzip-c3640-js-mz.124-10.bin
model = 3640
console = 3003
ram = 128
confreg = 0x2142
exec_area = 64
mmap = False
slot1 = NM-16ESW
f1/1 = SW2 f1/2
f1/2 = SW2 f1/1
f1/11 = PC1 f0/0
f1/12 = PC2 f0/0
[[router SW2]]
image = ..\ios\unzip-c3640-js-mz.124-10.bin
model = 3640
console = 3004
ram = 128
confreg = 0x2142
exec_area = 64
mmap = False
slot1 = NM-16ESW
f1/11 = PC3 f0/0
[[router PC1]]
model = 2621
ram = 20
image = ..\ios\unzip-c2600-i-mz.121-3.T.bin
mmap = False
confreg = 0x2142
console = 3006
[[router PC2]]
model = 2621
ram = 20
image = ..\ios\unzip-c2600-i-mz.121-3.T.bin
mmap = False
confreg = 0x2142
console = 3007
[[router PC3]]
model = 2621
ram = 20
image = ..\ios\unzip-c2600-i-mz.121-3.T.bin
mmap = False
confreg = 0x2142
console = 3008

其中:

  • autostart = False 表示 Dynagen 载入拓扑后 不会自动启动设备,需要在 Dynagen 控制台中手动启动;
  • localhost:指 Dynagen 要连接的 Dynamips 服务端运行在本机上。
  • port = 7200:对应前一个脚本里 Dynamips 启动参数 -H 7200。Dynagen 会通过 TCP 7200 端口控制 Dynamips。
  • udp = 10000:设置 Dynamips 实例的起始 UDP 端口(用于设备之间的帧交换通信)。
  • workingdir = ..\tmp\**:Dynagen 会把各个设备的启动配置、NVRAM、快照等文件存放在这个路径中。
[[router SW1]]
image = ..\ios\unzip-c3640-js-mz.124-10.bin
model = 3640
console = 3003
ram = 128
confreg = 0x2142
exec_area = 64
mmap = False
slot1 = NM-16ESW
f1/1 = SW2 f1/2
f1/2 = SW2 f1/1
f1/11 = PC1 f0/0
f1/12 = PC2 f0/0
  • 表示一台 Cisco 3640 路由器,加载了一个带交换模块的 IOS。
  • slot1 = NM-16ESW 表示插入了一块 16端口交换模块。
  • console = 3003 表示可通过 TCP 3003 端口连接控制台(例如用 telnet)。
  • ram = 128 设置虚拟机内存大小(单位 MB)。
  • image 指向 IOS 文件路径。
  • 端口连接如下:
    • SW1 的 FastEthernet1/1 ↔ SW2 的 FastEthernet1/2
    • SW1 的 FastEthernet1/2 ↔ SW2 的 FastEthernet1/1(即双链路连接)
    • SW1 的 FastEthernet1/11 ↔ PC1 的 FastEthernet0/0
    • SW1 的 FastEthernet1/12 ↔ PC2 的 FastEthernet0/0

SW1 和 SW2 介绍略。

[[router PC1]]
model = 2621
ram = 20
image = ..\ios\unzip-c2600-i-mz.121-3.T.bin
mmap = False
confreg = 0x2142
console = 3006
  • 模型:Cisco 2621(轻量路由器)
  • RAM 仅 20 MB
  • IOS 文件:unzip-c2600-i-mz.121-3.T.bin
  • 可以通过 Telnet 连接相应端口访问(例如 telnet localhost 3006)。

对应的拓扑图如下:

启动设备#

  1. 启动 SW1:

    Terminal window
    start SW1
  2. 设置 idlepc(该设备的 CPU 占用率):

    Terminal window
    idlepc get SW1

    等待一段时间后,选择具有 * 号且括号中数值最大项的序号作为 idlepc 值(如果都没有 * 可以再重新统计一次),例如:

    保存:

    Terminal window
    idlepc save SW1 db

    由于 PC 和 SW 使用的是不同的设备,所以也要在启动 PC1 时按照上述方法配置以下,演示略。

  3. 配置设备;

    在新的 cmd 窗口中输入:

    Terminal window
    telnet localhost 3006

    输入 en 进入配置权限(show running-config 用于查看当前配置内容):

    输入 conf t 进入配置命令行;

    通过 interface fx/y 配置指定端口,通过 ip add x.y.z.w 255.0.0.0 添加端口对应的 IP 地址。

    比如为该接口分配一个 IPv4 地址:

    • IP 地址:1.1.1.1
    • 子网掩码:255.0.0.0(即 /8)

    这意味着 PC1 所在的网络为 1.0.0.0/8。

    本实验需要配置的内容如下:

    Terminal window
    # start and configure SW1
    start SW1
    # start and configure PC1
    start PC1
    telnet localhost 3006
    en
    conf t
    interface f0/0
    ip add 1.1.1.1 255.0.0.0
    no shutdown # 开启接口(Cisco 默认接口是 shutdown 的)
    exit
    no cdp run # CDP 是 Cisco 的邻居发现协议,一般在“PC 模拟设备”上没必要运行。关闭它可以减少不必要的控制流量
    exit
    # configure PC2
    start PC2
    telnet localhost 3007
    en
    conf t
    interface f0/0
    ip add 1.1.1.2 255.0.0.0
    no shutdown # 开启接口(Cisco 默认接口是 shutdown 的)
    exit
    no cdp run # CDP 是 Cisco 的邻居发现协议,一般在“PC 模拟设备”上没必要运行。关闭它可以减少不必要的控制流量
    exit

    以 PC2 为例:

    配置完后,网络的拓扑如下:

    此时 PC1 和 PC2 互 Ping,Ping 通即说明成功:

    启用并配置剩余的节点:

    Terminal window
    # start and configure SW2
    start SW2
    # start and configure PC1
    start PC1
    telnet localhost 3008
    en
    conf t
    interface f0/0
    ip add 1.1.1.3 255.0.0.0
    no shutdown # 开启接口(Cisco 默认接口是 shutdown 的)
    exit
    no cdp run # CDP 是 Cisco 的邻居发现协议,一般在“PC 模拟设备”上没必要运行。关闭它可以减少不必要的控制流量
    exit

    配置完后拓扑结构如下:

    此时 PC1 和 PC3 互 Ping,Ping 通即说明成功:

实验二:路由器的简单配置#

说明#

本实验用到的网络拓扑结构如下,配置见 net/bupt_RT.net:

配置步骤#

  1. 在 Dynamips 中启动:

    Terminal window
    start R1
    start R2
    start PC1
    start PC2
  2. 配置 R1 和 R2 间的连接

    Terminal window
    # R1
    telnet localhost 3001
    R1>en
    R1#conf t
    R1(config)#interface s1/1
    R1(config-if)#clock rate 115200
    R1(config-if)#ip add 1.1.1.1 255.0.0.0
    R1(config-if)#encapsulation PPP
    R1(config-if)#no shutdown
    # 注意这里会观察到 s1/1 未启动,这是因为点对点(PPP)链路需要两端串口均配置完毕,等 R2 配置完就能观察到输出 s1/1 正确启动了
    # R2
    telnet localhost 3002
    R2>en
    R2#conf t
    R2(config)#interface s1/0
    R2(config-if)#ip add 1.1.1.2 255.0.0.0
    R2(config-if)#encapsulation PPP
    R2(config-if)#no shutdown
    # 这里可以先测试一下 R1 和 R2 链路是否能 Ping 通
  3. 配置 R1 与 PC1,R2 与 PC2 连接

    Terminal window
    # PC1
    telnet localhost 3003
    PC1>en
    PC1#cont
    PC1(config)#interface f0/0
    PC1(config-if)#ip add 2.1.1.2 255.0.0.0
    # R1
    R1(config)#interface f0/0
    R1(config-if)#ip add 2.1.1.1 255.0.0.0
    # PC2
    telnet localhost 3004
    PC2>en
    PC2#cont
    PC2(config)#interface f0/0
    PC2(config-if)#ip add 3.1.1.2 255.0.0.0
    # R2
    R2(config)#interface f0/0
    R2(config-if)#ip add 3.1.1.1 255.0.0.0
    # 此时可以测试一下 PC1 和 R1,PC2 和 R2 之间的链路是否能 Ping 通
    # 需要注意的是此时 PC1 和 R2,PC1 和 PC2 之间还是无法 Ping 通的,因为还没有配置路由表
  4. 配置路由表

    Terminal window
    # R1
    R1(config)#ip route 3.0.0.0 255.0.0.0 serial 1/1
    # R2
    R2(config)#ip route 2.0.0.0 255.0.0.0 serial 1/0
    # PC1
    PC1(config)#ip route 0.0.0.0 0.0.0.0 F 0/0
    # PC2
    PC2(config)#ip route 0.0.0.0 0.0.0.0 F 0/0

实验结果#

  1. Ping 一下 PC1 和 PC2

    Terminal window
    PC1>ping 3.1.1.2
    PC2>ping 2.1.1.2

    注:如果是第一次 Ping,你基本可以重复复现第一次失败,即(4/5),这是因为当主机/路由器第一次向目标 IP 发送报文时,若本地 ARP 缓存没有目标 IP 对应的 MAC 地址,会先发出 ARP 请求(广播)等待 ARP 回复。第一个 ICMP echo 请求要等到 ARP 完成才能被正确封装并发送出去,因此第一个请求常常“超时/丢失”。随后 ARP 被学到,后面的包就能成功到达。

    你可以通过在第一次 Ping 前后分别运行 show ip arp 查看 ARP 解析表验证这一点。

  2. 查看一下路由表

常用 Dynagen 命令速查表#

命令作用示例
list显示当前拓扑中所有设备及状态list
start <设备名>启动指定设备start SW1
start /all启动所有设备start /all
stop <设备名>停止指定设备stop SW1
stop /all停止所有设备stop /all
console <设备名>连接到设备的控制台(telnet 到对应端口)console SW1
reload <设备名>重启指定设备(相当于reload命令)reload PC1
telnet <地址> <端口>连接到地址对应的设备控制台telnet localhost 3001

常用 Dynamips 命令速查表#

命令作用示例
用户模式提示符形如:PC1>
en特权模式提示符形如:PC1#
conf t全局配置模式提示符形如:PC1(config)#
interface fx/y 或 interface sx/y接口配置模式提示符形如:PC1(config-if)#
exit退出当前配置模式返回上一级
(PC1#) hostname othername改名提示符变为:othername#
(PC1#) show ip route显示当前的路由表信息
(PC1#) show ip arp显示当前 ARP 解析信息
(PC1(config)#) no cdp runCDP 是 Cisco 的邻居发现协议,一般在“PC 模拟设备”上没必要运行。关闭它可以减少不必要的控制流量
(PC1(config)#) ip route 0.0.0.0 0.0.0.0 f0/0配置默认路由,如果路由表中没有匹配到其他更具体路由,就把包交给 FastEthernet 0/0接口发出去。
(R1(config)#) ip route 3.0.0.0 255.0.0.0 serial 1/1配置静态路由,如果要去往 3.0.0.0/8 网络的数据包,就从 Serial 1/1 接口发出去。
(PC1(config-if)#) ip add \<ip addr\> \<mask\>配置接口的 IP 地址ip add 2.1.1.1 255.0.0.0
no \<instruction\>撤回配置错误的指令no ip add 2.1.1.1 255.0.0.0
(R1(config-if)#) clock rate \<clockrate\>配置路由器 DCE 串口的时钟速率,单位为 kbps(DTE 端不要配置)clock rate 115200
(R1(config-if)#) encapsulation PPP配置路由器的串口的数据链路层协议(默认为 HDLC)encapsulation PPP
(PC1(config-if)#) no shutdown启动当前接口

文章分享

如果这篇文章对你有帮助,欢迎分享给更多人!

BUPT 计网实践不完全指北
https://blog.yokumi.cn/posts/an-incomplete-guide-to-bupt-computer-networking-practice/
作者
Yokumi
发布于
2025-10-03
许可协议
CC BY-NC-SA 4.0

评论区

文章目录