萬盛學電腦網

 萬盛學電腦網 >> 路由器知識 >> 路由器簡介 >> 路由器和交換機命令大全

路由器和交換機命令大全

  不論是路由器也好,還是交換機也好,終歸都是要依靠命令進行設備控制,因此你是否知道全部的命令呢?何不抓緊時間補全自己所缺失的命令,以便更好的進行工作開展。

  「基礎配置」

  進入console口進行本地配置用戶模式 xx>enable n特權模式 xx#configure terminal全局配置模式 xx(config)#interface [f|s] n/m進入接口配置模式xx(config-if)#

  進入(子)接口模式後配置IP(config-if)#ip addr A.B.C.D 子網掩碼激活接口(config-if)#no shutdown配置速度(config-if)#speed {auto|10|100}配置接口工作模式(config-if)#duplex {auto|half|full}配置時鐘(串行口DCE端)

  (config-if)#clock rate n反向操作(刪除配置)

  no + 命令在換回接口上配多個ip(config-if)#ip addr A.B.C.D 子網掩碼(config-if)#ip addr A.B.C.D 子網掩碼 secondary查看所有配置#show running-config

  路由器關閉路由功能充當主機(config)#no ip routing為路由器設置網關(config)#ip default-gateway ip地址

  改機器名字(config)#hostname yy控制線路超時(config)#line n(config-line)#exec-timeout 0 0關閉域名解析功能(config)#no ip domain-lookup開啟路由器http功能(config)#ip http server(config)#username xxx password yyy(config)#username xxx secret yyy(config)#enable secret yyy啟用密碼加密服務(config)#service password-encryption yyy開啟路由器https功能(config)#ip http secure-server開啟路由器遠程登錄功能(config)#line vty 0 4(config)#login local或者(config)#no login(config)#enable n登錄時使用命令 telnet A.B.C.D

  「交換機」

  查看mac地址表#show mac-address-table綁定靜態mac地址(config)#mac-address-table static H.H.H vlan n interface fx/x #show arp在主機上使用arp -a查看arp信息開啟交換機端口安全(防止連接主機惡意發送隨機mac填滿mac地址表)

  (conifg)#switchport port-security(conifg)#switchport ?

  #show port-security int fx/x恢復(config)#errdisable recovery

  為交換機vlan1配置管理ip(conifg)#int vlan 1(config-if)#ip addr A.B.C.D 子網掩碼(config-if)#no shut

  「交換機vlan」

  查看vlan #show vlan-switch或是#show vlan創建vlan #vlan database(vlan)#vlan n將端口加入到vlan中(config-if)#switchport access vlan n給允許多個vlan的接口打trunk(config-if)#switchport mode trunk

  「單臂路由vlan」

  路由器上配置子接口實現不同vlan之間通信,先必須激活其父接口,另外IP不允許重復(config)#interface fx/x.x(config-subif)#encapsulation dot1q vlan-id(config-subif)#ip addr A.C.D.E 子網掩碼(config-subif)#no shut

  「使用三層交換機交換虛擬接口」

  交換機上配置虛擬交換接口實現不同vlan之間通信,先必須在交換機上添加對應vlan(config)#int vlan n(config-if)#ip addr A.B.C.D 子網掩碼(config-if)#no shut在刪除時,務必先刪除交換虛擬接口,再刪對應vlan

  「VTP」

  配置VTP模式#vlan database(vlan)#vtp {server|client|transparent}只有域名和密碼完全一樣的路由器之間才能同步vlan信息(vlan)#vtp domain <域名>(vlan)#vtp password <密碼>打開VTP裁剪(vlan)#vtp pruning退出激活(vlan)#exit

  「端口聚合」

  創建R1(config)#interface port-channel 1(config-if)#switchport trunk encapsulation dot1q(config-if)#switchport mode trunk將指定接口加入聚合組內#int range f x/x-x #channel-group 1 mode on查看聚合接口#show etherchannel summary

  「生成樹協議」

  基於vlan的生成樹可防止環路開啟生成樹協議(STP默認是開啟的,可省略)

  (config)#spanning-tree vlan n修改生成樹協議優先級(根網橋:mac最小、優先級最小)

  (config)#spanning-tree vlan n priority m交換機和主機之間連接的端口開啟portfast,可防止主機發送BPDU偽造數據(config-if)#spanning-tree portfast查看生成樹#show spanning-tree [vlan n]

  「靜態路由」

  查看協議#show ip protocols查看路由表#show ip route添加靜態路由(以默認路由舉例)

  (config)#ip route 0.0.0.0 0.0.0.0 {出接口|下一跳ip}浮動靜態路由(備份鏈路,在原鏈路失效後起作用)

  (config)#ip route 0.0.0.0 0.0.0.0 出接口 AD管理距離靜態黑洞路由(config)#ip route 192.168.0.0 255.255.0.0 null 0

  「RIP距離矢量路由,動態路由」

  配置RIP宣告直連網段(config)#router rip(config-router)#network 網段更改為版本2(config-router)#version {2|1}關閉自動匯總(如果被其他網路隔開時,最好關閉自動匯總)

  (config-router)#no auto-summary設置被動接口(只接受更新,不宣告自己)

  (config-router)#passive-interface 接口單播更新(只和指定的ip交換路由信息)

  (config-router)#neighbor ip地址清除路由表內容#clear ip route *

  「OSPF鏈路狀態路由,動態路由」

  配置OSPF宣告直連網路(config)#router ospf <進程號>(config-router)#router-id <任意ip地址>(config-router)#network <反掩碼> area n重啟OSPF進程#clear ip ospf process查看接口的OSPF信息#show ip ospf interface查看鄰居表#show ip ospf neighbor查看鏈路數據表#show ip ospf database

  「EIGRP鏈路狀態路由,動態路由」

  配置EIGRP宣告直連網路(config)#router eigrp <系統編號>(config-router)#network 查看鄰居表#show ip eigrp neighbors查看拓撲表#show ip eigrp topology

  「VRRP虛擬路由器路由協議」

  提供網關冗余查看VRRP信息#show vrrp VRRP配置(在提供備份的兩台路由器上做以下配置)

  端口跟蹤(監視某個接口的狀態)

  (config)#track 1 interface 接口 line-protocol(config-if)#vrrp <1~254> ip 額外配置優先級(IP和優先級越大Master)和搶占(config-if)#vrrp <1~254> priority <1~254>(config-if)#vrrp <1~254> preempt(config-if)#vrrp 1 track 1 decrement <1~255>

  「訪問控制列表ACL」

  ACL無法控制自身發起的流量,對於已經建立的流量不起作用標准ACL(不能單獨刪除、添加一條訪問列表)

  (config)#access-list <1~99|1300~1999> {permit|deny} ip地址 反掩碼擴展ACL(config)#access-list <100-199> {permit|deny} <協議> <源ip> <反掩碼> <源端口> <目標ip> <反掩碼> <目標端口>應用到指定ACL到某個接口(config)#int 接口(config-if)#ip access-group <1~99|100-199|1300~1999> {in|out}

  命名ACL(config)#ip access-list standard <標准ACL名字>(config-std-nacl)#{permit|deny} ip地址 反掩碼(config)#ip access-list extended <擴展ACL名字>(config-ext-nacl)#{permit|deny} <協議> <源ip> <反掩碼> <源端口> <目標ip> <反掩碼> <目標端口>應用到指定ACL到某個接口(config)#int 接口(config-if)#ip access-group <標准ACL名字|擴展ACL名字> {in|out}

  自反ACL(RACL,可以只允許內網主動發起的流量通過)

  (config)#ip access-list extended OUTB(config-ext-nacl)#permit tcp any any reflect RACL(config)#ip access-list extended INB(config-ext-nacl)#evaluate RACL(config-ext-nacl)#deny ip any any應用到指定ACL到某個接口(config-if)#ip access-group OUTB out(config-if)#ip access-group INB in

  基於時間的ACL設置時區時間(config)#clock timezone GMT +8 #clock set hh:mm:ss <日> <月> <年>定義時間(config)#time-range <時間名>(config-time-range)#periodic hh:mm to hh:mm(config-time-range)#absolute start hh:mm:ss <日> <月> <年> end hh:mm:ss <日> <月> <年>結合ACL(config)#ip access-list extended <擴展ACL名字>(config-ext-nacl)#deny tcp any any time-range <時間名>

  「NAT和PAT」

  定義內外網接口(config)#int 接口(config-if)#ip nat {inside|outside}靜態NAT(config)#ip nat inside source static ip地址 靜態PAT(config)#ip nat inside source static <協議> ip地址 <端口號>

  使用ACL捕獲流量(config)#access-list n permit ip地址 反掩碼(config)#ip nat pool <地址池名> <起始ip地址> <終止ip地址> netmask 掩碼TCP負載均衡(輪詢轉換)

  (config)#ip nat pool <地址池名> <起始ip地址> <終止ip地址> netmask 掩碼 type rotary動態NAT(config)#ip nat insi

copyright © 萬盛學電腦網 all rights reserved