DNS Session Helper
DNS Session Helper
DNS Session Helper 在后台检查经过 FortiGate 转发的 DNS 流量,从 DNS 响应中被动学习主机名和 A/AAAA 记录,并将结果写入两种 DNS 缓存:
- 主机名(hostname)缓存:保存 FortiGate 从经过设备的 DNS 响应中学习到的 IP 地址/域名对应关系。DNS Proxy 可以复用这些记录,减少主动查询,同时为日志和网络可见性功能提供 IP 地址与主机名的关联信息。
- FQDN 地址对象缓存:保存 FQDN 地址对象已解析或学习到的 IP 地址。普通 FQDN 地址对象通过主动 DNS 查询更新缓存,通配符 FQDN 地址对象通过检查经过 FortiGate 的 DNS 响应学习 IP 地址。
DNS Proxy 可以直接使用这些记录,减少主动 FQDN 查询和反向 DNS 查询产生的流量。
FortiOS 提供以下两种 DNS Session Helper:
dns-udp:监听 UDP 53 端口,默认启用。dns-tcp:监听 TCP 53 端口,默认不启用(无配置)。
配置方法
查看当前 Session Helper 配置,确认 DNS Session Helper 的条目编号、协议和端口。
show system session-helper默认的
dns-udp条目配置如下所示。config system session-helper edit 14 set name dns-udp set protocol 17 set port 53 next end如果需要检查 TCP 53 端口上的 DNS 流量,新建
dns-tcpSession Helper。config system session-helper edit 0 set name dns-tcp set port 53 set protocol 6 next end在放行客户端到 DNS 服务器的防火墙策略中,将服务设置为
ALL,或使用同时包含 TCP 53 和 UDP 53 端口的预定义DNS服务。
判断是否命中 Session Helper
以下示例中,客户端
192.0.2.10通过 FortiGate 查询 DNS 服务器198.51.100.53。使用 Debug Flow 过滤 DNS 流量。diagnose debug reset diagnose debug flow filter clear diagnose debug flow filter saddr 192.0.2.10 diagnose debug flow filter daddr 198.51.100.53 diagnose debug flow filter dport 53 diagnose debug flow show function-name enable diagnose debug flow trace start 10 diagnose debug enable从客户端发起 DNS 查询,在 Debug Flow 输出中查找
run helper-dns-udp或run helper-dns-tcp。输出中的run helper-dns-udp(dir=original)表示该会话由dns-udpSession Helper 处理。id=65308 trace_id=138 func=print_pkt_detail line=5795 msg="vd-root:0 received a packet(proto=17, 192.0.2.10:64504->198.51.100.53:53) from lan." id=65308 trace_id=138 func=init_ip_session_common line=5980 msg="allocate a new session-01610aca" id=65308 trace_id=138 func=vf_ip_route_input_common line=2611 msg="find a route: gw-202.103.1.1 via wan1" id=65308 trace_id=138 func=fw_forward_handler line=990 msg="Allowed by Policy-1:" id=65308 trace_id=138 func=__ip_session_run_tuple line=3443 msg="run helper-dns-udp(dir=original)"完成检查后停止 Debug Flow 并清除过滤条件。
diagnose debug disable diagnose debug reset
查看 NP 加速状态
由 DNS Session Helper 处理的会话不会卸载到 NP,流量由 CPU 处理。可以通过会话表确认当前 DNS 会话的 Helper 和硬件卸载状态。
过滤并查看客户端到 DNS 服务器的会话。
diagnose sys session filter clear diagnose sys session filter src 192.0.2.10 diagnose sys session filter dst 198.51.100.53 diagnose sys session filter dport 53 diagnose sys session list检查会话输出中的
helper和npu info。session info: proto=17 proto_state=01 duration=11 expire=168 timeout=0 refresh_dir=both flags=00000000 socktype=0 sockport=0 av_idx=0 use=3 class_id=0 ha_id=0 policy_dir=0 tunnel=/ helper=dns-udp vlan_cos=0/255 state=log may_dirty npu f00 netflow-reply statistic(bytes/packets/allow_err): org=70/1/1 reply=118/1/1 tuples=2 tx speed(Bps/kbps): 6/0 rx speed(Bps/kbps): 10/0 orgin->sink: org pre->post, reply pre->post dev=40->7/7->40 gwy=202.103.1.1/192.0.2.1 hook=pre dir=org act=noop 192.0.2.10:60608->198.51.100.53:53(0.0.0.0:0) hook=post dir=reply act=noop 198.51.100.53:53->192.0.2.10:60608(0.0.0.0:0) misc=0 policy_id=1 pol_uuid_idx=4997 auth_info=0 chk_client_info=0 vd=0 serial=0019fcaf tos=ff/ff app_list=0 app=0 url_cat=0 sdwan_mbr_seq=1 sdwan_service_id=1 rpdb_link_id=ff000001 ngfw_id=n/a duplicaton_id=0 npu_state=00000000 npu info: flag=0x00/0x00, offload=0/0, ips_offload=0/0, epid=0/0, ipid=0/0, vlan=0x0000/0x0000 vlifid=0/0, vtag_in=0x0000/0x0000 in_npu=0/0, out_npu=0/0, fwd_en=0/0, qid=0/0, ha_divert=0/0 no_ofld_reason: ofld_fail_reason(kernel, drv): none/not-established, none(0)/none(0) npu_state_err=00/04 hrx info: valid=1/1, qid=8/8, npuid=1/1, sublink=0/0helper=dns-udp表示会话由 DNS Session Helper 处理。offload=0/0表示原始方向和响应方向均未卸载到 NP,流量由 CPU 处理。
完成检查后清除会话过滤条件。
diagnose sys session filter clear
查看 DNS Session Helper 记录的缓存
主机名缓存
通过
diagnose test application dnsproxy 13查看主机名缓存,检查缓存中的 IP 地址、域名和剩余 TTL。# diagnose test application dnsproxy 13 worker idx: 0 num=2198 ttl=86400 limit=5000 vdom=0 1.15.170.250 (domain=rc10-g5.oray.com ttl=68769 hits=0) vdom=0 1.71.81.59 (domain=internal-api-security.feishu.cn ttl=746 hits=0) vdom=0 1.71.81.60 (domain=internal-api-security.feishu.cn ttl=746 hits=0) vdom=0 4.150.223.107 (domain=v20.events.data.microsoft.com ttl=18835 hits=0) vdom=0 4.150.223.108 (domain=v10.events.data.microsoft.com ttl=61125 hits=0) ......通过
diagnose test application dnsproxy 14清除主机名缓存,该命令会删除当前已学习的 IP 地址与主机名对应关系,后续经过 FortiGate 的 DNS 响应会重新建立缓存。diagnose test application dnsproxy 14
FQDN 缓存
相关信息
FQDN 地址对象的缓存与 TTL 说明,参见网络管理 → DNS → DNS CLI 配置 → FQDN Cache TTL。
通过 diagnose test application dnsproxy 6 查看所有 FQDN 地址对象的缓存条目,检查 FQDN 地址对象、已缓存的 IP 地址和 TTL。
# diagnose test application dnsproxy 6
worker idx: 0
vfid-0:
name=*.google.com ver=IPv4 wait_list=0 timer=0 min_ttl=26 cache_ttl=0 slot=-1 num=1 wildcard=1
74.125.250.129 (ttl=26:0:0)
name=login.microsoftonline.com ver=IPv4 wait_list=0 timer=6 min_ttl=218 cache_ttl=0 slot=-1 num=8 wildcard=0 rcode=2
20.190.148.164 (ttl=277:0:0) 40.126.16.166 (ttl=277:0:0) 20.190.144.137 (ttl=277:0:0) 20.190.144.166 (ttl=277:0:0) 20.190.144.162 (ttl=277:0:0)
20.190.144.138 (ttl=277:0:0) 20.190.148.163 (ttl=277:0:0) 40.126.16.163 (ttl=277:0:0)
name=www.bilibili.com ver=IPv4 wait_list=0 timer=14 min_ttl=1 cache_ttl=0 slot=0 num=1 wildcard=0 rcode=2
192.168.100.177 (ttl=1:0:0)
name=gmail.com ver=IPv4 wait_list=0 timer=6 min_ttl=1 cache_ttl=0 slot=-1 num=1 wildcard=0 rcode=2
192.168.100.177 (ttl=1:0:0)
......停用 DNS Session Helper
重要
- 停用 DNS Session Helper 后,FortiGate 不再从转发的 DNS 流量中维护主机名缓存和 FQDN 地址记录,DNS Proxy 需要主动向 DNS 服务器查询所需记录,这可能增加 DNS Proxy 和 DNS 服务器的负载。
- 通配符 FQDN 地址对象初始为空,需要 DNS Session Helper 从客户端 DNS 响应中学习并添加匹配的 IP 地址。使用通配符 FQDN 地址对象时不要停用对应的 DNS Session Helper。
- 删除 DNS Session Helper 不表示 DNS 查询会话可以被硬件卸载。一次常规 DNS 查询通常只有请求和响应两个数据包,不足以进入 Fast Path,因此一般仍由 CPU 处理。
执行
show system session-helper,确认需要停用的 DNS Session Helper 条目编号。使用实际条目编号删除对应配置。以下示例删除编号为
14的dns-udp条目,TCP 53 端口上的dns-tcp也使用相同方法停用。config system session-helper delete 14 end