路由器的基本配置
Router(config)#hostname R01
(配置进入特权模式的密码)R01 (config)#enable secret Bs0023
(三层交换机开启路由功能)SW1(config-if)#no sw
配置远程登陆
(配置五个登录)R01 (config)#line vty 0 4
(登录密码)R01(config-if)#password Ruijie123
(启动远程登录功能)R01(config-if)login
配置vlan
(进入全局模式)SW1#configure terminal
(配置交换机名称)Switch(config)#hostname SW1
(创建vlan)SW1(config)#vlan 2
(将vlan取名字)SW1(config-vlan)#name xiaowugui
(进入接口)SW1(config)#int fastEthernet 0/1(同时配置多个接口)SW1(config)#interface range fastEthernet 0/1-10
(配置接口为access模式)SW1(config-if)#switchport mode access
(将接口划入vlan2)SW1(config-if)#switchport access vlan 2
(进入vlan接口)SW1(config)#interface vlan 200
(为vlan配置IP地址)SW1(config-if-vlan 200) # ip address 192.168.200.1 255.255.255.0
(开启vlan接口)SW1(config-if-vlan 200) #no shutdown
单臂路由
Router(config)#interface f0/0
Router(config-if)#no ip address
Router(config-if)#no shutdown
Router(config)#interface f0/0.1
Router(config-subif)#encapsulation dot1q 10
Router(config-subif)#ip address 10.0.0.1 255.255.255.0
Router(config)#interface f0/0.2
Router(config-subif)#encapsulation dot1q 20
Router(config-subif)#ip address 20.0.0.1 255.255.255.0
Switch(config)#interface f0/0
Switch(config)#switchport mode trunk
配置trunk
SW1(config)#interface fastEthernet 0/15
(在接口上配置trunk)SW1(config-if)#switchport mode trunk
(将vlan2从该接口trunk中移除)SW1(config-if)#switchport trunk allowed vlan remove 2
PVST
配置SW1为根网桥
SW1(config)# spanning-tree vlan 10(进入 VLAN 10 的生成树配置模式) root primary(设置当前交换机为 VLAN 10 的主要根桥)
SW1(config)# spanning-tree vlan 20 root primary
SW1(config)# spanning-tree vlan 30 root primary
链路聚合配置(链路的两边的接口都要配置)
(配置1-2接口)SW2(config)#interface range GE0/1-2
(指定接口通道协议为lacp)SW2(config-if-range)channel-protocol lacp
(接口范围为通道组 1,并设置模式为 "on")SW2(config-if-range)# channel-group 1 mode on
路由器接口配置
RB (config)# interface S0/0
没要求可以不配(配置时钟频率)RB(config-if) # clock rate 128000
(配置带宽)RB(config-if) # bandwidth 128
(配置端口IP地址)RB(config-if) # 15.255.255.0
(开启路由器的端口)RB(config-if) # no shutdown
HSRP热备份
R0(config)#interface fastEthernet 0/0
R0(config-if)#standby 10 ip 10.1.1.254(虚拟ip)
R0(config-if)#standby 10(组号) priority 110
R0(config)#interface fastEthernet 0/1
R0(config-if)#standby 172 ip 172.16.1.254
R0(config-if)#standby 172 priority 120
静态路由
(默认静态路由)R01 (config)#ip route 0.0.0.0 0.0.0.0 61.138.16.31(下一跳的ip地址)
(静态路由) R01 (config)#ip route 192.168.1.0 255.255.255.0 61.138.16.31(下一跳地址)
DHCP服务配置
其语法格式为:
(开启DHCP服务)RB (config)# service dhcp (可以省略)
(创建地址池)RB (config)# ip dhcp pool XZL(地址池名字)
(ip地址范围)RB (dhcp-config)# )# network 192.168.100.0 255.255.255.0
(配置网关地址,为与交换机连接的路由器接口地址)RB (dhcp-config)# )# default-router 192.168.100.1
(配置DNS服务器地址)RB (dhcp-config)# )# dns-server 114.114.114.114
(排除地址池中100.1到 100.5个地址)RB (config)# ip dhcp excluded-address 192.168.100.1 192.168.100.5
(排除地址池中的一个地址)RB (config)# ip dhcp excluded-address 192.168.100.100
(将 DHCP 请求中继到 IP 地址为 192.168.3.1 的 DHCP 服务器RB)RA(config)#ip helper-address 192.168.3.1
(将 DHCP 请求中继到 IP 地址为 192.168.4.1 的 DHCP 服务器RB)RC (config)# ip helper-address 192.168.4.1
通过使用 DHCP 中继器,可以在整个网络中集中管理 DHCP 配置。这样,只需在 DHCP 中继器上配置相关信息,而无需在每个子网上单独配置 DHCP 服务器。
RIP路由协议配置
(开启RIP协议)RA (config)# router rip
(选择rip协议版本)RA (config-router)#version 2
(宣告直连网段)RA (config-router)#network 192.168.3.0
RA (config-router)#network 192.168.10.0
RA (config-router)#network 192.168.100.0
OSPF路由协议配置
交换机(Switch(config)#ip routing)
(开启ospf协议标识号为1,一个ospf网络标识号相同)RC (config)# router ospf 1
(宣告直连网段和网段所在区域号)RC (config-router)#network 10.12.1.0 0.0.0.255(反向掩码) area 0
RC (config-router)#network 172.16.0.0 0.0.255.255 area 0
RC (config-router)#network 192.168.4.0 0.0.0.255 area 0
路由重分发
R1(config)# router ospf 1
R1(config-router)# redistribute rip(可变) metric 64(可变)subnets
R2(config)# router rip
R2(config-router)#redistribute ospf 1 metric 2(可变) subnets
ACL配置
(创建acl列表)RC (config)#access-list 100(列表名) deny(限制) ip 172.16.0.0 0.0.255.255(反向掩码) host 192.168.100.100目标主机
(创建允许其他所有的策略)RC (config)#access-list 100 permit ip any any
(进入接口)RC (config)#interface f0/1
(将acl列表作用到该接口的入方向)RC (config-if)#ip access-group 100 in
扩展ACL
ip access-list extended cisco(acl名字)
(单个地址到网段)deny ip host 10.0.0.1 192.168.0.0 0.0.0.255
NAPT地址转换配置
这些配置将允许来自172.16.10.0/24、172.16.20.0/24、172.16.30.0/24和192.168.200.0/24的内部网络流量通过NAT转换并使用61.138.16.28作为转换后的公网IP地址。
R01(config)# interface Se0/0/0
R01(config-if)#ip address 61.138.16.28 255.255.255.0
R01(config-if)#no shutdown
(定义出接口)R01(config-if)# ip nat outside
R01(config)# interface Ge0/1/1
(定义入接口)R01(config-if)# ip nat inside
R01(config)# access-list 1permit 172.16.10.0 0.0.0.255
R01(config)# access-list 1permit 172.16.20.0 0.0.0.255
R01(config)# access-list 1permit 172.16.30.0 0.0.0.255
R01(config)# access-list 1permit 192.168.200.0 0.0.0.255
R01(config) # ip nat pool one(地址池名字) 61.138.16.28(起始地址) 61.138.16.28(结束地址) netmask 255.255.255.0 type rotary(可选)地址池中的地址为循环使用
R01(config)# ip nat inside source list 1(access-list-number) pool one(地址池名字) overload(并支持Overload(端口地址转换)功能)