配置 Session TTL
2025/10/29大约 2 分钟
配置 Session TTL
功能介绍
- 会话生存时间,即会话建立后无任何数据传送情况下的存活时间,默认为 3600 秒,当该会话在超时之前有任何数据匹配该会话,则该会话 ttl 计时器复位到该数值,如 3600 秒。有的服务如数据库。需要长连接,尽可能能将其 TCP 的会话超时时间设置得较大。
- session-ttl 配置有 4 种不同的类型,分为全局 session-ttl 、全局自定义的 session-ttl、策略 session-ttl 、服务对象 session-ttl。session-ttl 必须在 CLI 下配置。
重要
配置 session-ttl 时间只对状态为“已建立”的会话 TTL 时间生效。
配置方法
配置全局 session-ttl。
config system session-ttl set default 3600 //TCP会话的老化时间,300-2764800秒(最大为32天),默认为3600s end config system global set udp-idle-timer 180 //UDP会话的老化时间,1-86400秒(最大为1天),默认为180s end全局自定义 session-ttl,可自由定义协议、端口与会话超时时间。
config system session-ttl config port edit 1 set protocol 6 set timeout 86400 set start-port 5000 set end-port 5000 next edit 2 set protocol 17 set timeout 360 set start-port 4500 set end-port 4500 next edit 3 set protocol 1 set timeout 60 next end end基于策略的 session-ttl,针对匹配该策略的所有协议的会话生效。
config firewall policy edit 1 set srcintf lan set dstintf wan1 set srcaddr all set dstaddr all set action accept set schedule always set service ANY set session-ttl 604800 //针对匹配该策略的所有协议/端口的会话生效 set nat enable next end基于服务对象的 session-ttl,定义不同的对象,虽然同为 23 端口,可以配置指定不同协议的 session-ttl 时间,被策略引用后才会生效。
config firewall service custom edit telnet set protocol TCP set tcp-portrange 23 set session-ttl 7200 next edit "telnetnew" set protocol UDP set tcp-portrange 23 set session-ttl 3600 next end
Session TTL 优先级
全局 session-ttl(低)< 全局自定义 session-ttl < 策略 session-ttl < 被策略引用的服务对象 session-ttl(高)。优先级高的 session-ttl 优先被使用。