Juniper JUNOS模擬器配置導航
本文中,我們會看一看如何多JUNOS配置文件進行操作。JUNOS配置文件在層級結構中很有條理;一旦你明白其結構和不同的層級,就可以輕松瀏覽文件并準確找到需要檢測和更改的部件,而且還不會受到其他不需要部件的影響。
首先,我們登錄路由:
Juniper5 (ttyd0) login: jeff Password: --- JUNOS 8.5R1.13 built 2007-11-14 17:54:24 UTC jeff@Juniper5> |
該指令顯示了用戶名(jeff)和路由器的名稱(Juniper5)。路由器現在處于可操作狀態,處于這種狀態下的時候,我們可以執行顯示路由狀態和數據庫,ping和跟蹤路由,遠程登錄(telnet)和ssh,重啟系統進程等任務——這些任務大都是我們在監視和解決系統問題時需要用到的命令。JUNOS可操作模式相當于IOS用戶的EXEC模式。
使用IOS的時候,問號可以為我們提供很多幫助;當我們不記得命令字符串中的下一個語句時或者只需要查看可用選項時,問號就成了基礎信息工具。我們可以使用問號來查看可操作狀態中所有可用的命令:
jeff@Juniper5> ? Possible completions: clear Clear information in the system configure Manipulate software configuration information diagnose Invoke diagnose script| file Perform file operations help Provide help information monitor Show real-time debugging information mtrace Trace multicast path from source to receiver ping Ping remote target quit Exit the management session request Make system-level requests restart Restart software process set Set CLI properties, date/time, craft interface message show Show system information ssh Start secure shell on another host start Start shell telnet Telnet to another host test Perform diagnostic debugging traceroute Trace route to remote host |
#p#
為了對配置進行更改, 筆者通過輸入configure命令來輸入配置模式:
jeff@Juniper5> configure |
JUNOS配置模式相當于IOS中專有的EXEC或啟用的模式。注意指令從>改為了#,在你輸入enable命令后IOS會有同樣的更改。
另一種JUNOS配置模式的特性是位于指令上面的[edit]欄目。我們可以圍繞配置層級來操作以便觀察或更改文件的某部分;[edit]欄目準確指出了你所在層級的位置。當這一欄顯示[edit]的時候,說明我們位于最頂層。因此,舉例來說,如果在你的類型顯示這一層級且沒出現修改程序的時候,JUNOS會顯示整個構造。
將show命令與問號一起使用,我們會看到構造頂部的層級:
[edit] jeff@Juniper5# show ? Possible completions: <[Enter]> Execute this command > access Network access configuration > accounting-options Accounting data configuration > applications Define applications by protocol characteristics + apply-groups Groups from which to inherit configuration data > chassis Chassis configuration > class-of-service Class-of-service configuration > event-options Event processing configuration > firewall Define a firewall configuration > forwarding-options Configure options to control packet forwarding > groups Configuration groups > interfaces Interface configuration > policy-options Routing policy option configuration > protocols Routing protocol configuration > routing-instances Routing instance configuration > routing-options Protocol-independent routing option configuration > security Security configuration > services Service PIC applications settings > snmp Simple Network Management Protocol configuration > system System parameters | Pipe through a command |
與該列表一起的標簽對層級做了很好的詮釋。例如,所有的界面都配置在了interfaces級別下,所有的協議都配置在了protocols級別下,而所有的路由策略都位于policy-options級別下。 #p#
在每個頂層下面存在許多子層級。例如,在protocols下你可以找到BGP,OSPFv2,OSPFv3,MPLS,RSVP等。在those下可以發現更下一層的子層級。比方,在OSPF下,我們可以找到區域配置的層級,而在每個區域層級以下還可以找到用來指定區域內界面的層級。
配置的層級結構讓我們可以只關注感興趣的局部配置上。假設你只想看一下構造中的BGP部分。show protocols bgp會顯示出整個BGP配置:
[edit] jeffr@Juniper5# show protocols bgp local-address 192.168.50.10; local-as 65503; group CustomerX { export XPolicy; peer-as 65510; neighbor 192.168.1.1 { authentication-key "$9$-Ud2aji.5z6qm"; ## SECRET-DATA } neighbor 192.168.1.5 { authentication-key "$9$JiZHmzF/t0I69ev"; ## SECRET-DATA } neighbor 192.168.1.10 { authentication-key "$9$mPF/u0Icrv1Rbs"; ## SECRET-DATA } } group CustomerY { neighbor 192.168.10.20; neighbor 192.168.10.30; neighbor 192.168.10.40; } group CustomerZ { neighbor 192.168.20.100; } |
在上面的配置中,我們看到出現了一個本地地址(192.168.50.10),所有的BGP TCP對話都源自該地址,本地AS號碼是65503,而且還存在三個同級組:CustomerX,CustomerY和CustomerZ。CustomerX具備一個輸出路由策略,我們已將其命名為Xpolicy;由于用于該組(65510)的AS號碼不同于本地AS號碼,所有它們就是EBGP同級組。位于這個組之下有三個臨近組,所有這些組都經由個人密碼驗證。同級組CustomerY(擁有三個臨近組)和CustomerZ(有一個臨近組)是IBGP,因為他們不具備指定單獨AS號碼,而且也沒有配備驗證。 #p#
假設,你所感興趣的只是CustomerX下的臨近組192.168.1.5的配置而不是整個BGP配置。我們可以用更明確的show命令,讓JUNOS只顯示出所需部分:
[edit] jeff@Juniper5# show protocols bgp group CustomerX neighbor 192.168.1.5 authentication-key "$9$JiZHmzF/t0I69ev"; ## SECRET-DATA |
當然,如果你處于配置模式,可能會想作出更多操作。在配置模式中單獨使用問號,就可以看到你能使用的各種操作:
[edit] jeff@Juniper5# ? Possible completions: <[Enter]> Execute this command activate Remove the inactive tag from a statement annotate Annotate the statement with a comment commit Commit current set of changes copy Copy a statement deactivate Add the inactive tag to a statement delete Delete a data element edit Edit a sub-element exit Exit from this level help Provide help information insert Insert a new ordered data element load Load configuration from ASCII file quit Quit from this level rename Rename a statement replace Replace character string in configuration rollback Roll back to previous committed configuration run Run an operational-mode command save Save configuration to ASCII file set Set a parameter show Show a parameter status Show users currently editing configuration top Exit to top level of configuration up Exit one level of configuration wildcard Wildcard operations |
#p#
筆者想為該配置添加更多要素,而要實現這一操作就要用到set命令。假設我們想為OSPF area 5添加界面fe-0/0/0。可以使用set,我們要按層級一直向下指定每一層知道我們到達所需位置——在area 5之下——界面要添加的位置:
[edit] jeff@Juniper5# set protocols ospf area 5 interface fe-0/0/0 |
如果沒有啟用OSPF或area 5不存在,相同的命令可能會啟用該協議并創建area 5,除此之外再向area中添加界面。
另一個方法是先移動到需要的層級,然后用edit命令作出更改:
[edit] jeff@Juniper5# edit protocols ospf area 5 [edit protocols ospf area 0.0.0.5] jeff@Juniper5# set interface fe-0/0/1 |
注意輸入edit protocols ospf area 5之后,指令后的欄目改為顯示我們所在的層級。我們再使用set命令往這一層添加界面fe-0/0/1。我們在這個時候指定整個層級,因為我們已經處于要作出更改的層級。
這兩種方法可以用來輕松管理配置。如果你只要為配置添加一兩個語句,那么在頂層進行操作,指定你要改變那一層的完整路徑,會更簡便。如果你要對某特定層級進行擴展性改變,一般可以先用edit命令移動到該層,然后直接作出更改就可以了。
edit命令可以帶你到達指定層級,up可以上升一層。假設我們位于OSPF area 5,我們想上移到OSPF層:
[edit protocols ospf area 0.0.0.5] jeff@Juniper5# up [edit protocols ospf] jeff@Juniper5# show area 0.0.0.5 { interface fe-0/0/0.0; interface fe-0/0/1.0; } |
你可以看到指令上面的那一欄在執行了up命令后發生了改變。每一欄的Show命令顯示了該層下面的所有配置語句。
如果你想從任意層跳回到頂層,可以使用top命令:
[edit protocols ospf] jeff@Juniper5# top [edit] jeff@Juniper5# |
在這個例子中,我們還可以通過執行up命令兩次的方式到達頂部:[edit protocols ospf] => up => [edit protocols] => up => [edit]。同時使用edit,up和top命令,可以移動到任意配置文件中的任意位置從而可以進而更有效的操作。
除了set命令以外,還有一些重要的命令可用來更改配置。在這里我們不加贅述,只是點到為止:
◆delete命令與set相反;它從配置中刪除了語句。
◆replace用來替換語句。
◆insert 用來添加帶有指定要素的語句時。
◆deactivate 禁用某語句而又不想刪除該語句的時候可以使用。
◆activate 重新激活被禁用的語句。
◆annotate 用來向語句添加注釋;適用于那些復雜的配置。
JUNOS和IOS之間可操作性的區別還在于,當你向JUNOS配置中輸入一個新語句后,它不會馬上在路由上執行。你可以盡可能多的作出更改,檢查更改,然后再將更改清楚明確地告訴路由后才執行。
【編輯推薦】