概述
本文介紹瞭如何創建防火牆規則來保護路由器和局域網(LAN)。本文創建的規則也可以通過運行“ Basic Setup”嚮導來自動創建。
添加防火牆規則
EdgeRouter 使用 stateful 防火牆,這意味著路由器防火牆規則可以在不同的連接狀態上匹配。流量狀態為:
new
傳入未知的數據包。established
傳入的數據包已建立連接。related
傳入的數據包是未知的,但與源已建立連接。invalid
傳入的數據包與其他狀態都不匹配。
使用這些防火牆狀態,路由器可以根據連接狀態沿不同方向接收/丟棄流量。例如,路由器可以阻止從 WAN 到 LAN 的所有流量,除非它是與現有連接有關的返回流量。EdgeOS 中的 Basic Setup 嚮導將以下防火牆規則添加到路由器:
WAN_IN
匹配通過路由器(WAN 到 LAN)傳遞的已建立/相關的無效流量。WAN_LOCAL
匹配目的為路由器本身的已建立和無效流量(WAN 到 LOCAL)。
請按照以下步驟從“ Basic Setup:” 嚮導手動創建防火牆策略:
1.打開 Firewall/NAT 選項卡。
2.添加 WAN_IN 防火牆策略,並將默認操作設置為 drop。
Firewall/NAT > Firewall Policies > + Add Ruleset
Name: WAN_IN //填寫規則名字
Description: WAN to internal //對規則的備註
Default action: Drop //將默認操作設置為 drop
- 將兩個規則添加到新創建的防火牆策略中。
Firewall/NAT > Firewall Policies > WAN_IN > Actions > Edit Ruleset > + Add New Rule
Description: Allow established/related //對規則的備註,允許建立
Action: Accept //設置操作為允許
Protocol: All protocols //設置對象為所有協議
Advanced > State: Established / Related //設置狀態為已建立
Firewall/NAT > Firewall Policies > WAN_IN > Actions > Edit Ruleset > + Add New Rule
Description: Drop invalid state //對規則的備註,阻止
Action: Drop //設置操作為阻止
Protocol: All protocols //設置對象為所有協議
Advanced > State: Invalid //設置狀態為無效
- 在 in 將防火牆策略附加到 WAN 接口。
Firewall/NAT > Firewall Policies > WAN_IN > Actions > Interfaces
Interface: eth0 //設置接口為 eth0
Direction: in //對規則解釋,為 in
- 添加 WAN_LOCAL 防火牆策略,並將默認操作設置為 drop。
Firewall/NAT > Firewall Policies > + Add Ruleset
Name: WAN_LOCAL //填寫規則名字
Description: WAN to router //對規則的備註
Default action: Drop //將默認操作設置為阻止
5.將兩個規則添加到新創建的防火牆策略中。
Firewall/NAT > Firewall Policies > WAN_LOCAL > Actions > Edit Ruleset > + Add New Rule
Description: Allow established/related //對規則的備註,允許建立
Action: Accept //設置操作為允許
Protocol: All protocols //設置對象為所有協議
Advanced > State: Established / Related //設置狀態為已建立
Firewall/NAT > Firewall Policies > WAN_LOCAL > Actions > Edit Ruleset > + Add New Rule
Description: Drop invalid state //對規則的備註,阻止
Action: Drop //設置操作為阻止
Protocol: All protocols //設置對象為所有協議
Advanced > State: Invalid //設置狀態為無效
6.在 LOCAL 方向上將防火牆策略附加到 WAN 接口。
Firewall/NAT > Firewall Policies > WAN_LOCAL > Actions > Interfaces
Interface: eth0 //設置接口為 eth0
Direction: local //對規則解釋,為 local
也可以使用 CLI 設置以上配置:
1.進入配置模式。
configure
2.配置 WAN_IN 防火牆策略。
set firewall name WAN_IN default-action drop
set firewall name WAN_IN description 'WAN to internal'
//建立 wan in 規則,並對其添加備註
set firewall name WAN_IN rule 10 action accept
set firewall name WAN_IN rule 10 description 'Allow established/related'
set firewall name WAN_IN rule 10 state established enable
set firewall name WAN_IN rule 10 state related enable
//建立規則 10 放行所以協議流量
set firewall name WAN_IN rule 20 action drop
set firewall name WAN_IN rule 20 description 'Drop invalid state'
set firewall name WAN_IN rule 20 state invalid enable
//建立規則 20 阻止流量
3.配置 WAN_LOCAL 防火牆策略。
set firewall name WAN_LOCAL default-action drop
set firewall name WAN_LOCAL description 'WAN to router'
//建立 wan local 規則,並對其添加備註
set firewall name WAN_LOCAL rule 10 action accept
set firewall name WAN_LOCAL rule 10 description 'Allow established/related'
set firewall name WAN_LOCAL rule 10 state established enable
set firewall name WAN_LOCAL rule 10 state related enable
//建立規則 10 放行所以協議流量
set firewall name WAN_LOCAL rule 20 action drop
set firewall name WAN_LOCAL rule 20 description 'Drop invalid state'
set firewall name WAN_LOCAL rule 20 state invalid enable
//建立規則 20 阻止流量
4.在 inbound 和 local 上將防火牆策略添加到 WAN 接口。
set interfaces ethernet eth0 firewall in name WAN_IN
set interfaces ethernet eth0 firewall local name WAN_LOCAL
5.提交更改並保存配置。
commit ; save
完整的 CLI 配置如下:
configure
set firewall name WAN_IN default-action drop
set firewall name WAN_IN description 'WAN to internal'
set firewall name WAN_IN rule 10 action accept
set firewall name WAN_IN rule 10 description 'Allow established/related'
set firewall name WAN_IN rule 10 state established enable
set firewall name WAN_IN rule 10 state related enable
set firewall name WAN_IN rule 20 action drop
set firewall name WAN_IN rule 20 description 'Drop invalid state'
set firewall name WAN_IN rule 20 state invalid enable
set firewall name WAN_LOCAL default-action drop
set firewall name WAN_LOCAL description 'WAN to router'
set firewall name WAN_LOCAL rule 10 action accept
set firewall name WAN_LOCAL rule 10 description 'Allow established/related'
set firewall name WAN_LOCAL rule 10 state established enable
set firewall name WAN_LOCAL rule 10 state related enable
set firewall name WAN_LOCAL rule 20 action drop
set firewall name WAN_LOCAL rule 20 description 'Drop invalid state'
set firewall name WAN_LOCAL rule 20 state invalid enable
set interfaces ethernet eth0 firewall in name WAN_IN
set interfaces ethernet eth0 firewall local name WAN_LOCAL
commit ; save