示例:配置 REST API
此示例演示如何在多台设备上配置 REST API Junos OS。
要求
需要运行 14.2 Junos OS更高版本的路由、交换或安全设备。
概述
此示例为多服务边缘路由器瞻博网络 M10i REST API。该示例配置了 HTTP 和 HTTPS 接入,同时具有光tpd 和 Juise 追踪。
配置
CLI快速配置
要快速配置此示例,请复制以下命令,将其粘贴到文本文件中,删除所有换行符,更改详细信息,以匹配网络配置,将命令复制并粘贴到 层次结构级别的 CLI 中,然后从配置模式进入 。 [edit]
commit
set system services rest control allowed-sources [192.0.2.0 198.51.100.0] set system services rest control connection-limit 100 set system services rest http port 3000 set system services rest http addresses [203.0.113.0 203.0.113.1] set system services rest https port 3443 set system services rest https addresses [203.0.113.2 203.0.113.3] set system services rest https server-certificate testcert set system services rest https cipher-list rsa-with-3des-ede-cbc-sha set system services rest https mutual-authentication certificate-authority testca set system services rest traceoptions flag all set system services rest enable-explorer
配置 REST API
逐步过程
要配置 REST API,请进行以下操作:
为传入 HTTP 和 HTTPS 连接指定允许的 IP 地址。
[edit] user@R1# set system services rest control allowed-sources [192.0.2.0 198.51.100.0]
指定通过 HTTP 和 HTTPS 允许的最大连接数。
[edit] user@R1# set system services rest control connection-limit 100
设置传入 HTTP 连接的 TCP 端口。
[edit] user@R1# set system services rest http port 3000
设置服务器侦听传入 HTTP 连接的地址。
[edit] user@R1# set system services rest http addresses [203.0.113.0 203.0.113.1]
设置传入 HTTPS 连接的 TCP 端口。
[edit] user@R1# set system services rest https port 3443
设置服务器侦听传入 HTTPS 连接的地址。
[edit] user@R1# set system services rest https addresses [203.0.113.2 203.0.113.3]
设置服务器证书。
[edit] user@R1# set system services rest https server-certificate testcert
配置服务器可用于执行加密和解密功能的密码集。
[edit] user@R1# set system services rest https cipher-list rsa-with-3des-ede-cbc-sha
(可选)使用证书在服务器和客户端上设置 TLS 相互认证。
[edit] user@R1# set system services rest https mutual-authentication certificate-authority testca
(可选)为 lighttpd、juise 或二者配置追踪选项。
[edit] user@R1# set system services rest traceoptions flag all
(可选)启用 REST API Explorer。
[edit] user@R1# set system services rest enable-explorer
提交配置。
[edit] user@R1# commit and-quit
结果
system { services { rest { control { allowed-sources [ 192.0.2.0 198.51.100.0 ]; connection-limit 100; } enable-explorer; http { addresses [ 203.0.113.0 203.0.113.1 ]; port 3000; } https { port 3443; addresses [ 203.0.113.2 203.0.113.3 ]; server-certificate testcert; cipher-list rsa-with-3des-ede-cbc-sha; mutual-authentication { certificate-authority testca; } } traceoptions { flag all; } } } }
验证
验证 REST API 配置
目的
确认 REST API 配置在设备上工作正常。
行动
发出操作模式命令,显示 REST API show configuration system services rest
配置。
user@R1> show configuration system services rest http { port 3000; addresses [ 203.0.113.0 203.0.113.1 ]; } https { port 3443; addresses [ 203.0.113.2 203.0.113.3 ]; server-certificate testcert; cipher-list rsa-with-3des-ede-cbc-sha; mutual-authentication { certificate-authority testca; } } control { allowed-sources [ 192.0.2.0 198.51.100.0 ]; connection-limit 100; } traceoptions { flag all; } enable-explorer;
意义
此示例在多服务边缘路由器上配置了 HTTP 瞻博网络 M10i HTTPS 访问。对于 HTTP 访问,设备将侦听端口 3000,允许来自 IP 地址 192.0.2.0、198.51.100.0、203.0.113.0 和 203.0.113.1 的信息流。对于更安全的连接,使用端口 3443 配置了 HTTPS 访问,允许使用 192.0.2.0、198.51.100.0、203.0.113.2 和 203.0.113.3 的 IP 地址。为 HTTP 和 HTTPS 配置了 100 个连接限制,同时已启用了 juise 和 lighttpd 追踪。默认情况下,REST API Explorer 处于禁用状态(请参阅 示例:使用 REST API Explorer)。