文章介绍:近期很多小伙伴在玩VyOS,在部署的过程中遇到最多的问题就是怎么配置NAT,怎么配置接口IP,怎么配置PPPOE拨号,怎么配置DHCP,怎么配置IPv6,怎么配置防火墙等等,今天休息花一点时间整理一版,关于VyOS在家里使用,配置一个WAN口eth0用来PPPOE拨号,获取IPv4+IPv6上网,配置一个LAN口,使用桥接模式把eth1,eth2,eth3接口绑定到br0,并配置DHCP给内网终端上网使用。
一、网络拓扑
- 运营商光猫是桥接模式,不负责拨号,只提供光转电功能。
- VyOS 的 WAN 口是 eth0 口连接光猫,配置 PPPOE 拨号上网。
- VyOS 的 LAN 口是 br0,br0 绑定 eth1,eth2,eth3 并配置dhcpv4。
二、接口调优配置
set interfaces ethernet eth0 offload gro
set interfaces ethernet eth0 offload gso
set interfaces ethernet eth0 offload hw-tc-offload
set interfaces ethernet eth0 offload lro
set interfaces ethernet eth0 offload rfs
set interfaces ethernet eth0 offload rps
set interfaces ethernet eth0 offload sg
set interfaces ethernet eth0 offload tso
set interfaces ethernet eth0 ring-buffer rx '4096'
set interfaces ethernet eth0 ring-buffer tx '4096'
set interfaces ethernet eth1 offload gro
set interfaces ethernet eth1 offload gso
set interfaces ethernet eth1 offload hw-tc-offload
set interfaces ethernet eth1 offload lro
set interfaces ethernet eth1 offload rfs
set interfaces ethernet eth1 offload rps
set interfaces ethernet eth1 offload sg
set interfaces ethernet eth1 offload tso
set interfaces ethernet eth1 ring-buffer rx '4096'
set interfaces ethernet eth1 ring-buffer tx '4096'
set interfaces ethernet eth2 offload gro
set interfaces ethernet eth2 offload gso
set interfaces ethernet eth2 offload hw-tc-offload
set interfaces ethernet eth2 offload lro
set interfaces ethernet eth2 offload rfs
set interfaces ethernet eth2 offload rps
set interfaces ethernet eth2 offload sg
set interfaces ethernet eth2 offload tso
set interfaces ethernet eth2 ring-buffer rx '4096'
set interfaces ethernet eth2 ring-buffer tx '4096'
set interfaces ethernet eth3 offload gro
set interfaces ethernet eth3 offload gso
set interfaces ethernet eth3 offload hw-tc-offload
set interfaces ethernet eth3 offload lro
set interfaces ethernet eth3 offload rfs
set interfaces ethernet eth3 offload rps
set interfaces ethernet eth3 offload sg
set interfaces ethernet eth3 offload tso
set interfaces ethernet eth3 ring-buffer rx '4096'
set interfaces ethernet eth3 ring-buffer tx '4096'
一、Offload 功能配置
Offload 的核心思想:将网络协议栈的部分计算任务(如分片、合并、校验等)从 CPU 转移到网卡硬件处理,从而降低 CPU 负载并提升网络性能。
- GRO (Generic Receive Offload)
- 作用:在接收方向,将多个小数据包合并成更大的数据包,减少 CPU 处理数据包的开销。
- 适用场景:高吞吐量接收(如文件传输、视频流)。
- 注意:可能增加延迟,不适合低延迟敏感场景。
- GSO (Generic Segmentation Offload)
- 作用:在发送方向,将大数据包的分段操作延迟到网卡硬件处理,减少 CPU 分段负担。
- 适用场景:发送大量数据(如 HTTP 大文件响应)。
- 依赖:需要网卡支持 TSO/UFO 等具体协议卸载。
- hw-tc-offload (Hardware Traffic Control Offload)
- 作用:将流量分类、队列调度、限速等 QoS 任务卸载到网卡硬件。
- 典型用途:结合 TC(Traffic Control)实现硬件加速的流量整形。
- 限制:依赖网卡厂商对 eBPF 或特定 QoS 功能的支持。
- LRO (Large Receive Offload)
- 作用:类似 GRO,但更激进地合并数据包(可能跨 TCP 流)。
- 风险:可能导致协议栈异常(如 NAT 或隧道场景),建议在虚拟化或复杂网络中谨慎启用。
- RFS (Receive Flow Steer)
- 作用:根据数据流的哈希值,将中断请求定向到处理该流的 CPU 核心,提升 CPU 缓存利用率。
- 依赖:需与 RPS 配合使用,且需要内核配置支持。
- RPS (Receive Packet Steering)
- 作用:通过软件将数据包处理分散到多个 CPU 核心,提高多核系统的并行处理能力。
- 适用场景:单队列网卡在高负载下的多核负载均衡。
- SG (Scatter/Gather)
- 作用:允许网卡直接读写分散在内存中的数据块(DMA 分散/聚集),减少内存复制。
- 优势:提升大数据块(如巨帧)传输效率。
- TSO (TCP Segmentation Offload)
- 作用:由网卡将大 TCP 数据包自动分段为 MTU 兼容的大小,降低 CPU 分段压力。
- 典型用途:高速 TCP 传输(如 iSCSI、NFS)。
二、Ring Buffer 配置
set interfaces ethernet eth0 ring-buffer rx '4096'
- 作用:设置接收环形缓冲区大小为 4096。增大缓冲区可应对突发流量高峰,减少丢包。
- 代价:增加内存占用,可能引入更高延迟。
set interfaces ethernet eth0 ring-buffer tx '4096'
- 作用:设置发送环形缓冲区大小。提升网卡在拥塞时的暂存能力。
三、配置注意事项
- 硬件兼容性:并非所有网卡均支持全部卸载功能(如虚拟网卡或低端硬件)。
- 延迟敏感场景:GRO/LRO 可能增加延迟,需在吞吐量和延迟之间权衡。
- 虚拟化环境:LRO 可能导致 Guest OS 网络异常,建议禁用。
四、典型应用场景
- 高吞吐服务器:启用 GRO/GSO/TSO + 大 Ring Buffer。
- 低延迟交易系统:禁用 LRO/GRO,减小 Ring Buffer。
- 边缘路由器 QoS:启用
hw-tc-offload
实现硬件加速流量控制。
三、WAN口配置
set interfaces pppoe pppoe0 authentication password 'password'
set interfaces pppoe pppoe0 authentication username 'username'
set interfaces pppoe pppoe0 description 'ISP-WAN'
set interfaces pppoe pppoe0 dhcpv6-options pd 0 interface br0 address '1'
set interfaces pppoe pppoe0 dhcpv6-options pd 0 interface br0 sla-id '0'
set interfaces pppoe pppoe0 dhcpv6-options pd 0 length '64'
#set interfaces pppoe pppoe0 dhcpv6-options pd 0 length '56'
set interfaces pppoe pppoe0 ip adjust-mss 'clamp-mss-to-pmtu'
set interfaces pppoe pppoe0 ipv6 address autoconf
set interfaces pppoe pppoe0 ipv6 adjust-mss 'clamp-mss-to-pmtu'
set interfaces pppoe pppoe0 mtu '1492'
set interfaces pppoe pppoe0 source-interface 'eth0'
一、基础 PPPoE 拨号配置
- 认证信息
set interfaces pppoe pppoe0 authentication password 'password'
set interfaces pppoe pppoe0 authentication username 'username'
- 作用:设置 PPPoE 拨号所需的用户名和密码(由 ISP 提供)。
- 接口描述
set interfaces pppoe pppoe0 description 'ISP-WAN'
- 作用:为接口添加注释,标记为互联网服务提供商(ISP)的广域网接口,便于管理。
- 源接口绑定
set interfaces pppoe pppoe0 source-interface 'eth0'
- 作用:指定 PPPoE 拨号使用的物理接口(
eth0
需连接到 ISP 调制解调器或光纤终端)。
- MTU 设置
set interfaces pppoe pppoe0 mtu '1492'
- 作用:设置 PPPoE 接口的 MTU(最大传输单元)为 1492 字节(默认以太网 MTU 1500 减去 PPPoE 头部 8 字节)。
- 必要性:避免因 MTU 不匹配导致的数据包分片或丢弃。
二、TCP/IP 优化配置
- MSS 钳制(IPv4/IPv6)
set interfaces pppoe pppoe0 ip adjust-mss 'clamp-mss-to-pmtu'
set interfaces pppoe pppoe0 ipv6 adjust-mss 'clamp-mss-to-pmtu'
- 作用:自动调整 TCP 协议的 最大报文段长度(MSS),使其适配 PPPoE 的 MTU。
- 意义:防止 TCP 握手时协商的 MSS 超过实际路径 MTU(PMTU),避免数据分片和性能下降。
- 典型值:MSS = MTU - 40(IPv4)或 60(IPv6)字节头部。
三、IPv6 配置
- IPv6 地址自动获取
set interfaces pppoe pppoe0 ipv6 address autoconf
- 作用:通过 SLAAC(无状态地址自动配置)获取 IPv6 全局单播地址。
- 依赖:ISP 需支持 IPv6 并广播 RA(路由通告)消息。
- DHCPv6 前缀委派(Prefix Delegation)
set interfaces pppoe pppoe0 dhcpv6-options pd 0 interface br0 address '1'
set interfaces pppoe pppoe0 dhcpv6-options pd 0 interface br0 sla-id '0'
set interfaces pppoe pppoe0 dhcpv6-options pd 0 length '64'
- 功能解析:
pd 0
:定义一个前缀委派实例(ID 为 0)。length '64'
:向 ISP 请求的 IPv6 前缀长度(如/56
或/64
),具体是56还是64需要自行测试。interface br0
:将获取的前缀分配给内部接口br0
(桥接或 LAN 接口)。address '1'
:使用请求到的前缀的第 1 个子网(例如,若 ISP 分配前缀2001:db8::/56
,则子网为2001:db8:0:1::/64
)。sla-id '0'
:站点级聚合标识符(Site-Level Aggregation Identifier),用于子网划分。
四、配置注意事项
-
ISP 兼容性:
- 确认 ISP 支持 PPPoE 协议,且提供的认证方式为 PAP/CHAP。
- 验证 ISP 是否分配了 IPv6 前缀(DHCPv6-PD)。
-
IPv6 连通性验证:
show interfaces pppoe pppoe0 # 检查 PPPoE 状态 ping6 ipv6.google.com # 测试 IPv6 连通性
-
故障排查:
- 使用
monitor interface pppoe0
实时查看 PPPoE 连接状态。 - 检查日志:
show log | match pppoe0
- 使用
四、LAN口配置
set interfaces bridge br0 address '192.168.1.1/24'
set interfaces bridge br0 description 'LAN'
set interfaces bridge br0 member interface eth1
set interfaces bridge br0 member interface eth2
set interfaces bridge br0 member interface eth3
set interfaces bridge br0 offload gro
set interfaces bridge br0 offload gso
set interfaces bridge br0 offload hw-tc-offload
set interfaces bridge br0 offload lro
set interfaces bridge br0 offload rfs
set interfaces bridge br0 offload rps
set interfaces bridge br0 offload sg
set interfaces bridge br0 offload tso
set interfaces bridge br0 ring-buffer rx '4096'
set interfaces bridge br0 ring-buffer tx '4096'
set interfaces bridge br0 aging '300'
set interfaces bridge br0 hello-time '2'
set interfaces bridge br0 max-age '20'
set interfaces bridge br0 priority '32768'
set interfaces bridge br0 stp
一、基础桥接配置
- IP 地址分配
set interfaces bridge br0 address '192.168.1.1/24'
- 作用:指定br0的 IP 地址是:192.168.1.1/24。
- 接口描述
set interfaces bridge br0 description 'LAN'
- 作用:标记桥接接口为局域网(LAN),便于管理。
- 成员接口绑定
set interfaces bridge br0 member interface eth1
set interfaces bridge br0 member interface eth2
set interfaces bridge br0 member interface eth3
- 作用:将物理接口
eth1
、eth2
、eth3
加入桥接组br0
,实现二层交换功能。 - 典型用途:将多个物理接口合并为一个逻辑接口,用于连接交换机、AP 或其他设备。
二、生成树协议(STP)配置
- 基础参数
set interfaces bridge br0 aging '300'
set interfaces bridge br0 hello-time '2'
set interfaces bridge br0 max-age '20'
set interfaces bridge br0 priority '32768'
set interfaces bridge br0 stp
- 功能解析:
stp
:启用 IEEE 802.1D 生成树协议,防止网络环路。aging 300
:MAC 地址表老化时间为 300 秒(默认 300)。hello-time 2
:每隔 2 秒发送 BPDU 协议报文。max-age 20
:BPDU 报文的最大存活时间为 20 秒(超时后重新计算拓扑)。priority 32768
:桥接优先级为 32768(默认值),数值越小优先级越高。
- 典型用途:在多桥接设备(如多个交换机)的网络中避免环路。
五、SNAT配置
set nat source rule 100 outbound-interface name 'pppoe0'
set nat source rule 100 source address '192.168.1.0/24'
set nat source rule 100 translation address 'masquerade'
一、指定出接口
- 定义规则编号与出站接口
set nat source rule 100 outbound-interface name 'pppoe0'
- 作用:
rule 100
:定义 NAT 规则的优先级(数值越小优先级越高)。outbound-interface name 'pppoe0'
:指定该规则仅作用于从pppoe0
接口出站的流量(即 PPPoE 拨号获得的公网接口)。
- 匹配源地址范围
set nat source rule 100 source address '192.168.1.0/24'
- 作用:
匹配来自内网192.168.1.0/24
网段的所有流量(如 LAN 设备),仅对这些流量执行 NAT 转换。
- 启用动态地址伪装
set nat source rule 100 translation address 'masquerade'
- 作用:
将匹配流量的源 IP 地址动态伪装为pppoe0
接口的公网 IP 地址,实现 源地址转换(SNAT)。- 动态适配:
masquerade
自动识别pppoe0
接口的当前公网 IP(适用于动态 IP 环境,如 PPPoE 拨号场景)。 - 端口复用:通过 PAT(端口地址转换)允许多个内网设备共享单一公网 IP。
- 动态适配:
二、查看详情
- 验证命令:
show nat source translations detail # 查看源地址转换(SNAT/Masquerade)的活跃会话详情 show nat destination translations detail # 查看目的地址转换(DNAT/端口转发)的活跃会话详情
六、DHCPv4配置
set service dhcp-server dynamic-dns-update
set service dhcp-server hostfile-update
set service dhcp-server listen-interface 'br0'
set service dhcp-server shared-network-name br0 authoritative
set service dhcp-server shared-network-name br0 option ntp-server '192.168.1.1'
set service dhcp-server shared-network-name br0 option time-zone 'Asia/Shanghai'
set service dhcp-server shared-network-name br0 subnet 192.168.1.0/24 lease '86400'
set service dhcp-server shared-network-name br0 subnet 192.168.1.0/24 option default-router '192.168.1.1'
set service dhcp-server shared-network-name br0 subnet 192.168.1.0/24 option name-server '192.168.1.1'
set service dhcp-server shared-network-name br0 subnet 192.168.1.0/24 range 100 start '192.168.1.100'
set service dhcp-server shared-network-name br0 subnet 192.168.1.0/24 range 100 stop '192.168.1.200
一、基础服务配置
- 动态 DNS 更新
set service dhcp-server dynamic-dns-update
- 作用:允许 DHCP 服务器在客户端获取 IP 后,自动更新 DNS 记录(如将主机名映射到分配的 IP)。
- 依赖:需 DNS 服务器(如 BIND)支持动态更新,并配置 TSIG 密钥认证。
- 主机文件更新
set service dhcp-server hostfile-update
- 作用:将 DHCP 分配的 IP 与主机名写入本地
/etc/hosts
文件,实现局域网内主机名解析。 - 限制:仅影响 VyOS 路由器自身,不广播到其他设备。
- 监听接口
set service dhcp-server listen-interface 'br0'
- 作用:限制 DHCP 服务仅在桥接接口
br0
上响应请求,防止意外干扰其他网络接口。 - 必要性:确保 DHCP 服务仅在内网(LAN)提供,避免 WAN 接口暴露服务。
二、共享网络定义
- 权威模式
set service dhcp-server shared-network-name br0 authoritative
- 作用:声明此 DHCP 服务器为
br0
网络的唯一权威服务器,可强制回收非法分配的 IP 并响应 DHCP 请求。 - 场景:防止网络中其他 DHCP 服务器(如错误配置的设备)造成 IP 冲突。
- 全局选项
set service dhcp-server shared-network-name br0 option ntp-server '192.168.1.1'
set service dhcp-server shared-network-name br0 option time-zone 'Asia/Shanghai'
- 功能:
- NTP 服务器:为客户端指定时间同步服务器(通常指向路由器自身或公共 NTP)。
- 时区:向客户端传递时区信息(部分操作系统支持自动配置时区)。
三、子网配置
- 子网范围与租期
set service dhcp-server shared-network-name br0 subnet 192.168.1.0/24 lease '86400'
- 作用:定义 DHCP 作用域为
192.168.1.0/24
,租期 24 小时(86400 秒)。 - 租期建议:
- 长租期:适合设备数量少且稳定的网络(如家庭)。
- 短租期:适合 IP 紧张或设备频繁变动的环境(如公共 Wi-Fi)。
- 关键网络参数
set service dhcp-server shared-network-name br0 subnet 192.168.1.0/24 option default-router '192.168.1.1'
set service dhcp-server shared-network-name br0 subnet 192.168.1.0/24 option name-server '192.168.1.1'
- 功能:
- 默认网关:客户端流量通过
192.168.1.1
(通常为路由器 LAN 接口)路由。 - DNS 服务器:客户端使用
192.168.1.1
解析域名(需路由器运行 DNS 转发或独立 DNS 服务)。
- 默认网关:客户端流量通过
- IP 地址池
set service dhcp-server shared-network-name br0 subnet 192.168.1.0/24 range 100 start '192.168.1.100'
set service dhcp-server shared-network-name br0 subnet 192.168.1.0/24 range 100 stop '192.168.1.200'
- 作用:分配从
192.168.1.100
到192.168.1.200
的 IP 地址(共 101 个可用地址)。 - 保留地址:
192.168.1.1
:通常预留给路由器 LAN 接口。192.168.1.255
:广播地址(不可分配)。
四、验证命令
show dhcp server statistics # 查看 DHCP 服务状态
show dhcp server leases # 查看已分配的 IP 租约
show dhcp server dynamic-dns updates # 检查动态 DNS 更新记录
七、IP MAC 绑定
set service dhcp-server shared-network-name br0 subnet 192.168.1.0/24 static-mapping oppo ip-address 192.168.1.66
set service dhcp-server shared-network-name br0 subnet 192.168.1.0/24 static-mapping oppo mac-address 11:22:33:44:55:66
set service dhcp-server shared-network-name br0 subnet 192.168.1.0/24 static-mapping oppo option routers 192.168.1.254
set service dhcp-server shared-network-name br0 subnet 192.168.1.0/24 static-mapping oppo option domain-name-servers 192.168.1.254
-
set service dhcp-server shared-network-name br0 subnet 192.168.1.0/24 static-mapping oppo ip-address 192.168.1.66
- 这条命令为
oppo
设备配置了静态 IP 地址192.168.1.66
。 - 这个 IP 地址将分配给 MAC 地址为
11:22:33:44:55:66
的设备。
- 这条命令为
-
set service dhcp-server shared-network-name br0 subnet 192.168.1.0/24 static-mapping oppo mac-address 11:22:33:44:55:66
- 这条命令为设备
oppo
配置了 MAC 地址11:22:33:44:55:66
。 - 这使得设备
oppo
每次请求 DHCP 地址时,都会根据这个 MAC 地址获得相同的 IP 地址,即192.168.1.66
。
- 这条命令为设备
-
set service dhcp-server shared-network-name br0 subnet 192.168.1.0/24 static-mapping oppo option routers 192.168.1.254
- 这条命令为设备
oppo
设置了 DHCP 选项:默认网关(路由器)为192.168.1.254
。 - 这个网关将会被分配给设备
oppo
。
- 这条命令为设备
-
set service dhcp-server shared-network-name br0 subnet 192.168.1.0/24 static-mapping oppo option domain-name-servers 192.168.1.254
- 这条命令为设备
oppo
设置了 DHCP 选项:DNS 服务器为192.168.1.254
。 - 这个 DNS 服务器将会被分配给设备
oppo
,设备将使用该 DNS 服务器进行域名解析。
- 这条命令为设备
八、IPv6路由通告(RA)配置
set service router-advert interface br0 link-mtu '1490'
set service router-advert interface br0 prefix ::/64 valid-lifetime '172800'
set service router-advert interface pppoe0
-
set service router-advert interface br0 link-mtu '1490'
- 在接口
br0
的 RA(路由器通告)中声明链路 MTU 值为 1490 字节,供客户端自动配置 IPv6 MTU。
- 在接口
-
set service router-advert interface br0 prefix ::/64 valid-lifetime '172800'
- 通过 RA 向客户端通告 IPv6 前缀 ::/64,并设置该前缀的有效生命周期为 172800 秒(2天)。
-
set service router-advert interface pppoe0
- 在接口
pppoe0
上启用路由器通告服务(需结合其他参数配置 IPv6 前缀或参数)。
- 在接口
九、系统DNS配置
set service dns forwarding allow-from '192.168.1.0/24'
set service dns forwarding cache-size '10000'
set service dns forwarding dnssec 'off'
set service dns forwarding listen-address '192.168.1.1'
set service dns forwarding name-server 223.6.6.6
set service dns forwarding name-server 223.5.5.5
set service dns forwarding no-serve-rfc1918
set service dns forwarding system
set service dns forwarding allow-from '192.168.1.0/24'
允许来自192.168.1.0/24
网络的客户端使用 DNS 转发服务。set service dns forwarding cache-size '10000'
设置 DNS 查询缓存大小为 10000 条记录。set service dns forwarding dnssec 'off'
关闭 DNSSEC 验证功能。set service dns forwarding listen-address '192.168.1.1'
在本地地址192.168.1.1
上监听 DNS 请求。set service dns forwarding name-server 223.6.6.6
设置上游 DNS 服务器为223.6.6.6
(阿里公共 DNS)。set service dns forwarding name-server 223.5.5.5
设置另一个上游 DNS 服务器为223.5.5.5
(阿里公共 DNS)。set service dns forwarding no-serve-rfc1918
拒绝解析RFC1918
私有地址段的 DNS 查询请求。set service dns forwarding system
使用系统默认的 DNS 设置作为备用上游解析器。
十、系统NTP配置
set service ntp allow-client address '127.0.0.0/8'
set service ntp allow-client address '169.254.0.0/16'
set service ntp allow-client address '10.0.0.0/8'
set service ntp allow-client address '172.16.0.0/12'
set service ntp allow-client address '192.168.0.0/16'
set service ntp allow-client address '::1/128'
set service ntp allow-client address 'fe80::/10'
set service ntp server ntp.aliyun.com
set service ntp server ntp.tencent.com
set service ntp allow-client address '127.0.0.0/8'
允许本地回环地址段的客户端访问 NTP 服务。set service ntp allow-client address '169.254.0.0/16'
允许链路本地地址段的客户端访问 NTP 服务。set service ntp allow-client address '10.0.0.0/8'
允许私有网络段10.0.0.0/8
的客户端访问 NTP 服务。set service ntp allow-client address '172.16.0.0/12'
允许私有网络段172.16.0.0/12
的客户端访问 NTP 服务。set service ntp allow-client address '192.168.0.0/16'
允许私有网络段192.168.0.0/16
的客户端访问 NTP 服务。set service ntp allow-client address '::1/128'
允许 IPv6 回环地址的客户端访问 NTP 服务。set service ntp allow-client address 'fe80::/10'
允许 IPv6 链路本地地址段的客户端访问 NTP 服务。set service ntp server ntp.aliyun.com
设置阿里云的 NTP 服务器为时间同步源。set service ntp server ntp.tencent.com
设置腾讯云的 NTP 服务器为时间同步源。
十一、防火墙配置
11.1、全局配置
set firewall global-options all-ping 'enable'
set firewall global-options broadcast-ping 'disable'
set firewall global-options ip-src-route 'disable'
set firewall global-options ipv6-receive-redirects 'disable'
set firewall global-options ipv6-src-route 'disable'
set firewall global-options log-martians 'enable'
set firewall global-options receive-redirects 'disable'
set firewall global-options send-redirects 'enable'
set firewall global-options source-validation 'disable'
set firewall global-options syn-cookies 'enable'
set firewall global-options twa-hazards-protection 'disable'
set firewall global-options all-ping 'enable'
允许响应所有接口上的 ICMP Echo 请求(ping)。set firewall global-options broadcast-ping 'disable'
禁止响应广播地址的 ping 请求,防止 Smurf 攻击。set firewall global-options ip-src-route 'disable'
禁用 IPv4 源路由功能,防止绕过正常路由路径。set firewall global-options ipv6-receive-redirects 'disable'
禁用接收 IPv6 重定向报文,防止中间人攻击。set firewall global-options ipv6-src-route 'disable'
禁用 IPv6 源路由功能,提高安全性。set firewall global-options log-martians 'enable'
记录来自非法或不可路由地址(Martians)的包。set firewall global-options receive-redirects 'disable'
禁用接收 IPv4 ICMP 重定向,防止篡改路由。set firewall global-options send-redirects 'enable'
允许发送 ICMP 重定向,适用于需要引导客户端更优路径的场景。set firewall global-options source-validation 'disable'
禁用反向路径源地址验证。set firewall global-options syn-cookies 'enable'
启用 SYN cookies,防止 SYN Flood 攻击。set firewall global-options twa-hazards-protection 'disable'
禁用 TCP 窗口调整相关的安全防护机制(适用于高性能或特定应用环境)。
11.2、IPv4防火墙配置
set firewall ipv4 name LAN-LOCAL default-action 'accept'
set firewall ipv4 name LAN-WAN default-action 'accept'
set firewall ipv4 name LOCAL-LAN default-action 'accept'
set firewall ipv4 name LOCAL-WAN default-action 'accept'
set firewall ipv4 name WAN-LAN default-action 'drop'
set firewall ipv4 name WAN-LAN rule 10 action 'accept'
set firewall ipv4 name WAN-LAN rule 10 state 'established'
set firewall ipv4 name WAN-LAN rule 10 state 'related'
set firewall ipv4 name WAN-LAN rule 100 action 'accept'
set firewall ipv4 name WAN-LAN rule 100 destination address '192.168.1.0/24'
set firewall ipv4 name WAN-LAN rule 100 log
set firewall ipv4 name WAN-LAN rule 100 protocol 'tcp_udp'
set firewall ipv4 name WAN-LOCAL default-action 'drop'
set firewall ipv4 name WAN-LOCAL rule 10 action 'accept'
set firewall ipv4 name WAN-LOCAL rule 10 state 'established'
set firewall ipv4 name WAN-LOCAL rule 10 state 'related'
set firewall ipv4 name WAN-LOCAL rule 100 action 'accept'
set firewall ipv4 name WAN-LOCAL rule 100 protocol 'icmp'
set firewall ipv4 name LAN-LOCAL default-action 'accept'
允许 LAN 到本地系统的所有 IPv4 流量。set firewall ipv4 name LAN-WAN default-action 'accept'
允许 LAN 到 WAN 的所有 IPv4 流量。set firewall ipv4 name LOCAL-LAN default-action 'accept'
允许本地系统到 LAN 的所有 IPv4 流量。set firewall ipv4 name LOCAL-WAN default-action 'accept'
允许本地系统到 WAN 的所有 IPv4 流量。set firewall ipv4 name WAN-LAN default-action 'drop'
默认丢弃来自 WAN 到 LAN 的 IPv4 流量。set firewall ipv4 name WAN-LAN rule 10 action 'accept'
允许符合状态规则的流量。set firewall ipv4 name WAN-LAN rule 10 state 'established'
允许已建立连接的流量。set firewall ipv4 name WAN-LAN rule 10 state 'related'
允许与现有连接相关的流量。set firewall ipv4 name WAN-LAN rule 100 action 'accept'
允许特定流量进入 LAN。set firewall ipv4 name WAN-LAN rule 100 destination address '192.168.1.0/24'
指定允许的目标地址段为192.168.1.0/24
。set firewall ipv4 name WAN-LAN rule 100 log
记录该规则匹配到的流量日志。set firewall ipv4 name WAN-LAN rule 100 protocol 'tcp_udp'
规则适用于 TCP 和 UDP 协议。set firewall ipv4 name WAN-LOCAL default-action 'drop'
默认丢弃来自 WAN 到本地系统的 IPv4 流量。set firewall ipv4 name WAN-LOCAL rule 10 action 'accept'
允许符合状态规则的流量。set firewall ipv4 name WAN-LOCAL rule 10 state 'established'
允许已建立连接的流量。set firewall ipv4 name WAN-LOCAL rule 10 state 'related'
允许与现有连接相关的流量。set firewall ipv4 name WAN-LOCAL rule 100 action 'accept'
允许特定协议的流量。set firewall ipv4 name WAN-LOCAL rule 100 protocol 'icmp'
允许 ICMP 协议(如 ping)从 WAN 到本地系统。
11.3、IPv6防火墙配置
set firewall ipv6 name LAN-LOCAL-6 default-action 'accept'
set firewall ipv6 name LAN-WAN-6 default-action 'accept'
set firewall ipv6 name LOCAL-LAN-6 default-action 'accept'
set firewall ipv6 name LOCAL-WAN-6 default-action 'accept'
set firewall ipv6 name WAN-LAN-6 default-action 'drop'
set firewall ipv6 name WAN-LAN-6 rule 10 action 'accept'
set firewall ipv6 name WAN-LAN-6 rule 10 state 'established'
set firewall ipv6 name WAN-LAN-6 rule 10 state 'related'
set firewall ipv6 name WAN-LOCAL-6 default-action 'drop'
set firewall ipv6 name WAN-LOCAL-6 rule 10 action 'accept'
set firewall ipv6 name WAN-LOCAL-6 rule 10 state 'related'
set firewall ipv6 name WAN-LOCAL-6 rule 10 state 'established'
set firewall ipv6 name WAN-LOCAL-6 rule 20 action 'accept'
set firewall ipv6 name WAN-LOCAL-6 rule 20 protocol 'ipv6-icmp'
set firewall ipv6 name WAN-LOCAL-6 rule 30 action 'accept'
set firewall ipv6 name WAN-LOCAL-6 rule 30 destination port '546'
set firewall ipv6 name WAN-LOCAL-6 rule 30 protocol 'udp'
set firewall ipv6 name WAN-LOCAL-6 rule 30 source port '547'
set firewall ipv6 name LAN-LOCAL-6 default-action 'accept'
允许 LAN 到本地系统的所有 IPv6 流量。set firewall ipv6 name LAN-WAN-6 default-action 'accept'
允许 LAN 到 WAN 的所有 IPv6 流量。set firewall ipv6 name LOCAL-LAN-6 default-action 'accept'
允许本地系统到 LAN 的所有 IPv6 流量。set firewall ipv6 name LOCAL-WAN-6 default-action 'accept'
允许本地系统到 WAN 的所有 IPv6 流量。set firewall ipv6 name WAN-LAN-6 default-action 'drop'
默认丢弃来自 WAN 到 LAN 的 IPv6 流量。set firewall ipv6 name WAN-LAN-6 rule 10 action 'accept'
允许符合状态规则的 IPv6 流量。set firewall ipv6 name WAN-LAN-6 rule 10 state 'established'
允许已建立的 IPv6 连接。set firewall ipv6 name WAN-LAN-6 rule 10 state 'related'
允许与现有连接相关的 IPv6 流量。set firewall ipv6 name WAN-LOCAL-6 default-action 'drop'
默认丢弃来自 WAN 到本地系统的 IPv6 流量。set firewall ipv6 name WAN-LOCAL-6 rule 10 action 'accept'
允许符合状态规则的 IPv6 流量。set firewall ipv6 name WAN-LOCAL-6 rule 10 state 'related'
允许与现有连接相关的 IPv6 流量。set firewall ipv6 name WAN-LOCAL-6 rule 10 state 'established'
允许已建立的 IPv6 连接。set firewall ipv6 name WAN-LOCAL-6 rule 20 action 'accept'
允许 IPv6 ICMP 协议流量。set firewall ipv6 name WAN-LOCAL-6 rule 20 protocol 'ipv6-icmp'
匹配 IPv6 的 ICMP 协议(如邻居发现、ping 等)。set firewall ipv6 name WAN-LOCAL-6 rule 30 action 'accept'
允许 DHCPv6 客户端请求。set firewall ipv6 name WAN-LOCAL-6 rule 30 destination port '546'
目标端口为 546(DHCPv6 客户端端口)。set firewall ipv6 name WAN-LOCAL-6 rule 30 protocol 'udp'
协议为 UDP。set firewall ipv6 name WAN-LOCAL-6 rule 30 source port '547'
源端口为 547(DHCPv6 服务器端口)。
11.4、接口调用防火墙
set firewall zone LAN from LOCAL firewall ipv6-name 'LOCAL-LAN-6'
set firewall zone LAN from LOCAL firewall name 'LOCAL-LAN'
set firewall zone LAN from WAN firewall ipv6-name 'WAN-LAN-6'
set firewall zone LAN from WAN firewall name 'WAN-LAN'
set firewall zone LAN member interface 'br0'
set firewall zone LOCAL from LAN firewall ipv6-name 'LAN-LOCAL-6'
set firewall zone LOCAL from LAN firewall name 'LAN-LOCAL'
set firewall zone LOCAL from WAN firewall ipv6-name 'WAN-LOCAL-6'
set firewall zone LOCAL from WAN firewall name 'WAN-LOCAL'
set firewall zone LOCAL local-zone
set firewall zone WAN from LAN firewall ipv6-name 'LAN-WAN-6'
set firewall zone WAN from LAN firewall name 'LAN-WAN'
set firewall zone WAN from LOCAL firewall ipv6-name 'LOCAL-WAN-6'
set firewall zone WAN from LOCAL firewall name 'LOCAL-WAN'
set firewall zone WAN member interface 'pppoe0'
区域定义与接口绑定
LAN
区域绑定接口:br0
LOCAL
区域为本地系统(local-zone)WAN
区域绑定接口:pppoe0
区域间防火墙策略(含 IPv4 和 IPv6)
LAN 来源:
- 从
LOCAL
到LAN
:- IPv4 使用规则集:
LOCAL-LAN
- IPv6 使用规则集:
LOCAL-LAN-6
- IPv4 使用规则集:
- 从
WAN
到LAN
:- IPv4 使用规则集:
WAN-LAN
- IPv6 使用规则集:
WAN-LAN-6
- IPv4 使用规则集:
LOCAL 来源:
- 从
LAN
到LOCAL
:- IPv4 使用规则集:
LAN-LOCAL
- IPv6 使用规则集:
LAN-LOCAL-6
- IPv4 使用规则集:
- 从
WAN
到LOCAL
:- IPv4 使用规则集:
WAN-LOCAL
- IPv6 使用规则集:
WAN-LOCAL-6
- IPv4 使用规则集:
WAN 来源:
- 从
LAN
到WAN
:- IPv4 使用规则集:
LAN-WAN
- IPv6 使用规则集:
LAN-WAN-6
- IPv4 使用规则集:
- 从
LOCAL
到WAN
:- IPv4 使用规则集:
LOCAL-WAN
- IPv6 使用规则集:
LOCAL-WAN-6
- IPv4 使用规则集:
十二、动态DDNS配置
12.1、cloudflare
set service dns dynamic name DDNS-CF-v4 address interface 'pppoe0'
set service dns dynamic name DDNS-CF-v4 host-name 'ddns.example.com'
set service dns dynamic name DDNS-CF-v4 ip-version 'ipv4'
set service dns dynamic name DDNS-CF-v4 password 'token'
set service dns dynamic name DDNS-CF-v4 protocol 'cloudflare'
set service dns dynamic name DDNS-CF-v4 zone 'example.com'
set service dns dynamic name DDNS-CF-v6 address interface 'pppoe0'
set service dns dynamic name DDNS-CF-v6 host-name 'ddns6.example.com'
set service dns dynamic name DDNS-CF-v6 ip-version 'ipv6'
set service dns dynamic name DDNS-CF-v6 password 'token'
set service dns dynamic name DDNS-CF-v6 protocol 'cloudflare'
set service dns dynamic name DDNS-CF-v6 zone 'example.com'
Cloudflare DDNS(IPv4 版)配置
- set service dns dynamic name DDNS-CF-v4 address interface 'pppoe0'
指定使用 pppoe0 接口上的 IPv4 地址作为 DDNS 更新时的目标地址。 - set service dns dynamic name DDNS-CF-v4 host-name 'ddns.example.com'
设置要更新的完整域名为 ddns.example.com,也就是 Cloudflare 上需要动态更新的记录名称。 - set service dns dynamic name DDNS-CF-v4 ip-version 'ipv4'
指明此 DDNS 更新使用 IPv4 地址。 - set service dns dynamic name DDNS-CF-v4 password 'token'
提供 Cloudflare API 认证的凭据(通常是 API token),用于验证 DDNS 更新请求。 - set service dns dynamic name DDNS-CF-v4 protocol 'cloudflare'
指定采用 Cloudflare 专用的 DDNS 更新协议。 - set service dns dynamic name DDNS-CF-v4 zone 'example.com'
指定该记录所属的 DNS 区域(Zone)为 example.com。
Cloudflare DDNS(IPv6 版)配置
- set service dns dynamic name DDNS-CF-v6 address interface 'pppoe0'
指定使用 pppoe0 接口上的 IPv6 地址作为 DDNS 更新时的目标地址。 - set service dns dynamic name DDNS-CF-v6 host-name 'ddns6.example.com'
设置要更新的 IPv6 记录的完整域名为 ddns6.example.com。 - set service dns dynamic name DDNS-CF-v6 ip-version 'ipv6'
指明此 DDNS 更新使用 IPv6 地址。 - set service dns dynamic name DDNS-CF-v6 password 'token'
提供 Cloudflare API 的认证 token。 - set service dns dynamic name DDNS-CF-v6 protocol 'cloudflare'
采用 Cloudflare 协议更新 IPv6 记录。 - set service dns dynamic name DDNS-CF-v6 zone 'example.com'
指定该记录所属的 DNS 区域为 example.com。
12.2、dnspod
set service dns dynamic name DNSPOD-v4 address interface 'pppoe0'
set service dns dynamic name DNSPOD-v4 host-name 'ddns.example.com'
set service dns dynamic name DNSPOD-v4 password 'token'
set service dns dynamic name DNSPOD-v4 protocol 'dyndns2'
set service dns dynamic name DNSPOD-v4 server 'dnsapi.cn'
set service dns dynamic name DNSPOD-v4 username 'id'
DNSPOD DDNS(IPv4 版)配置
- set service dns dynamic name DNSPOD-v4 address interface 'pppoe0'
指定使用 pppoe0 接口上的 IPv4 地址用于 DNSPOD 的 DDNS 更新。 - set service dns dynamic name DNSPOD-v4 host-name 'ddns.example.com'
设置要更新的域名为 ddns.example.com。 - set service dns dynamic name DNSPOD-v4 password 'token'
设置认证密码或令牌,此处用于 DNSPOD 的身份验证。 - set service dns dynamic name DNSPOD-v4 protocol 'dyndns2'
指定使用 dyndns2 协议(常见的 DDNS 协议)进行更新。 - set service dns dynamic name DNSPOD-v4 server 'dnsapi.cn'
指定 DNSPOD 的 DDNS 更新服务器地址为 dnsapi.cn。 - set service dns dynamic name DNSPOD-v4 username 'id'
指定用于认证的用户名(通常为账户 ID),配合密码一起完成身份验证。