跳转至

10 路由器基本配置

说明

本文档仅涉及部分内容,仅可用于复习重点知识

10.1 配置初始路由器设置

10.1.1 基本路由器配置步骤

  1. 配置设备名称
  2. 保护特权模式
  3. 保护用户模式
  4. 保护远程 Telnet / SSH 访问
  5. 保护配置文件中的所有密码
  6. 提供法律通知
  7. 保存配置
Router(config)# hostname {hostname}
Router(config)# enable secret {password}
Router(config)# line console 0
Router(config-line)# password {password}
Router(config-line)# login
Router(config-line)# line vty 0 4
Router(config-line)# password {password}
Router(config-line)# login
Router(config-line)# transport input {ssh | telnet}
Router(config-line)# exit
Router(config)# service password-encryption
Router(config)# banner motd {delimiter message delimiter}
Router(config)# end
Router# copy running-config startup-config

10.1.2 路由器基本配置示例

Router> enable 
Router# configure terminal 
Enter configuration commands, one per line.
End with CNTL/Z.
Router(config)# hostname R1 
R1(config)#
R1(config)# enable secret class 
R1(config)#
R1(config)# line console 0 
R1(config-line)# password cisco 
R1(config-line)# login 
R1(config-line)# exit 
R1(config)#
R1(config)# line vty 0 4 
R1(config-line)# password cisco 
R1(config-line)# login 
R1(config-line)# transport input ssh telnet 
R1(config-line)# exit 
R1(config)#
R1(config)# service password-encryption
R1(config)#
R1(config)# banner motd #
Enter TEXT message. End with a new line and the #
*********************************************** 
WARNING: Unauthorized access is prohibited!
***********************************************
#
R1(config)#
R1# copy running-config startup-config
Destination filename [startup-config]? 
Building configuration...
[OK]
R1#

10.2 配置接口

10.2.1 配置路由器接口

这是因为在配置接口之前,终端设备无法访问路由器。思科路由器上有许多不同类型的接口。例如,思科 ISR 4321 路由器配备了两个千兆以太网接口:

  1. GigabitEthernet 0/0/0 (G0/0/0)
  2. GigabitEthernet 0/0/1 (G0/0/1)

配置路由器接口的任务与交换机上管理 SVI 非常相似。具体来说,它包括发出以下命令:

1
2
3
4
5
Router(config)# interface {type-and-number}
Router(config-if)# description {description-text}
Router(config-if)# ip address {ipv4-address subnet-mask}
Router(config-if)# ipv6 address {ipv6-address/prefix-length}
Router(config-if)# no shutdown

10.2.2 配置路由器接口示例

R1> enable
R1# configure terminal
Enter configuration commands, one per line.
End with CNTL/Z.
R1(config)# interface gigabitEthernet 0/0/0
R1(config-if)# description Link to LAN
R1(config-if)# ip address 192.168.10.1 255.255.255.0
R1(config-if)# ipv6 address 2001:db8:acad:10::1/64
R1(config-if)# no shutdown
R1(config-if)# exit
R1(config)#
*Aug  1 01:43:53.435: %LINK-3-UPDOWN: Interface GigabitEthernet0/0/0, changed state to down
*Aug  1 01:43:56.447: %LINK-3-UPDOWN: Interface GigabitEthernet0/0/0, changed state to up
*Aug  1 01:43:57.447: %LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/0/0, changed state to up
R1(config)#
R1(config)#
R1(config)# interface gigabitEthernet 0/0/1
R1(config-if)# description Link to R2
R1(config-if)# ip address 209.165.200.225 255.255.255.252
R1(config-if)# ipv6 address 2001:db8:feed:224::1/64
R1(config-if)# no shutdown
R1(config-if)# exit
R1(config)#
*Aug  1 01:46:29.170: %LINK-3-UPDOWN: Interface GigabitEthernet0/0/1, changed state to down
*Aug  1 01:46:32.171: %LINK-3-UPDOWN: Interface GigabitEthernet0/0/1, changed state to up
*Aug  1 01:46:33.171: %LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/0/1, changed state to up
R1(config)#

10.2.3 检验接口配置

有多条命令可用于检验接口配置。其中最有用的是 show ip interface briefshow ipv6 interface brief 命令

10.3 配置默认网关

10.3.1 主机的默认网关

如果您的本地网络只有一个路由器,它就将是网关路由器,并且必须使用此信息配置网络上的所有主机和交换机。如果您的本地网络有多个路由器,则必须选择其中一个作为默认网关路由器

10.3.2 交换机的默认网关

连接客户端计算机的交换机通常是第 2 层设备。因此,第 2 层交换机不需要使用 IP 地址就能正常工作。但是,可以在交换机上配置 IP 配置,以便管理员能够远程访问交换机

要通过本地 IP 网络连接和管理交换机,必须配置交换机虚拟接口 (SVI)。SVI 配置了本地局域网上的 IPv4 地址和子网掩码。要从远端网络管理交换机,必须给交换机配置一个默认网关

要为交换机配置默认网关,请使用 ip default-gateway {ip-address} 全局配置命令。配置的 IP 地址是连接到交换机的本地路由器接口的 IP 地址

评论区

欢迎在评论区指出文档错误,为文档提供宝贵意见,或写下你的疑问