天天看點

openwrt 中使用uci 設定防火牆規則 1

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 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      

繼續閱讀