【网络实验】/主机/路由器/交换机/网关/路由协议/RIP+OSPF/DHCP(上)+https://developer.aliyun.com/article/1623574
测试一下成功:
PC>ping 10.0.0.2 Ping 10.0.0.2: 32 data bytes, Press Ctrl_C to break From 10.0.0.2: bytes=32 seq=1 ttl=254 time=31 ms From 10.0.0.2: bytes=32 seq=2 ttl=254 time=16 ms From 10.0.0.2: bytes=32 seq=3 ttl=254 time=15 ms From 10.0.0.2: bytes=32 seq=4 ttl=254 time=16 ms From 10.0.0.2: bytes=32 seq=5 ttl=254 time=16 ms --- 10.0.0.2 ping statistics --- 5 packet(s) transmitted 5 packet(s) received 0.00% packet loss round-trip min/avg/max = 15/18/31 ms
4.2配置动态路由
常见动态路由协议:
- rip(适用小型网络)
- ospf(适用大型网络)
4.2.1首先RIP配置动态路由(最简单的)
测试:
测试一下成功:
PC>ping 10.0.0.2 Ping 10.0.0.2: 32 data bytes, Press Ctrl_C to break From 10.0.0.2: bytes=32 seq=1 ttl=254 time=31 ms From 10.0.0.2: bytes=32 seq=2 ttl=254 time=16 ms From 10.0.0.2: bytes=32 seq=3 ttl=254 time=15 ms From 10.0.0.2: bytes=32 seq=4 ttl=254 time=16 ms From 10.0.0.2: bytes=32 seq=5 ttl=254 time=16 ms --- 10.0.0.2 ping statistics --- 5 packet(s) transmitted 5 packet(s) received 0.00% packet loss round-trip min/avg/max = 15/18/31 ms
4.2.2然后用OSPF配置动态路由
首先划分单区域area0、1、2:
然后进入路由器1:
<Huawei>undo termin <Huawei>undo terminal mon <Huawei>undo terminal monitor Info: Current terminal monitor is off. <Huawei> <Huawei>sys Enter system view, return user view with Ctrl+Z. ##第一步:进入ospf命令 [Huawei]ospf ##划分区域0 [Huawei-ospf-1]area 0 ##network直连网段和反子网掩码 [Huawei-ospf-1-area-0.0.0.0]network 10.0.0.0 0.0.0.255 [Huawei-ospf-1-area-0.0.0.0]network 192.168.1.0 0.0.0.255 [Huawei-ospf-1-area-0.0.0.0]q [Huawei-ospf-1]q ##查看路由表项: [Huawei]dis ip routing-table Route Flags: R - relay, D - download to fib ------------------------------------------------------------------------------ Routing Tables: Public Destinations : 11 Routes : 11 Destination/Mask Proto Pre Cost Flags NextHop Interface 10.0.0.0/24 Direct 0 0 D 10.0.0.1 GigabitEthernet 0/0/0 10.0.0.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet 0/0/0 10.0.0.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet 0/0/0 127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0 127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0 127.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0 192.168.1.0/24 Direct 0 0 D 192.168.1.254 GigabitEthernet 0/0/1 192.168.1.254/32 Direct 0 0 D 127.0.0.1 GigabitEthernet 0/0/1 192.168.1.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet 0/0/1 ##重点: 192.168.2.0/24 OSPF 10 2 D 10.0.0.2 GigabitEthernet 0/0/0 255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0 [Huawei] Please check whether system data has been changed, and save data in time Configuration console time out, please press any key to log on
进入路由器2:
<Huawei>sys Enter system view, return user view with Ctrl+Z. ##第一步:进入ospf命令 [Huawei]ospf ##划分区域0 [Huawei-ospf-1]area 0 ##network直连网段和反子网掩码 [Huawei-ospf-1-area-0.0.0.0]network 192.168.2.0 0.0.0.255 [Huawei-ospf-1-area-0.0.0.0]network 10.0.0.0 0.0.0.255 [Huawei-ospf-1-area-0.0.0.0] ##查看路由表项: [Huawei]dis ip routing-table Route Flags: R - relay, D - download to fib ------------------------------------------------------------------------------ Routing Tables: Public Destinations : 11 Routes : 11 Destination/Mask Proto Pre Cost Flags NextHop Interface 10.0.0.0/24 Direct 0 0 D 10.0.0.2 GigabitEthernet 0/0/0 10.0.0.2/32 Direct 0 0 D 127.0.0.1 GigabitEthernet 0/0/0 10.0.0.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet 0/0/0 127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0 127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0 127.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0 ##(重点)192.168.1.0/24 OSPF 10 2 D 10.0.0.1 GigabitEthernet 0/0/0 192.168.2.0/24 Direct 0 0 D 192.168.2.254 GigabitEthernet 0/0/1 192.168.2.254/32 Direct 0 0 D 127.0.0.1 GigabitEthernet 0/0/1 192.168.2.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet 0/0/1 255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0 [Huawei] Please check whether system data has been changed, and save data in time Configuration console time out, please press any key to log on
测试:
4.3配置单臂路由(实现不同vlan之间的单臂互通)
单臂路由是指在路由器的一个接口上通过配置子接口(或“逻辑接口”,并不存在真正物理接口)的方式,实现原来相互隔离的不同VLAN(虚拟局域网)之间的互联互通。
这里设置的逻辑子接口为 1.1 、1.2 、1.3
先配置IP、子网掩码、网关如下图:
然后进入交换机配置:
The device is running! ########## <Huawei> <Huawei>undo ter <Huawei>undo terminal mon <Huawei>undo terminal monitor Info: Current terminal monitor is off. <Huawei> <Huawei>sys Enter system view, return user view with Ctrl+Z. ##添加多个vlan: [Huawei]vlan batch 10 20 30 Info: This operation may take a few seconds. Please wait for a moment...done. ##进入pc1所在接口: [Huawei]int g0/0/2 ##配置好vlan,配置交换机和pc之间的链路类型为access [Huawei-GigabitEthernet0/0/2]port link-type access ##链路允许vlan 10通过: [Huawei-GigabitEthernet0/0/2]port default vlan 10 ################################################### [Huawei-GigabitEthernet0/0/2]int g0/0/3 [Huawei-GigabitEthernet0/0/3]port link-type access [Huawei-GigabitEthernet0/0/3]port default vlan 20 ################################################### [Huawei-GigabitEthernet0/0/3]int g0/0/4 [Huawei-GigabitEthernet0/0/4]port link-type access [Huawei-GigabitEthernet0/0/4]port default vlan 30 ################################################### ##配置交换机和路由器之间的链路类型为trunk模式 [Huawei-GigabitEthernet0/0/4]int g0/0/1 [Huawei-GigabitEthernet0/0/1]port link-type trunk ##允许所有vlan通过 [Huawei-GigabitEthernet0/0/1]port trunk allow-pass vlan all
最后进入路由器配置网关:
<Huawei>sys Enter system view, return user view with Ctrl+Z. ##单臂路由划分三个逻辑接口为 1.1、1.2、1.3 ##进入子接口1.1: [Huawei]int g0/0/1.1 ##配置pc1网关 [Huawei-GigabitEthernet0/0/1.1]ip address 192.168.1.254 24 ##配置vlan封装结构为帧 [Huawei-GigabitEthernet0/0/1.1]dot1q termination vid 10 [Huawei-GigabitEthernet0/0/1.1]q ############################################################## [Huawei]int g0/0/1.2 [Huawei-GigabitEthernet0/0/1.2]ip address 192.168.2.254 24 [Huawei-GigabitEthernet0/0/1.2]dot1q termination vid 20 ############################################################## [Huawei]int g0/0/1.3 [Huawei-GigabitEthernet0/0/1.3]ip address 192.168.3.254 24 [Huawei-GigabitEthernet0/0/1.3]dot1q termination vid 30 ############################################################## ##最后设置arp,开启arp子接口广播功能,pc机之间可以通信了 <Huawei> <Huawei>sys ##开启每个子接口的arp广播功能: [Huawei]int g0/0/1.1 [Huawei-GigabitEthernet0/0/1.1]arp broadcast enable ##开启每个子接口的arp广播功能: [Huawei-GigabitEthernet0/0/2]int g0/0/1.2 [Huawei-GigabitEthernet0/0/1.2]arp broadcast enable ##开启每个子接口的arp广播功能: [Huawei-GigabitEthernet0/0/1.2]int g0/0/1.3 [Huawei-GigabitEthernet0/0/1.3]arp broadcast enable
测试:
主机ping网关:
pc2 ping pc3:
五、密码模式(console端口+ctl线)
5.1简单密码模式(密码)
下图所示,系统视图和串口命令行是一样的,那边操作都可以:
开始设置密码:
<Huawei>sys Enter system view, return user view with Ctrl+Z. ##进入console用户控制台 [Huawei]user-interface console 0 ##设置简单密码模式: [Huawei-ui-console0]authentication-mode password ##设置密码:123 [Huawei-ui-console0]set authentication password cipher 123 ##设置三级控制级别 [Huawei-ui-console0]user privilege level 3 [Huawei-ui-console0]q [Huawei]q <Huawei>q User interface con0 is available Please Press ENTER. Login authentication ##进入了密码模式,需要你输入密码!! Password:
5.2AAA模式(账户+密码)
###################################### <Huawei>sys Enter system view, return user view with Ctrl+Z. ##进入用户控制台 [Huawei]user-interface console 0 ##设置密码模式为aaa模式 [Huawei-ui-console0]authentication-mode aaa [Huawei-ui-console0]q ##进入aaa模式 [Huawei]aaa ##设置密码为123 [Huawei-aaa]local-user huawei password cipher 123 Info: Add a new user. [Huawei-aaa]local-user huawei privilege level 3 [Huawei-aaa]q [Huawei]q <Huawei>q User interface con0 is available Please Press ENTER. Login authentication ##让你输入用户名密码验证: Username:huawei Password: <Huawei>sys Enter system view, return user view with Ctrl+Z.
六、secureCRT远程登录(telnet)
路由器1成功访问路由器2:
路由器1:
The device is running! <Huawei>sys Enter system view, return user view with Ctrl+Z. [Huawei]int g0/0/0 [Huawei-GigabitEthernet0/0/0]ip address 192.168.1.1 24 [Huawei-GigabitEthernet0/0/0]q [Huawei]user-interface vty 0 4 [Huawei-ui-vty0-4]authentication-mode password Please configure the login password (maximum length 16):123456 [Huawei-ui-vty0-4]user privilege level 3 [Huawei-ui-vty0-4]
路由器2登录:
<Huawei>sys Enter system view, return user view with Ctrl+Z. [Huawei]int g0/0/0 [Huawei-GigabitEthernet0/0/0]ip address 192.168.1.2 24 [Huawei-GigabitEthernet0/0/0]q [Huawei]q <Huawei>telnet 192.168.1.1
如下图登录成功:
七、DHCP(动态主机分配协议)
DHCP:让主机动态获取ip地址,就不需要手工繁琐人工配置IP地址了。
路由器:
<Huawei>sys Enter system view, return user view with Ctrl+Z. ##进入dhcp功能: [Huawei]dhcp enable Info: The operation may take a few seconds. Please wait for a moment.done. ##定义ip池名为1 [Huawei]ip pool 1 ##选择地址池的范围+子网掩码mask [Huawei-ip-pool-1]network 192.168.1.0 mask 255.255.255.0 ##定义网关: [Huawei-ip-pool-1]gateway-list 192.168.1.1 ##添加排除地址、设置不参与自动分配的IP地址 [Huawei-ip-pool-1]excluded-ip-address 192.168.1.2 192.168.1.253 ##定义dns网关地址: [Huawei-ip-pool-1]dns-list 8.8.8.8 [Huawei-ip-pool-1]q [Huawei]int g0/0/0 ##绑定网关: [Huawei-GigabitEthernet0/0/0]ip address 192.168.1.1 24 ##dhcp选择全局分配、接口下使能全局方式分配地址 [Huawei-GigabitEthernet0/0/0]dhcp select global
上图获取成功!
八、链路聚合
链路聚合==本质就是将两个交换机变成逻辑上的一根线。
8.1手动模式【动态模式为LACP】
交换机1:
<Huawei>sys ##创建并配置编号为1的Eth-Trunk端口 [Huawei]int Eth-Trunk 1 ##指定手动模式 [Huawei-Eth-Trunk1]mode manual load-balance [Huawei-Eth-Trunk1]int g0/0/1 ##将接口0/0/1加入到trunk1下 [Huawei-GigabitEthernet0/0/1]eth-trunk 1 [Huawei-GigabitEthernet0/0/1]int g0/0/2 ##将接口0/0/2加入到trunk1下 [Huawei-GigabitEthernet0/0/2]eth-trunk 1 [Huawei-GigabitEthernet0/0/2]
交互机2(同上):
<Huawei>sys [Huawei]int Eth-Trunk 1 [Huawei-Eth-Trunk1]mode manual load-balance [Huawei-Eth-Trunk1]int g0/0/1 [Huawei-GigabitEthernet0/0/1]eth-trunk 1 [Huawei-GigabitEthernet0/0/1]int g0/0/2 [Huawei-GigabitEthernet0/0/2]eth-trunk 1 [Huawei-GigabitEthernet0/0/2]
看是否开启成功:
##查看开启是否成功: [Huawei]dis eth-trunk 1 Eth-Trunk1's state information is: WorkingMode: NORMAL Hash arithmetic: According to SIP-XOR-DIP Least Active-linknumber: 1 Max Bandwidth-affected-linknumber: 8 Operate status: up Number Of Up Port In Trunk: 2 -------------------------------------------------------------------------------- ##开启成功: PortName Status Weight GigabitEthernet0/0/1 Up 1 GigabitEthernet0/0/2 Up 1 [Huawei]