PC通过路由器连接交换机(用路由器连接交换机)

小编:迷魂冰 更新时间:2022-04-13
PC通过路由器连接交换机(用路由器连接交换机)

PC通过路由器远程连接交换机

基本环境介绍:

PC:192.168.0.2/24 GW:192.168.0.1

路由器:FastEthernet 0/0 接口连接PC的 FastEthernet接口

FastEthernet 0/1 接口连接交换机的 FastEthernet 0/1接口。

FastEthernet 0/0 IP:192.168.0.1/24

FastEthernet 0/1 IP:192.168.1.1/24

交换机: FastEthernet 0/1接口连接路由器的 FastEthernet 0/1接口。

管理地址VLAN 1:192.168.1.2/24 GW:192.168.1.1

设置默认网关为:192.168.1.1/24。

配置过程如下:

PC: 配置--接口--FastEthernet 设置静态IP:192.168.0.2 子网掩码:255.255.255.0 配置--全局--设置 设置静态网关:192.168.0.1 DNS服务器:114.114.114.114 路由器: Router>enable 进入特权exec模式 Router#configure terminal 从特权exec模式切换到全局配置模式 Router(config)#interface fastEthernet 0/0 指定接口并且进入接口配置模式 Router(config-if)#ip address 192.168.0.1 255.255.255.0 配置路由器接口IP地址和子网掩码 Router(config-if)#no shutdown 启用接口 Router(config-if)#exit 退出到上一层全局配置模式 Router(config)#interface fastEthernet 0/1 指定接口并且进入接口配置模式 Router(config-if)#ip address 192.168.1.1 255.255.255.0 配置路由器接口IP地址和子网掩码 Router(config-if)#no shutdown 启用接口 Router(config-if)#exit 退出到上一层全局配置模式 Router(config)#end 完全退出配置模式,并且进入特权exec模式。 Router#write 保存当前运行配置 交换机: Switch>enable 进入特权exec模式 Switch#configure terminal 从特权exec模式切换到全局配置模式 Switch(config)#interface vlan 1 进入vlan 1配置模式 Switch(config-if)#ip address 192.168.1.2 255.255.255.0 配置交换机管理IP地址和子网掩码 Switch(config-if)#no shutdown 启用接口 Switch(config-if)#exit 退出到上一层全局配置模式 Switch(config)#ip default-gateway 192.168.1.1 配置交换机默认网关IP地址 Switch(config)#end 完全退出配置模式,并且进入特权exec模式。 Switch#write 保存当前运行配置 Switch#configure terminal 从特权exec模式切换到全局配置模式 Switch(config)#username cisco password cisco 创建远程登录的用户名和密码 Switch(config)#line vty 0 4 指定vty线路,并且进入线路配置模式 Switch(config-line)#password 123 设置线路密码 Switch(config-line)#login local 启用Telnet时使用本地用户和密码功能 Switch(config-line)#transport input telnet 开启Telnet服务 Switch(config-line)#exit 退出到上一层全局配置模式 Switch(config)#enable password 123 设置进入特权exec模式的明文密码 Switch(config)#service password-encryption 设置密码加密 Switch(config)#end 完全退出配置模式,并且进入特权exec模式。 Switch#write 保存当前运行配置 验证: PC--桌面--命令提示符: PC>telnet 192.168.1.2 User Access Verification Username: cisco Password: cisco Switch>enable Password: 123 Switch#

这里用到的知识点是:

ip default-gateway 网关IP

cisco 二层交换机上,使用ip default-gateway命令去配置默认网关。二层交换机配置了vlan 1的管理地址和ip default-gateway就是将二层交换机看作一台主机,如果仅设置了vlan 1的管理地址,但是没有设置默认网关的地址,是无法用vty进行远程管理连接的。交换机管理vlan的地址必须与ip default-gateway指定的默认网关的地址在同一个网段。

鼓励话语:成功的三要素是:有野心、有能力、有耐心!