路由器、交换机常用命令


交换机支持的命令:(注:交换机支持命令对应的为思科2系列交换机。)

交换机基本状态:

switch: ;交换机的ROM态

rommon> ;路由器的R状态

switch > ;用户模式

switch# ;特权模式

switch(config)# ;全局配置模式

switch(vlan)# 交换机VLAN配置模式

switch(config-if)# ;端口配置模式

switch(config-line)# ; 指定连接状态(console连接 telnet连接)

交换机显示命令:

switch#write ;保存配置信息

switch#show running ;查看当前配置信息

switch#show startup 查看交换机NVROM配置信息

switch#show vlan ;查看vlan配置信息

switch#show vlan-switch 同样为查看vlan配置信息(一些高端

交换机比如3系列的交换机必须用这个命令才能查看vlan配置信息)

switch#show vtp status 查看VTP配置信息

switch#show interface ;查看所有的端口信息

switch#show interface f0/3 ;查看指定的f0/3快速以太网端口信息

switch#show interfacef0/3 switchport 查看指定的f0/3快速以太网端口trunk信息
switch #show spanning-tree 查看交换机生成树协议情况

switch #show spanning-tree vlan 2 查看交换机VLAN2的生成树协议情况

switch #show spanning-tree interface f0/1 查看交换机F0/1端口生成树协议情况

switch #show cdp 显示交换机当前邻居更新信息

switch #show cdp neighbor ;显示邻居直连路由信息

switch #show cdp neighbor detail 显示邻居直连路由详细信息

switch #show cdp interface 显示所有端口是否开启cdp功能

switch (config-if)#no cdp enable 关闭指定端口的cdp功能

switch (config-if)#cdp enable 打开指定端口的cdp功能

switch (config)#no cdp run 关闭所有端口的cdp功能

switch (config)#cdp run 打开所有端口的cdp功能

switch#show version 查看交换机版本信息

switch#show flash 查看flash里面的IOS信息

switch#show mac-address-table 查看交换机所有端口的MAC
地址信息

交换机口令设置:

switch>enable ;进入特权模式

switch#config terminal ;进入全局配置模式

switch(config)#hostname

switch(config)#enable secret xxx ;设置特权加密口令(真正进入enable特权模式需要输入这个口令)

switch(config)#enable password xxa ;设置特权非密口令

switch(config)#line console 0 ;进入控制台口

switch(config-line)#login ;允许登录

switch (config-line)# password xx 设置登陆控制台口口令

switch (config-line)#exec-timeout 0 0 设置控制台口多长时间不操作会自动退出,前面一个0表示分钟 后面一个0表示秒 两个都是0表示一直不会自动退出。

switch(config-line)#logging sy

switch(config-line)#no ip domain-lookup 关闭域名查找功能(如果你输错了命令,switch会认为你输入的是域名,就会查找。。。浪费时间。no ip domain-lookup就是取消这种查找)

switch(config-line)#line vty 0 4 ;进入虚拟终端

switch(config-line)#login ;允许登录

switch(config-line)#password xx ;设置登录虚拟终端口令xx

switch#exit ;返回命令

交换机常规配置

switch(config)#no mac-address-table static (需要删掉的mac地址) fastethernet f0/7 清除掉交换机F0/7端口的MAC地址

switch(config-if)#duplex full/halt/auto ;设置交换机端口工作方式
(full全双工 halt半双工模式 auto自动检测)

switch(config-if)#speed 10/100/1000/auto ;设置交换机对应端口局域网交换速度

switch(config)#interface f0/1 进入快速以太网端口端口f0/1

switch(config)#interface vlan 1 ;进入vlan 1

switch(config)#interface range f0/1 – 24 进入快速以太网端口f0/1到f0/24

交换机文件操作:

switch#copy running-config startup-config 将RAM的当前配置存储到NVRAM

switch#copy running-config tftp 备份RAM存储的配置信息到tftp

switch#copy startup-config tftp 备份NVRAM配置备份到tftp

switch#copy flash tftp ;备份路由器的flash文件IOS到tftp

switch#copy tftp startup-config ;恢复NVRAM配置文件

switch#copy tftp running-config 恢复NVRAM配置文件

switch#copy tftp flash: 将flash文件IOS从tftp恢复到路由器

switch#erase startup-config 清除NVRAM存储的配置文件

交换机生成树协议配置

switch(config)#spanning-tree 开启交换机生成树协议

switch(config)#no spanning-tree 关闭交换机生成树协议

switch(config-if)#spanning-tree port-priority 32 设定这个端口的优先级为32(端口优先级取值范围为0~240 之间的16 倍数,即取值范围为 0、16、32、48…240.设定数值越小,优先级越高)

switch(config)#spanning-tree priority 4096 设定这个交换机STP优先级为4096(取值范围为0~61440 之间的4096 的倍数,即取值范围为0、4096、8192…61440. 设定数值越小,优先级越高)

交换机端口镜像配置

Switch (config)# monitor session 1 destination interface f0/1 配置f0/1为镜像端口。

Switch (config)# monitor session 1 source interface f0/2 both 配置f0/2为被镜像端口,且出入双向数据均被镜像。

Switch (config)# monitor session 1 source interface f0/2-f0/10 both 配置f0/1到f0/10为被镜像端口,且出入双向数据均被镜像。

Switch (config)# monitor session 1 source vlan2 both 配置整个vlan2为被镜像端口,且出入双向数据均被镜像。

Switch (config)# no monitor session 1 去掉镜像1。

交换机VLAN设置:

switch#vlan database ;进入VLAN设置

switch(vlan)#vlan 2 ;建VLAN 2

switch(vlan)#vlan 2 name

switch(vlan)#no vlan 2 ;删vlan 2

switch(vlan)#vtp domain

switch(vlan)#vtp password

switch(vlan)#vtp server ;设置发vtp服务模式

switch(vlan)#vtp client ;设置发vtp客户模式

switch(vlan)#vtp pruning ;设置vtp 允许

switch(config)#ip routing 启动三层交换机路由转发

switch(config-if)#switchport access vlan 2 ;当前端口加入vlan 2

switch(config-if)#switchport mode trunk ;设置为干线(开启trunk干线功能)

switch(config-if)#switchport trunk encap dot1q ;设置vlan 中继(开启vlan封装的802.1q协议)

switch(config-if)#switchport trunk allowed vlan all ;设置允许的vlan(这个命令为允许所有的vlan从这个干线进行传递)

switch(config-if)#switchport trunk allowed vlan 2 3 设置允许的vlan(这个命令为允许vlan 2和 vlan 3从这个干线进行传递)

交换机设置IP地址:

switch(config-if)#ip address

switch(config)#ip default-gateway

switch#dir flash: ;查看闪存

3750#show arp 查看IP与MAC对应
Address Age (min) Hardware Addr Type Interface

10.0.0.2 31 0090.0b09.622e arpa Gi1/1

192.168.100.3 0 00e0.6109.5e90 arpa VL10

192.168.100.49 15 0019.21bd.b6cd arpa VL10

192.168.100.50 0 00e0.b0ef.97d8 arpa VL10

192.168.100.51 1 0019.21cf.dcdb arpa VL10

看MAC地址从哪个端口学习上来

3750#show mac-address-table

Vlan MAC Address Type Interface

1 001e.ecbf.8744 DYNAMIC Gi1/22

1 00d0.f87b.f7a5 DYNAMIC Gi1/23

1 00d0.f88b.a04d DYNAMIC Gi1/24

交换机名(config)# interface fastethernet 0/1 /*进入接口0/1的配置模式

交换机名(config-if)# speed 10 /*设置该端口的速率为10Mb/s

交换机名(config-if)# duplex full /*设置该端口为全双工

交换机名(config-if)# end /*退回到特权模式

交换机名# show interface fastethernet 0/1 /*查询端口0/1的配置结果

1、duplex auto; 自适应双工模式

2、duplex full; 全双工模式

3、duplex half; 半双工模式

路由器支持的命令:

建立本地数据库用户名CNTC 密码123

router(config)#username CNTC password 123

进入控制台接口,配置路由器以本地数据库的方式进行认证

router(config)#line console 0

router(config-line)#login local

router(config-line)#

进入VTY接口,设置远程登录时用本地数据库认证

router(config)#line vty 0 4

router(config-line)#login local

router(config-line)#

router#Clear line vty 0 永久性清除telent登录

查看路由器当前配置show running-config

可以通过“default”命令修改快速还原以前的封装协议

向192.168.1.1发送150个大小为200字节的数据包

router(config)#line console 0

router(config-line)#exec-timeout 0 0 设置路由器console永不超时

router(config-line)#logging synchronous 阻止控制台口信息妨碍CLI操作
(console口信息同步)

No ip domain-lookup 关闭域名解析功能

no auto-summary关闭自动汇总

路由器基本状态:

router: ;路由器的ROM态

rommon> ;路由器的R状态

router> ;用户模式

router# ;特权模式

router(config)# ;全局配置模式

router(config-if)# ;端口配置模式

router(config-line)# ; 指定连接状态(console连接 telnet连接)
router(config-router)# 路由状态配置模式(动态路由配置模式)

router(dhcp-config)# 路由器DHCP配置模式

路由器显示命令:

router#show running ;显示配置信息

router#show startup 查看交换机NVROM启动配置信息

router#show interface ;显示接口信息

router#show ip int brief 显示接口ip地址

router#show interface f0/0 ;查看指定端口信息

router#show ip route ;显示路由表信息

router #show cdp 显示路由器当前邻居更新信息

router#show cdp neighbor ;显示邻居直连路由信息

router#show cdp neighbor detail 显示邻居直连路由详细信息

router#show cdp interface 显示所有端口是否开启cdp功能

router#show access-lists

router (config-if)#no cdp enable 关闭指定端口的cdp功能

router (config-if)#cdp enable 打开指定端口的cdp功能

router(config)#no cdp run 关闭所有端口的cdp功能

router(config)#cdp run 打开所有端口的cdp功能

router(config)#no ip domain lookup 关掉域名解析

router#reload     ;重新起动

router#show version 查看路由器版本信息

router#show flash 查看flash里面的IOS信息

路由器口令设置:

router>enable ;进入特权模式

router#config terminal ;进入全局配置模式

router(config)#hostname

router(config)#enable secret xxx ;设置特权加密口令(真正进入enable特权模式需要输入这个口令)

router(config)#enable password xxx ;设置特权非密口令

router(config)#line console 0 ;进入控制台口

router(config-line)#login ;要求口令验证

router(config-line)# password xx 设置登陆控制台口口令

router(config-line)#exec-timeout 0 0 设置控制台口多长时间不操

作会自动退出,前面一个0表示分钟 后面一个0表示秒 两个都是0表示一直不会自动退出。

router(config-line)#logging sy

router(config-line)#no ip domain-lookup 关闭域名查找功能(如果你输错了

命令,router会认为你输入的是域名,就会查找。。。浪费时间。no ip domain-lookup就是取消

这种查找)

router(config-line)#line vty 0 4 ;进入虚拟终端

router(config-line)#login ;要求口令验证

router(config-line)#password xx 设置登录虚拟终端口令xx

router(config)#(Ctrl+z) ; 返回特权模式

router#exit ;返回命令

路由器常规配置:

router#clock set 18:10:53 20 march 2010 设定路由器时钟,例子设定

的为2010年3月20日18点10分53秒

router(config)#interface s0/0 ;进入Serail接口(串口)

router(config)#interface f0/0 进入快速以太网接口f0/0

router(config-if)#no shutdown ;激活当前接口

router(config-if)#bandwidth 64 ;设定指定串口带宽

router(config-if)#clock rate 64000 ;设置同步时钟

router(config-if)#ip address

router(config-if)#ip address

router(config-if)#interface f0/0.1 ;进入子接口

router(config-subif.1)#ip address

router(config-subif.1)#encapsulation dot1q

router(config)#config-register 0x2142 ;跳过配置文件

router(config)#config-register 0x2102 ;正常使用配置文件

router#reload ;重新引导

路由器文件操作:

router#copy running-config startup-config 将RAM的当前配置存储到NVRAM

router#copy running-config tftp 备份RAM存储的配置信息到tftp

router#copy startup-config tftp 备份NVRAM配置备份到tftp

router#copy flash tftp ;备份路由器的flash文件IOS到tftp

router#copy tftp startup-config ;恢复NVRAM配置文件

router#copy tftp running-config 恢复NVRAM配置文件

router#copy tftp flash: 将flash文件IOS从tftp恢复到路由器

router#erase startup-config 清除NVRAM存储的配置文件

ROM状态:

如果需要将路由器恢复到出厂设置要求在先启动计算机的超级终端,还原为9600波特率,在路由

器上电60秒内按计算机的 Ctrl+Break 键,你将会看到rommon>

Ctrl+Break ;进入ROM监控态

rommon>confreg 0x2142 ;跳过配置文件

rommon>confreg 0x2102 ;恢复配置文件

rommon>reset ;重新引导

rommon>copy xmodem:

rommon>IP_ADDRESS=10.65.1.2 ;设置路由器IP

rommon>IP_SUBNET_MASK=255.255.0.0 ;设置路由器码

rommon>TFTP_SERVER=10.65.1.1 指定TFTP服务器IP

rommon>TFTP_FILE=c2600.bin 指定下载的文件

rommon>tftpdnld ;从tftp下载

rommon>dir flash: ;查看闪存内容

rommon>boot ;引导IOS

静态路由:

ip route

router(config)#ip route 192.168.1.0 255.255.255.0 192.168.3.2 ;静态路由举

默认缺省路由

router(config)#ip route 0.0.0.0 0.0.0.0 192.168.10.5 ;默认缺省路由举例

动态路由:(特指RIPV2动态路由协议)

router(config)#ip routing ;启动路由转发

router(config)#router rip ;启动RIP动态路由协议。

router(config-router) #version 2 设置启用RIP动态路由协议

为RIPV2版本

router(config-router)#network

router(config-router)#neighbor

动态路由:(特指EIGRP动态路由协议)

router(config)#router eigrp

router(config-router)#network

router#show ip eigrp neighbor 显示EIGRP协议的邻居信息

router#show ip eigrp topology 显示EIGRP协议的拓扑表信息

router#show ip route eigrp 显示EIGRP协议的路由表信息

帧中继命令:

router(config)#frame-relay switching ;使能帧中继交换

router(config-s0)#encapsulation frame-relay ;使能封装帧中继

router(config-s0)#frame-relay lmi-type cisco ;设置lmi本地接口管理类型(11.2以上的IOS不用配置会自动分配一个lmi类型)

router(config-s0)#frame-relay intf-type DCE ;设置为DCE

router(config-s0)#frame-relay dlci 16 ;

router(config-s0)#frame-relay local-dlci 130 ;设置本地虚电路号

router(config-s0)#frame-relay interface-dlci 120 ;设置本地虚电路号

router(config-s0)#frame-relay map 10.35.35.1 110 broadcast 手动指派

本地虚电路号

router(config-if)#frame-relay inverse-arp 打开帧中继inverse arp(反向ARP

的DLCI学习IP地址)

router(config-if)#no frame-relay inverse-arp 关闭帧中继inverse arp(反向ARP

的DLCI学习IP地址)

router#debug frame-relay inverse-arp 打开帧中继inverse arp(反向ARP的

DLCI学习IP地址)的调试开关

router(config)#log-adjacency-changes ;记录邻接变化

router(config)#int s0/0.1 point-to-point ;设置子接口点对点

router#show frame pvc ;显示永久虚电路

router#show frame-relay map ;显示动态反向ARP的DLCI学习IP地址映射信息

基本访问控制列表:(基本访问控制列表应用列表号为1-99)

router(config)#access-list

router(config)#interface

router(config-if)#ip access-group

控制访问列表中反向子网掩码非常重要,下面说明如何计算反向子网掩码

如何计算反向子网掩码,比如255.255.255.248的反向子网掩码为多少?可以呢么计算255的反

向子网掩码为0 至于248的话可以用255-248=7那么其反向子网掩码为7,所得的

255.255.255.248的反向子网掩码就为0.0.0.7

基本访问控制列表例1:

router(config)#access-list 1 deny host 10.65.1.1

router(config)#access-list 1 permit any

router(config)#int f0/0

router(config-if)#ip access-group 4 in

基本访问控制列表例2:

router(config)#access-list 3 permit 192.168.1.0 0.0.0.255 允许192.168.1.0的网段的电脑通过本路由器

router(config)#access-list 3 deny 192.168.1.0 0.0.0.255 拒绝192.168.1.0的网段的电脑通过本路由器

router(config)#access-list 3 permit 192.168.0.0 0.0.255.255 允许192.168.0.0网段的所有电脑通过本路由器

router(config)#access-list 3 deny 192.168.0.0.0.0.255.255 拒绝192.168.0.0网段的所有电脑通过本路由器

router(config)#access-list 3 permit any 允许所有网段的电脑通过本路由器

router(config)#int f0/1

router(config-if)#ip access-group 4 in

基本访问控制列表例3

router(config)#access-list 3 deny 192.168.1.70 0.0.0.0 拒绝192.168.1.70的电脑通过本路由器(一个IP地址的正向子网掩码为255.255.255.255 所以对应反向子网掩码为0.0.0.0)

扩展访问控制列表:(扩展访问列表应用列表号为100-199)

access-list

扩展访问控制列表例1:

router(config)#access-list 101 deny icmp any 10.64.0.2 0.0.0.0 echo
router(config)#access-list 101 permit ip any any
router(config)#int s0/0
router(config-if)#ip access-group 101 in

扩展访问控制列表例2

router(config)#access-list 102 tcp 192.168.1.0 0.0.0.255 any eq 80 不允许局域网内192.168.1.0这个网段所有的机器访问任何网络的WEB服务
router(config)#access-list 102 permit ip any any允许扩展访问控制列表所有网段的电脑访问

扩展访问控制列表例3:

router(config)#access-list 102 deny tcp 192.168.1.50 0.0.0.0 130.20.110.95 0.0.0.0 eq 80 不允许局域网内192.168.1.50这台电脑访问IP地址为130.20.110.95这台电脑所提供的WEB服务
router(config)#access-list 102 deny tcp 192.168.1.50 0.0.0.0 any eq 80 不允许局域网192.168.1.50这台电脑访问所有网络的WEB服务
router(config)#access-list 102 permit ip any any 允许扩展访问控制列表所有网段的电脑访问
router(config)#interface s0/1
router(config-if)#ip access-group 102 out

命名访问控制列表(IOS为11.2以上的版本可以使用命名访问控制列表)

router(config)#ip access-list standard| extended

删除访问控制例表:

router(config)#no access-list 102
router(config-if)#no ip access-group 101 in

路由器的NAT配置

Router(config-if)#ip nat inside ;当前接口指定为局域网内部接口

Router(config-if)#ip nat outside ;当前接口指定为外部接口

Router(config)#ip nat pool nt 125.130.65.205 125.130.65.210 netmask 255.255.255.248 定义地址池

Router(config)#ip nat inside source list 1 pool nt 将控制访问列表1的局域网地址转换到NT的公网地址池中(采用动态地址转换)

Router(config)#ip nat inside source list 1 pool nt overload 将控制访问列表1的局域网地址转换到NT的公网地址池中(采用端口复用地址转换)

Router(config)#ip nat inside destination list 2 pool p2

Router(config)#ip nat inside source list 2 interface s0/0 overload

Router(config)#ip nat pool p2 10.65.1.2 10.65.1.4 255.255.255.0 type rotary

Router#show ip nat translation

rotary 参数是轮流的意思,地址池中的IP轮流与NAT分配的地址匹配。

overload参数用于PAT 将内部IP映射到一个公网IP不同的端口上。

思科端口映射配置(也叫静态地址转换)

Router(config)#ip nat inside source static [端口类型] <私有IP><公网IP> [port]

思科端口映射配置(也叫静态地址转换)举例

Router(config)#ip nat inside source static 192.168.1.120 125.130.65.205

Router(config)#ip nat inside source static tcp 192.168.1.120 80 125.130.65.205 80

思科路由器DHCP配置

Router(config)#dhcp server 开启路由器的DHCP服务

Router(config)#ip dhcp pool nt 定义DHCP地址池的名字(DHCP服务器地址池名字为nt 你可以采用有意义的字符串来表示)

Router(dhcp-config)#network 192.168.1.0 255.255.255.0 设置地址池可以用于分配的IP地址段

Router(dhcp-config)#default-router 192.168.1.1 设置分配的网关

Router(dhcp-config)#dns-server 202.99.96.68 设置分配的DNS服务器

Router(config)#ip dhcp excluded-address 192.168.1.210 192.168.1.254

设置哪些IP地址是不能用于自动分配的需要排除的IP地址

Router(dhcp-config)#lease 10 设置地址租期为10天

Router(config-if)#ip helper-address 192.168.1.1. 指定DHCP服务器的IP地址

Router(dhcp-config)#domain-name cisco.com

外部网关协议配置

routerA(config)#router bgp 100

routerA(config-router)#network 19.0.0.0

routerA(config-router)#neighbor 8.1.1.2 remote-as 200

配置PPP验证:

RouterA(config)#username

RouterA(config)#int s0

RouterA(config-if)#ppp authentication {chap|pap}

PIX防火墙命令

Pix525(config)#nameif ethernet0 outside security0 ;命名接口和级别

Pix525(config)#interface ethernet0 auto ;设置接口方式

Pix525(config)#interface ethernet1 100full ;设置接口方式

Pix525(config)#interface ethernet1 100full shutdown

Pix525(config)#ip address inside 192.168.0.1 255.255.255.0

Pix525(config)#ip address outside 133.0.0.1 255.255.255.252

Pix525(config)#global (if_name) natid ip-ip ;定义公网IP区间

Pix525(config)#global (outside) 1 7.0.0.1-7.0.0.15 ;例句

Pix525(config)#global (outside) 1 133.0.0.1 ;例句

Pix525(config)#no global (outside) 1 133.0.0.1 ;去掉设置

Pix525(config)#nat (if_name) nat_id local_ip [netmark]

Pix525(config)#nat (inside) 1 0 0

内网所有主机(0代表0.0.0.0)可以访问global 1指定的外网。

Pix525(config)#nat (inside) 1 172.16.5.0 255.255.0.0

内网172.16.5.0/16网段的主机可以访问global 1指定的外网。

Pix525(config)#route if_name 0 0 gateway_ip [metric] ;命令格式

Pix525(config)#route outside 0 0 133.0.0.1 1 ;例句

Pix525(config)#route inside 10.1.0.0 255.255.0.0 10.8.0.1 1 ;例句

Pix525(config)#static (inside, outside) 133.0.0.1 192.168.0.8
表示内部ip地址192.168.0.8,访问外部时被翻译成133.0.0.1全局地址。

Pix525(config)#static (dmz, outside) 133.0.0.1 172.16.0.8
中间区域ip地址172.16.0.8,访问外部时被翻译成133.0.0.1全局地址。

猜你喜欢

转载自www.cnblogs.com/Coeus-P/p/9005093.html