Juniper JUNOS模擬器配置導(dǎo)航
本文中,我們會(huì)看一看如何多JUNOS配置文件進(jìn)行操作。JUNOS配置文件在層級(jí)結(jié)構(gòu)中很有條理;一旦你明白其結(jié)構(gòu)和不同的層級(jí),就可以輕松瀏覽文件并準(zhǔn)確找到需要檢測和更改的部件,而且還不會(huì)受到其他不需要部件的影響。
首先,我們登錄路由:
Juniper5 (ttyd0) login: jeff Password: --- JUNOS 8.5R1.13 built 2007-11-14 17:54:24 UTC jeff@Juniper5> |
該指令顯示了用戶名(jeff)和路由器的名稱(Juniper5)。路由器現(xiàn)在處于可操作狀態(tài),處于這種狀態(tài)下的時(shí)候,我們可以執(zhí)行顯示路由狀態(tài)和數(shù)據(jù)庫,ping和跟蹤路由,遠(yuǎn)程登錄(telnet)和ssh,重啟系統(tǒng)進(jìn)程等任務(wù)——這些任務(wù)大都是我們在監(jiān)視和解決系統(tǒng)問題時(shí)需要用到的命令。JUNOS可操作模式相當(dāng)于IOS用戶的EXEC模式。
使用IOS的時(shí)候,問號(hào)可以為我們提供很多幫助;當(dāng)我們不記得命令字符串中的下一個(gè)語句時(shí)或者只需要查看可用選項(xiàng)時(shí),問號(hào)就成了基礎(chǔ)信息工具。我們可以使用問號(hào)來查看可操作狀態(tài)中所有可用的命令:
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#
為了對配置進(jìn)行更改, 筆者通過輸入configure命令來輸入配置模式:
jeff@Juniper5> configure |
JUNOS配置模式相當(dāng)于IOS中專有的EXEC或啟用的模式。注意指令從>改為了#,在你輸入enable命令后IOS會(huì)有同樣的更改。
另一種JUNOS配置模式的特性是位于指令上面的[edit]欄目。我們可以圍繞配置層級(jí)來操作以便觀察或更改文件的某部分;[edit]欄目準(zhǔn)確指出了你所在層級(jí)的位置。當(dāng)這一欄顯示[edit]的時(shí)候,說明我們位于最頂層。因此,舉例來說,如果在你的類型顯示這一層級(jí)且沒出現(xiàn)修改程序的時(shí)候,JUNOS會(huì)顯示整個(gè)構(gòu)造。
將show命令與問號(hào)一起使用,我們會(huì)看到構(gòu)造頂部的層級(jí):
[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 |
與該列表一起的標(biāo)簽對層級(jí)做了很好的詮釋。例如,所有的界面都配置在了interfaces級(jí)別下,所有的協(xié)議都配置在了protocols級(jí)別下,而所有的路由策略都位于policy-options級(jí)別下。 #p#
在每個(gè)頂層下面存在許多子層級(jí)。例如,在protocols下你可以找到BGP,OSPFv2,OSPFv3,MPLS,RSVP等。在those下可以發(fā)現(xiàn)更下一層的子層級(jí)。比方,在OSPF下,我們可以找到區(qū)域配置的層級(jí),而在每個(gè)區(qū)域?qū)蛹?jí)以下還可以找到用來指定區(qū)域內(nèi)界面的層級(jí)。
配置的層級(jí)結(jié)構(gòu)讓我們可以只關(guān)注感興趣的局部配置上。假設(shè)你只想看一下構(gòu)造中的BGP部分。show protocols bgp會(huì)顯示出整個(gè)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; } |
在上面的配置中,我們看到出現(xiàn)了一個(gè)本地地址(192.168.50.10),所有的BGP TCP對話都源自該地址,本地AS號(hào)碼是65503,而且還存在三個(gè)同級(jí)組:CustomerX,CustomerY和CustomerZ。CustomerX具備一個(gè)輸出路由策略,我們已將其命名為Xpolicy;由于用于該組(65510)的AS號(hào)碼不同于本地AS號(hào)碼,所有它們就是EBGP同級(jí)組。位于這個(gè)組之下有三個(gè)臨近組,所有這些組都經(jīng)由個(gè)人密碼驗(yàn)證。同級(jí)組CustomerY(擁有三個(gè)臨近組)和CustomerZ(有一個(gè)臨近組)是IBGP,因?yàn)樗麄儾痪邆渲付▎为?dú)AS號(hào)碼,而且也沒有配備驗(yàn)證。 #p#
假設(shè),你所感興趣的只是CustomerX下的臨近組192.168.1.5的配置而不是整個(gè)BGP配置。我們可以用更明確的show命令,讓JUNOS只顯示出所需部分:
[edit] jeff@Juniper5# show protocols bgp group CustomerX neighbor 192.168.1.5 authentication-key "$9$JiZHmzF/t0I69ev"; ## SECRET-DATA |
當(dāng)然,如果你處于配置模式,可能會(huì)想作出更多操作。在配置模式中單獨(dú)使用問號(hào),就可以看到你能使用的各種操作:
[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#
筆者想為該配置添加更多要素,而要實(shí)現(xiàn)這一操作就要用到set命令。假設(shè)我們想為OSPF area 5添加界面fe-0/0/0??梢允褂胹et,我們要按層級(jí)一直向下指定每一層知道我們到達(dá)所需位置——在area 5之下——界面要添加的位置:
[edit] jeff@Juniper5# set protocols ospf area 5 interface fe-0/0/0 |
如果沒有啟用OSPF或area 5不存在,相同的命令可能會(huì)啟用該協(xié)議并創(chuàng)建area 5,除此之外再向area中添加界面。
另一個(gè)方法是先移動(dòng)到需要的層級(jí),然后用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之后,指令后的欄目改為顯示我們所在的層級(jí)。我們再使用set命令往這一層添加界面fe-0/0/1。我們在這個(gè)時(shí)候指定整個(gè)層級(jí),因?yàn)槲覀円呀?jīng)處于要作出更改的層級(jí)。
這兩種方法可以用來輕松管理配置。如果你只要為配置添加一兩個(gè)語句,那么在頂層進(jìn)行操作,指定你要改變那一層的完整路徑,會(huì)更簡便。如果你要對某特定層級(jí)進(jìn)行擴(kuò)展性改變,一般可以先用edit命令移動(dòng)到該層,然后直接作出更改就可以了。
edit命令可以帶你到達(dá)指定層級(jí),up可以上升一層。假設(shè)我們位于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; } |
你可以看到指令上面的那一欄在執(zhí)行了up命令后發(fā)生了改變。每一欄的Show命令顯示了該層下面的所有配置語句。
如果你想從任意層跳回到頂層,可以使用top命令:
[edit protocols ospf] jeff@Juniper5# top [edit] jeff@Juniper5# |
在這個(gè)例子中,我們還可以通過執(zhí)行up命令兩次的方式到達(dá)頂部:[edit protocols ospf] => up => [edit protocols] => up => [edit]。同時(shí)使用edit,up和top命令,可以移動(dòng)到任意配置文件中的任意位置從而可以進(jìn)而更有效的操作。
除了set命令以外,還有一些重要的命令可用來更改配置。在這里我們不加贅述,只是點(diǎn)到為止:
◆delete命令與set相反;它從配置中刪除了語句。
◆replace用來替換語句。
◆insert 用來添加帶有指定要素的語句時(shí)。
◆deactivate 禁用某語句而又不想刪除該語句的時(shí)候可以使用。
◆activate 重新激活被禁用的語句。
◆annotate 用來向語句添加注釋;適用于那些復(fù)雜的配置。
JUNOS和IOS之間可操作性的區(qū)別還在于,當(dāng)你向JUNOS配置中輸入一個(gè)新語句后,它不會(huì)馬上在路由上執(zhí)行。你可以盡可能多的作出更改,檢查更改,然后再將更改清楚明確地告訴路由后才執(zhí)行。
【編輯推薦】