[TOC]
概述
层次结构
junos是按层次结构来管理配置的。可以在任何一级进行edit,如果在父级delete,会被它及它的下级配置一起删除
image
模式
cli操作(operational)模式
操作模式能干什么?
- 查看当前配置、设备运行状态、路由会话信息
- 在操作模式下输入config或edit命令进入配置模式
怎样进入cli模式?
- 登录后输入
cli
可以进入操作模式 - 或者的edit模式下,用run + cli模式下的命令
配置模式(configure)模式
配置模式可对各个模块进行配置
配置模式可分层分级配置
edit 命令进入下一级,exit返回上一级,top回到根级
怎样修改配置
- cli
- config
- set ... 或 delete...(增加or删除)、activate...(激活功能模块)或deactivate(关闭功能模块)
- 修改完后使用
commit
使配置生效,可以使用commit confirmed 2
,要求在2分钟内再次输入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份有效配置
- 通过执行 rolback和commit命令返回到以前配置(如 rollback 0/ commit可返回到前一 commit配置)
- 也可以直接通过执行
save configname.conf
手动保存当前配置,并执行load override configname_conf / commit
调用前期手动保存的配置 - 执行
load factory-default / commit
命令可恢复到出厂缺省配置。
主要配置
部署SRX防火墙主要有以下几个方面需要进行配置:
- System:主要是系统级内容配置,如主机名、管理员账号口令及权限、时钟时区、 Syslog、SNMP、系统级开
放的远程管理服务(如 telnet)等内容。 - Interface:接口相关配置内容。
- Security:是SRX防火墙的主要配置内容,安全相关部分内容全部在 Security层级下完成配置,如NAT、Zone
Policy、 Address-book、 Ipsec、 Screen、Idp、UTM等,可简单理解为 Screenos防火墙安全相关内容都迁移至此配置层次下,除了 Application自定义服务。 - Application:自定义服务单独在此进行配置,配置内容与 ScreenOS基本一致
- routing- options:配置静态路由或 router-id等系统全局路由属性配置
配置举例
怎样进入或切换各种模式(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>
一个完整的实例
说明:本实例先将防火墙恢复到出厂设置,再逐一配置,本实例的拓扑如下
image
- 将防火墙ge-0/0/0分到untrust区域,ge-0/0/1分到trust区域
- 主机A区域的主机可以ping主机B
- 主机A可以访问B区域的SSH服务
root@SRX_A% cli
root@SRX_A> configure
Entering configuration mode
[edit]
root@SRX_A# load factory-default
warning: activating factory configuration
[edit] //恢复出厂后,必须立刻设置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
//分别给接口设置IP,注意,不能把IP直接设在接口上,而是设置在子接口上,“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
//设置默认路由
root# set routing-options static route 0.0.0.0/0 next-hop 172.16.1.254
//将端口分配到各个security-zone上,这是必须的,没被分配安全区域的接口,即使有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]
//此时,在防火墙上应该可以ping与它直连的设备了
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
//下面的四个服务是出厂默认允许从untrust接口访问的服务,可以根据需要决定是否删除。如果需要从untrust
//区域访问trust区域的服务,则需要另外使用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
//设置允许trust区域的主机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区域的any主机ping trust区域的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