拓撲結構:
Wan口接外網或者上級router,lan口和wlan同屬一個局域網;
配置/etc/config/wireless文件
config wifi-device 'radio0' option type 'mac80211' option path 'platform/10300000.wmac' option htmode 'HT20' option disabled '0' option txpower '0' option hwmode '11g' option channel '11' config wifi-iface 'default_radio0' option device 'radio0' option network 'lan' option mode 'ap' option encryption 'none' option ssid 'OpenWrt'
接着修改/etc/config/network文件
config interface 'loopback' option ifname 'lo' option proto 'static' option ipaddr '127.0.0.1' option netmask '255.0.0.0' config globals 'globals' option ula_prefix 'fd3d:25cc:a776::/48' config interface 'wan' option ifname 'eth0.1' option proto 'static' option ipaddr '192.168.2.238' option netmask '255.255.255.0' option gateway '192.168.2.1' option dns '114.114.114.114' config device 'wan_dev' option name 'eth0.1' option macaddr '00:0c:43:06:76:2a' config interface 'wan6' option ifname 'eth0.1' option proto 'dhcpv6' config interface 'lan' option type 'bridge' option ifname 'eth0.2' option proto 'static' option ipaddr '192.168.10.1' option netmask '255.255.255.0' option dns '114.114.114.114' config device 'lan_dev' option name 'eth0.2' option macaddr '00:0c:43:06:76:29' config switch option name 'switch0' option reset '1' option enable_vlan '1' config switch_vlan option device 'switch0' option vlan '1' option ports '0 6t' config switch_vlan option device 'switch0' option vlan '2' option ports '1 2 3 4 6t'
然后重啟network
/etc/init.d/network restart
測試發現如果開機關閉防火牆,則wifi不可訪問外網,需要打開防火牆,在rc.local內加入開機啟動防火牆
/etc/init.d/firewall start & exit 0
如果打開防火牆后外網還是無法訪問,可以修改防火牆規則 /etc/config/firewall
config zone option name lan list network 'lan' option input ACCEPT option output ACCEPT option forward ACCEPT config zone option name wan list network 'wan' list network 'wan6' option input REJECT option output ACCEPT option forward REJECT option masq 1 option mtu_fix 1 config forwarding option src lan option dest wan
增加以上紅色部分,使lan口數據可以轉發到WAN口,不過這項在openwrt應該是默認配置好的,所以正常情況防火牆規則是不需要另外配置的;
如果上不了外網,可以查看是否獲取到網關(如下則為正常獲取到了網關):
route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface default 192.168.2.1 0.0.0.0 UG 0 0 0 eth0.1 10.10.10.0 * 255.255.255.0 U 0 0 0 br-lan 192.168.2.0 * 255.255.255.0 U 0 0 0 eth0.1 192.168.2.1 * 255.255.255.255 UH 0 0 0 eth0.1