三层架构-pc通外网小实验

要求:pc端能上外网(isp)

效果图:pc1(VLAN2)和pc3(vlan3)都能ping通2.2.2.2(R2环回)

代码:#先配置好r1,r2,端口ip

#

[R1]

ip route-static 0.0.0.0 0.0.0.0 10.1.1.2

acl 2000

rule permit source any 

interface GigabitEthernet0/0/2
 nat outbound 2000                #R2只配置ip没有静态,r1要用nat才能通r2

ospf 1 router-id 1.1.1.1 
 default-route-advertise        #下放缺省
 area 0.0.0.0 
  network 1.1.1.1 0.0.0.0 
  network 11.1.1.1 0.0.0.0 
  network 12.1.1.1 0.0.0.0 

[SW1]        #g0/0/3,g0/0/4设为access链路,g0/0/5为trunk链路,代码省略

vlan batch 2 to 3

interface Vlanif1                        #交换机没有物理接口地址,只能在vlan里配置
 ip address 11.1.1.2 24

ospf 1 router-id 2.2.2.2
 area 0.0.0.0
  network 0.0.0.0 255.255.255.255

interface Eth-Trunk 1                                #将g0/0/2,g0/0/6,g0/0/7聚合为1条逻辑线路
 port link-type trunk
 port trunk allow-pass vlan all

interface GigabitEthernet0/0/2                #g0/0/6和g0/0/7同理
 eth-trunk 1                                                

interface Vlanif2
 ip address 192.168.1.1 255.255.255.0
 vrrp vrid 1 virtual-ip 192.168.1.1
 vrrp vrid 1 priority 120
 vrrp vrid 1 preempt-mode timer delay 20
 dhcp select global

interface Vlanif3
 ip address 172.16.1.1 255.255.255.0
 vrrp vrid 2 virtual-ip 172.16.1.1
 vrrp vrid 2 preempt-mode timer delay 20
 dhcp select global

stp mode mstp                 #华为软件eNSP默认开启mstp

stp region-configuration
 instance 1 vlan 2
 instance 2 vlan 3
 active region-configuration

stp instance 1 root primary                        #设置SW1为vlan 2生成树的根
stp instance 2 root secondary

dhcp enable

ip pool 1
 gateway-list 192.168.1.1
 network 192.168.1.0 mask 255.255.255.0
 dns-list 8.8.8.8

ip pool 2
 gateway-list 172.16.1.1
 network 172.16.1.0 mask 255.255.255.0
 dns-list 8.8.8.8

[SW2]        #g0/0/3,g0/0/4设为access链路,g0/0/5为trunk链路,代码省略  

vlan batch 2 to 3

interface Vlanif1
 ip address 12.1.1.2 24

ospf 1 router-id 3.3.3.3
 area 0.0.0.0
  network 0.0.0.0 255.255.255.255

interface Eth-Trunk 1                                #将g0/0/2,g0/0/6,g0/0/7聚合为1条逻辑线路
 port link-type trunk
 port trunk allow-pass vlan all

interface GigabitEthernet0/0/2                #g0/0/6和g0/0/7同理
 eth-trunk 1                                                

interface Vlanif2
 ip address 192.168.1.2 255.255.255.0
 vrrp vrid 1 virtual-ip 192.168.1.2
 dhcp select global

interface Vlanif3
 ip address 172.16.1.2 255.255.255.0
 vrrp vrid 2 virtual-ip 172.16.1.2
 vrrp vrid 2 priority 120
 vrrp vrid 2 preempt-mode timer delay 20
 dhcp select global

stp mode mstp 

stp region-configuration
 instance 1 vlan 2
 instance 2 vlan 3
 active region-configuration

stp instance 1 root secondary
stp instance 2 root primary

dhcp enable

ip pool 1
 gateway-list 192.168.1.2
 network 192.168.1.0 mask 255.255.255.0
 dns-list 8.8.8.8

ip pool 2
 gateway-list 172.16.1.2
 network 172.16.1.0 mask 255.255.255.0
 dns-list 8.8.8.8

[SW3]        #e0/0/1,e0/0/2,e0/0/3,e0/0/4都设为access链路

vlan 2

port-group 1

group-member e0/0/1 to e0/0/4

port link-type access 

port default vlan 2

[SW4]        #e0/0/1,e0/0/2,e0/0/3,e0/0/4都设为access链路

vlan 2

port-group 1

group-member e0/0/1 to e0/0/4

port link-type access 

port default vlan 3

[SW5]        #e0/0/1,e0/0/2为trunk链路,e0/0/3,e0/0/4为access链路

vlan batch 2 to 3

interface Ethernet0/0/1
 port link-type trunk
 port trunk allow-pass vlan all

interface Ethernet0/0/2
 port link-type trunk
 port trunk allow-pass vlan all

interface Ethernet0/0/3
 port link-type access
 port default vlan 2

interface Ethernet0/0/4
 port link-type access
 port default vlan 3

相关推荐

最近更新

  1. TCP协议是安全的吗?

    2024-01-26 16:44:01       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-01-26 16:44:01       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-01-26 16:44:01       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-01-26 16:44:01       20 阅读

热门阅读

  1. ES6对象新增了哪些扩展?

    2024-01-26 16:44:01       35 阅读
  2. Linux系统安全加固规范

    2024-01-26 16:44:01       32 阅读
  3. C++从零开始的打怪升级之路(day21)

    2024-01-26 16:44:01       34 阅读
  4. 轻松学 Vue.js3.0 开启前端开发新篇章

    2024-01-26 16:44:01       35 阅读
  5. kotlin 项目中文件显示带.kt 结尾与不带.kt结尾

    2024-01-26 16:44:01       34 阅读
  6. 「HDLBits题解」Shift Registers

    2024-01-26 16:44:01       34 阅读
  7. Adb windows脚本

    2024-01-26 16:44:01       30 阅读
  8. 【.NET Core】深入理解任务并行库 (TPL)

    2024-01-26 16:44:01       29 阅读