openwrt 中使用uci 設定防火牆規則 1
阿新 • • 發佈:2019-01-09
openwrt 使用 uci 軟體實現對系統的配置。
UCI的配置檔案全部儲存在/etc/config目錄下。
需要記住。使用 uci 設定後,必須呼叫
uci commit firewall
配置才會生效
root@OpenWrt:/# ls /etc/config/
dhcp dropbear firewall network system wireless
更多內容請參考 : http://ingchuang.com/article/217
本文著重講解防火牆設定。
防火牆的配置檔案位於 /etc/config/firewall
例如。我們要讓自己能ping到別人。但是讓別人ping不通自己
對於ping這個協議,進來的為8(ping),出去的為0(響應).
由於openwrt的防火牆預設是全堵我們為了達到目的,需要禁止8進來
所以。我們需要在 firewall 檔案中新增加這樣的一條規則:
config rule 'myrule'
option name 'ping'
option proto 'icmp'
option dest_port '8'
option src '*'
option target 'REJECT'
使用 uci 命令,則應當做如下操作
#增加節點
uci set firewall.myrule=rule
uci set firewall.myrule.name=ping
uci set firewall.myrule.proto=icmp
uci set firewall.myrule .dest_port=8
uci set firewall.myrule.target=REJECT
uci set firewall.myrule.src=*
uci commit firewall
/etc/init.d/firewall restart