示例:配置 DHCP 防火墙过滤器以保护路由引擎
此示例说明如何配置防火墙过滤器,以确保正确的 DHCP 数据包可以到达运行该 jdhcpd 进程的受支持路由器上的路由引擎。
要求
此配置示例仅适用于由进程(而非传统dhcpd进程或 fud(UDP 转发)进程提供 jdhcpd DHCP 本地服务器和 DHCP 中继代理服务的路由器。DHCP 中继必须在层次结构级别下[edit forwarding-options dhcp-relay]配置,而非在层次结构级别配置[edit forwarding-options helpers bootp]。
在配置此功能之前,不需要除设备初始化之外的特殊配置。
概述
在路由引擎上处理 DHCP 数据包的防火墙过滤器必须正确考虑 DHCP 服务器流量的 UDP 端口 67 (bootps) 和 DHCP 客户端流量的 UDP 端口 68 (bootpc)。这些端口是 DHCP 运维的基础,必须在防火墙过滤器配置中正确处理。
Junos OS 表现出管理员必须了解的特定 DHCP 数据包处理行为。当线卡上收到数据包时,jdhcpd 进程会执行封装并修改 UDP 报头,在转发到路由引擎之前将源端口和目标端口都设置为 68。端口重写是瞻博网络 DHCP 实施的一个关键方面。
在 DHCP 中继和代理方案中,流量会遵循特定的端口模式。传输到服务器的客户端数据包最初使用源端口 68 和目标端口 67。当服务器响应时,它使用源和目标端口 67,但线卡会执行另一次修改,在传送到路由引擎之前将这些修改重写到端口 68。
这些行为对防火墙有重要的影响。为确保 DHCP 正常运行,必须将防火墙过滤器配置为允许端口 67 和 68。此双端口要求可容纳原始客户端请求(使用端口 68 到 67)和重写的服务器响应(从端口 67 转换为 68)。过滤器必须保持这种灵活性,以处理所有合法的 DHCP 流量场景,同时仍为路由引擎提供预期的保护。
此示例不会显示所有可能的配置选项,也不会显示如何在配置中应用过滤器。此示例既适用于过滤器的静态应用,也适用于具有动态配置文件的动态应用。
配置
过程
CLI 快速配置
要快速配置示例路由引擎 DHCP 过滤器,请复制以下命令,将其粘贴到文本文件中,删除所有换行符,然后将命令复制并粘贴到 CLI 中。
[edit] edit firewall family inet filter RE-protect edit term dhcp-client-accept set from source-address 0.0.0.0/32 set from destination-address 255.255.255.255/32 set from protocol udp set from source-port 68 set from destination-port [67 68] set then count dhcp-client-accept set then accept up edit term dhcp-server-accept set from protocol udp set from source-port 67 set from source-port 68 set from destination-port 67 set from destination-port 68 set then count dhcp-server-accept set then accept top
分步程序
下面的示例要求您在各个配置层级中进行导航。有关操作说明,请参阅在 配置模式下使用 CLI 编辑器。
要配置 DHCP 防火墙过滤器来保护路由引擎,请执行以下操作:
创建或指定防火墙过滤器。
[edit firewall] user@host# edit family inet filter RE-protect
为客户端创建筛选器术语。
[edit firewall family inet filter RE-protect] user@host# edit term dhcp-client-accept
指定 DHCP 数据包的匹配条件。
[edit firewall family inet filter RE-protect term dhcp-client-accept] user@host# set from source-address 0.0.0.0/32 user@host# set from destination-address 255.255.255.255/32 user@host# set from protocol udp user@host# set from source-port 68 user@host# set from destination-port 67
指定要对匹配的数据包执行的操作。
[edit firewall family inet filter RE-protect term dhcp-client-accept] user@host# set then count dhcp-client-accept user@host# set then accept
为服务器创建筛选器术语。
[edit firewall family inet filter RE-protect] user@host# edit term dhcp-server-accept
指定 DHCP 数据包的匹配条件。
[edit firewall family inet filter RE-protect term dhcp-server-accept] user@host# set from protocol udp user@host# set from source-port [67 68] user@host# set from destination-port [67 68]
指定要对匹配的数据包执行的操作。
[edit firewall family inet filter RE-protect term dhcp-server-accept] user@host# set then count dhcp-client-accept user@host# set then accept
结果
在配置模式下,输入 show firewall 命令以确认您的配置。如果输出未显示预期的配置,请重复此示例中的配置说明进行更正。
[edit]
user@host# show firewall
family inet {
filter RE-protect {
term dhcp-client-accept {
from {
source-address {
0.0.0.0/32;
}
destination-address {
255.255.255.255/32;
}
protocol udp;
source-port 68;
destination-port 67;
}
then {
count dhcp-client-accept;
accept;
}
}
term dhcp-server-accept {
from {
protocol udp;
source-port [ 67 68 ];
destination-port [ 67 68 ];
}
then {
count dhcp-server-accept;
accept;
}
}
}
}
如果完成设备配置,请从配置模式进入。commit
验证
要确认路由引擎 DHCP 保护过滤器正确传递 DHCP 数据包,请执行以下任务:
验证 DHCP 过滤器操作
目的
验证当 DHCP 流量传递到路由引擎时,这两个计数器是否都会递增。
行动
在操作模式下,输入命令 show firewall family inet filter RE-protect 。
user@host> show firewall family inet filter RE-protect Filter: RE-protect Counters: Name Bytes Packets dhcp-client-accept 328 1 dhcp-server-accept 574 1 user@host> show firewall family inet filter RE-protect Filter: RE-protect Counters: Name Bytes Packets dhcp-client-accept 660 2 dhcp-server-accept 1152 2
意义
输出列出了配置的计数器 dhcp-client-accept 和 dhcp-server-accept。通过多次发出命令,您可以看到字节和数据包字段都显示正在接受和计算流量。