路由器和交換機命令大全

General 更新 2024年06月03日

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

  「基礎配置」

  進入console口進行本地配置使用者模式 xx>enable n特權模式 xx#configure terminal全域性配置模式 xxconfig#interface [f|s] n/m進入介面配置模式xxconfig-if#

  進入子介面模式後配置IPconfig-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 + 命令在換回介面上配多個ipconfig-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 nconfig-line#exec-timeout 0 0關閉域名解析功能config#no ip domain-lookup開啟路由器http功能config#ip http serverconfig#username xxx password yyyconfig#username xxx secret yyyconfig#enable secret yyy啟用密碼加密服務config#service password-encryption yyy開啟路由器https功能config#ip http secure-server開啟路由器遠端登入功能config#line vty 0 4config#login local或者config#no loginconfig#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-securityconifg#switchport ?

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

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

  「交換機vlan」

  檢視vlan #show vlan-switch或是#show vlan建立vlan #vlan databasevlan#vlan n將埠加入到vlan中config-if#switchport access vlan n給允許多個vlan的介面打trunkconfig-if#switchport mode trunk

  「單臂路由vlan」

  路由器上配置子介面實現不同vlan之間通訊,先必須啟用其父介面,另外IP不允許重複config#interface fx/x.xconfig-subif#encapsulation dot1q vlan-idconfig-subif#ip addr A.C.D.E 子網掩碼config-subif#no shut

  「使用三層交換機交換虛擬介面」

  交換機上配置虛擬交換介面實現不同vlan之間通訊,先必須在交換機上新增對應vlanconfig#int vlan nconfig-if#ip addr A.B.C.D 子網掩碼config-if#no shut在刪除時,務必先刪除交換虛擬介面,再刪對應vlan

  「VTP」

  配置VTP模式#vlan databasevlan#vtp {server|client|transparent}只有域名和密碼完全一樣的路由器之間才能同步vlan資訊vlan#vtp domain <域名>vlan#vtp password <密碼>開啟VTP裁剪vlan#vtp pruning退出啟用vlan#exit

  「埠聚合」

  建立R1config#interface port-channel 1config-if#switchport trunk encapsulation dot1qconfig-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 ripconfig-router#network 網段更改為版本2config-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-protocolconfig-if#vrrp <1~254> ip 額外配置優先順序IP和優先順序越大Master和搶佔config-if#vrrp <1~254> priority <1~254>config-if#vrrp <1~254> preemptconfig-if#vrrp 1 track 1 decrement <1~255>

  「訪問控制列表ACL」

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

  config#access-list <1~99|1300~1999> {permit|deny} ip地址 反掩碼擴充套件ACLconfig#access-list <100-199> {permit|deny} <協議> <源ip> <反掩碼> <源埠> <目標ip> <反掩碼> <目標埠>應用到指定ACL到某個介面config#int 介面config-if#ip access-group <1~99|100-199|1300~1999> {in|out}

  命名ACLconfig#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}

  自反ACLRACL,可以只允許內網主動發起的流量通過

  config#ip access-list extended OUTBconfig-ext-nacl#permit tcp any any reflect RACLconfig#ip access-list extended INBconfig-ext-nacl#evaluate RACLconfig-ext-nacl#deny ip any any應用到指定ACL到某個介面config-if#ip access-group OUTB outconfig-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:mmconfig-time-range#absolute start hh:mm:ss <日> <月> <年> end hh:mm:ss <日> <月> <年>結合ACLconfig#ip access-list extended <擴充套件ACL名字>config-ext-nacl#deny tcp any any time-range <時間名>

  「NAT和PAT」

  定義內外網介面config#int 介面config-if#ip nat {inside|outside}靜態NATconfig#ip nat inside source static ip地址 靜態PATconfig#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動態NATconfig#ip nat inside source list n pool <地址池名>動態PATconfig#ip nat inside source list n pool <地址池名> overload

  檢視轉換項#show ip nat translations

  「廣域網PPP協議」

  在序列口上的兩臺路由器都封裝ppp協議config#int sx/xconfig-if#encapsulation pppconfig-if#no shut

  啟用PAP認證,未加密認證方config#username <使用者名稱> password <密碼>config-if#ppp authentication pap請求認證方config-if#ppp pap sent-username <使用者名稱> password <密碼>

  啟用CHAP認證,安全加密認證方config#username <請求認證方名> password <請求認證方密碼>config-if#ppp authentication chap請求認證方config#username <認證方名> password <認證方密碼>config-if#ppp authentication chap

  「幀中繼」

  無廣播的多路訪問網路NBMA

  配置幀中繼交換機關閉路由器路由功能config#no ip routing啟用幀中繼config#frame-relay switching進入序列介面R8config#int sx/x封裝frame-relay協議R8config-if#encapsulation frame-relay指定lmi-type型別config-if#frame-relay lmi-type cisco指定intf-type介面型別為DCEconfig-if#frame-relay intf-type dce配置時鐘頻率config-if#clock rate n配置DLCIconfig-if#frame-relay route <進DLCI號> int <出介面> <出DLCI號>

  配置路由器,封裝frame-relay協議config-if#encapsulation frame-relay靜態指定對映config-if#frame-relay map ip 清除動態學到的Frame Relay #clear frame-relay-inarp檢視對映#show frame-relay map除錯#debug frame-relay lmi

  點到多點解決水平分割問題,劃分子介面

  適用於全互聯和部分互聯config#int sx/xconfig-if#encapsulation frame-relayconfig#int sx/x.x multipoint關閉反向arp,禁止自學習DLCI號和IP對應,而採取靜態Mapconfig-subif#no frame-relay inverse-arp靜態對映DLCI號和IPconfig-subif#frame-relay map ip broadcast如在R1上對R3 DLCI號103 IP地址192.168.1.3

  點到點子介面不存在水平分割問題

  子介面可以看作是專線,適用於星型config#int sx/xconfig-if#encapsulation frame-relayconfig#int sx/x.x point-to-pointconfig-subif#frame-relay interface-dlci

  以上就是帶給大家不一樣的精彩。想要了解更多精彩的朋友可以持續關注,我們將會為你奉上最全最新鮮的內容哦! ,因你而精彩。

路由器連線示意圖
怎樣遠端配置路由器
相關知識
路由器和交換機命令大全
思科交換機路由器常規配置命令大全
路由器和交換機的區別有哪些
區域網內路由器和交換機怎麼設定
路由器與交換機組網圖解
怎麼在宿舍裝路由器轉交換機
如何將路由器當交換機使用
路由器與交換機有區別嗎
路由器與交換機五大區別
路由器與交換機共享的方法