[TOC]
概述
層次結(jié)構(gòu)
junos是按層次結(jié)構(gòu)來管理配置的。可以在任何一級進行edit,如果在父級delete,會被它及它的下級配置一起刪除

image
模式
cli操作(operational)模式
操作模式能干什么?
- 查看當前配置、設(shè)備運行狀態(tài)、路由會話信息
- 在操作模式下輸入config或edit命令進入配置模式
怎樣進入cli模式?
- 登錄后輸入
cli可以進入操作模式 - 或者的edit模式下,用run + cli模式下的命令
配置模式(configure)模式
配置模式可對各個模塊進行配置
配置模式可分層分級配置
edit 命令進入下一級,exit返回上一級,top回到根級
怎樣修改配置
- cli
- config
- set ... 或 delete...(增加or刪除)、activate...(激活功能模塊)或deactivate(關(guān)閉功能模塊)
- 修改完后使用
commit使配置生效,可以使用commit confirmed 2,要求在2分鐘內(nèi)再次輸入commit確認,否則配置回自動倒退(這樣可以避免遠程配置變更時管理員失去對SRX的遠程連接)
查看配置
show查看當前候選配置(還沒有commit的)run show config查看當前生效的配置(Active config)-
show | compare 可以以“+”或“-”的方式對比候選配置和生效配置
下面的例子使用set修改了主機名,show | compare回顯示
+ host-name SRX -A
[edit]
root# set system host-name SRX_A
[edit]
root# show | compare
[edit system]
+ host-name SRX_A;
[edit]
root#
怎樣回退到前的配置
- 缺省按先后 commit順序自動保存50份有效配置
- 通過執(zhí)行 rolback和commit命令返回到以前配置(如 rollback 0/ commit可返回到前一 commit配置)
- 也可以直接通過執(zhí)行
save configname.conf手動保存當前配置,并執(zhí)行load override configname_conf / commit調(diào)用前期手動保存的配置 - 執(zhí)行
load factory-default / commit命令可恢復(fù)到出廠缺省配置。
主要配置
部署SRX防火墻主要有以下幾個方面需要進行配置:
- System:主要是系統(tǒng)級內(nèi)容配置,如主機名、管理員賬號口令及權(quán)限、時鐘時區(qū)、 Syslog、SNMP、系統(tǒng)級開
放的遠程管理服務(wù)(如 telnet)等內(nèi)容。 - Interface:接口相關(guān)配置內(nèi)容。
- Security:是SRX防火墻的主要配置內(nèi)容,安全相關(guān)部分內(nèi)容全部在 Security層級下完成配置,如NAT、Zone
Policy、 Address-book、 Ipsec、 Screen、Idp、UTM等,可簡單理解為 Screenos防火墻安全相關(guān)內(nèi)容都遷移至此配置層次下,除了 Application自定義服務(wù)。 - Application:自定義服務(wù)單獨在此進行配置,配置內(nèi)容與 ScreenOS基本一致
- routing- options:配置靜態(tài)路由或 router-id等系統(tǒng)全局路由屬性配置
配置舉例
怎樣進入或切換各種模式(cli/edit/shell)
下面是console口登錄的
login: root
Password:
--- JUNOS 12.1X47-D20.7 built 2015-03-03 21:53:50 UTC
root@SRX_A%
root@SRX_A% cli //進入cli操作模式
root@SRX_A> configure //進入配置模式
Entering configuration mode
[edit]
root@SRX_A# exit //退出connfig模式,回到cli模式
Exiting configuration mode
root@SRX_A> start shell //進入shell模式
root@SRX_A% exit
exit
root@SRX_A>
一個完整的實例
說明:本實例先將防火墻恢復(fù)到出廠設(shè)置,再逐一配置,本實例的拓撲如下

image
- 將防火墻ge-0/0/0分到untrust區(qū)域,ge-0/0/1分到trust區(qū)域
- 主機A區(qū)域的主機可以ping主機B
- 主機A可以訪問B區(qū)域的SSH服務(wù)
root@SRX_A% cli
root@SRX_A> configure
Entering configuration mode
[edit]
root@SRX_A# load factory-default
warning: activating factory configuration
[edit] //恢復(fù)出廠后,必須立刻設(shè)置root帳號密碼>
root@SRX_A# set system root-authentication plain-text-password
New password:
Retype new password:
[edit]
root@SRX_A# commit
commit complete
root@SRX_A% exit
root@SRX_A> request system reboot
Reboot the system ? [yes,no] (no) yes
Shutdown NOW!
[pid 1543]
root@SRX_A>
*** FINAL System shutdown message from root@SRX_A ***
//重啟后
root@%
root@% cli
root> configure
Entering configuration mode
[edit]
root# set system host-name srx-a
[edit]
root# run set date 201912201110.00
Fri Dec 20 11:10:00 UTC 2019
[edit]
root# set system time-zone Asia/Shanghai
//分別給接口設(shè)置IP,注意,不能把IP直接設(shè)在接口上,而是設(shè)置在子接口上,“unit 0”就是子接口
root# set interfaces ge-0/0/0 unit 0 family inet address 172.16.1.1/24
root# set interfaces ge-0/0/1 unit 0 family inet address 172.16.2.1/24
//設(shè)置默認路由
root# set routing-options static route 0.0.0.0/0 next-hop 172.16.1.254
//將端口分配到各個security-zone上,這是必須的,沒被分配安全區(qū)域的接口,即使有IP也是不能通信,但能看到MAC地址
root@# set security zones security-zone untrust interfaces ge-0/0/0.0
root@# set security zones security-zone trust interfaces ge-0/0/1.0
root@srx-a# commit
commit complete
[edit]
//此時,在防火墻上應(yīng)該可以ping與它直連的設(shè)備了
root@srx-a# run ping 172.16.2.3
PING 172.16.2.3 (172.16.2.3): 56 data bytes
64 bytes from 172.16.2.3: icmp_seq=0 ttl=64 time=24.742 ms
64 bytes from 172.16.2.3: icmp_seq=1 ttl=64 time=11.010 ms
//下面的四個服務(wù)是出廠默認允許從untrust接口訪問的服務(wù),可以根據(jù)需要決定是否刪除。如果需要從untrust
//區(qū)域訪問trust區(qū)域的服務(wù),則需要另外使用policy
root@# set security zones security-zone untrust interfaces ge-0/0/0.0 host-inbound-traffic system-services http
root@# set security zones security-zone untrust interfaces ge-0/0/0.0 host-inbound-traffic system-services https
root@# set security zones security-zone untrust interfaces ge-0/0/0.0 host-inbound-traffic system-services ssh
root@# set security zones security-zone untrust interfaces ge-0/0/0.0 host-inbound-traffic system-services telnet
//設(shè)置允許trust區(qū)域的主機ping 接口ge-0/0/1.0(要commit才生效)
root@#set security zones security-zone trust interfaces ge-0/0/1.0 host-inbound-traffic system-services ping
//下面的四條配置允許untrust區(qū)域的any主機ping trust區(qū)域的any主機
//(要注意是否存在默認deny所以的policy)
set security policies from-zone untrust to-zone trust policy untrust-to-trust match source-address any
set security policies from-zone untrust to-zone trust policy untrust-to-trust match destination-address any
set security policies from-zone untrust to-zone trust policy untrust-to-trust match application junos-ping
set security policies from-zone untrust to-zone trust policy untrust-to-trust then permit
//增加允許untrust的 any訪問trust的ssh
root@srx-a# edit security policies from-zone untrust to-zone trust policy untrust-to-trust
[edit security policies from-zone untrust to-zone trust policy untrust-to-trust]
root@srx-a# set match application junos-ssh
[edit security policies from-zone untrust to-zone trust policy untrust-to-trust]
root@srx-a# show |compare
[edit security policies from-zone untrust to-zone trust policy untrust-to-trust match]
- application junos-ping;
+ application [ junos-ping junos-ssh ];
[edit security policies from-zone untrust to-zone trust policy untrust-to-trust]
root@srx-a# commit
commit complete
//如果只是想讓172.16.1.2主機訪問,要改成這樣
set security zones security-zone untrust address-book address 172.16.1.2 172.16.1.2/32
set security policies from-zone untrust to-zone trust policy allow-access-ssh match source-address 172.16.1.2
set security policies from-zone untrust to-zone trust policy allow-access-ssh match destination-address any
set security policies from-zone untrust to-zone trust policy allow-access-ssh match application junos-ssh
set security policies from-zone untrust to-zone trust policy allow-access-ssh then permit
//然后把any的刪掉
root@srx-a# delete security policies from-zone untrust to-zone trust policy untrust-to-trust
[edit]
root@srx-a# show |compare
[edit security policies from-zone untrust to-zone trust]
- policy untrust-to-trust {
- match {
- source-address any;
- destination-address any;
- application [ junos-ping junos-ssh ];
- }
- then {
- permit;
- }
- }
[edit]
root@srx-a# commit
commit complete

image