OpenWRT实现有线+WiFi的STA模式双WAN叠加
本文系转载,原文作者LvSin
配置/etc/config/network文件- <font color="#000000">config switch 'eth1'
- option reset '0'
- option enable_vlan '0'
- config interface 'loopback'
- option ifname 'lo'
- option proto 'static'
- option ipaddr '127.0.0.1'
- option netmask '255.0.0.0'
- config interface 'lan'
- option ifname 'eth1'
- option proto 'static'
- option ipaddr '192.168.6.1'
- option netmask '255.255.255.0'
- config interface 'wan0'
- option ifname 'wlan0'
- option proto 'dhcp'
- config interface 'wan1'
- option ifname 'eth0'
- option proto 'dhcp'
- option ifname eth0
- option proto dhcp</font>
复制代码 注意:wan0与wan1的配置,ifname的值要对应准确,此处interface的编号要被dhcp、wireless配置文件所使用。
配置/etc/config/dhcp 实现wan0、wan1自动dhcp获取IP地址功能- <font color="#000000">config dnsmasq
- option domainneeded '1'
- option boguspriv '1'
- option filterwin2k '0'
- option localise_queries '1'
- option rebind_protection '1'
- option rebind_localhost '1'
- option local '/lan/'
- option domain 'lan'
- option expandhosts '1'
- option nonegcache '0'
- option authoritative '1'
- option readethers '1'
- option leasefile '/tmp/dhcp.leases'
- option resolvfile '/tmp/resolv.conf.auto'
- config dhcp 'lan'
- option interface 'lan'
- option start '100'
- option limit '150'
- option leasetime '12h'
- option dhcpv6 'server'
- option ra 'server'
- config dhcp 'wan0'
- option interface 'wan0'
- option ignore '1'
- config dhcp 'wan1'
- option interface 'wan1'
- option ignore '1'
- config odhcpd 'odhcpd'
- option maindhcp '0'
- option leasefile '/tmp/hosts/odhcpd'
- option leasetrigger '/usr/sbin/odhcpd-update'</font>
复制代码 配置/etc/config/wireless- <font color="#000000">config wifi-device 'radio0'
- option type 'mac80211'
- option channel '0'
- option hwmode '11g'
- option path 'platform/ar933x_wmac'
- option htmode 'HT20'
- config wifi-iface
- option device 'radio0'
- option network 'wan0'
- option mode 'sta'
- option ssid 'wifi名称'
- option encryption 'psk2'
- option key 'wifi密码'</font>
复制代码 注意:option network的值要与/etc/config/network中的interface编号对应。
配置/etc/config/firewall- <font color="#000000">config defaults
- option syn_flood '1'
- option input 'ACCEPT'
- option output 'ACCEPT'
- option forward 'REJECT'
- config zone
- option name 'lan'
- option network 'lan'
- option input 'ACCEPT'
- option output 'ACCEPT'
- option forward 'ACCEPT'
- config zone
- option name 'wan'
- list network 'wan0'
- list network 'wan1'
- list network 'wan6'
- option input 'ACCEPT'
- option output 'ACCEPT'
- option forward 'ACCEPT'
- option masq '1'
- option mtu_fix '1'
- config forwarding
- option src 'lan'
- option dest 'wan'
- config rule
- option name 'Allow-DHCP-Renew'
- option src 'wan'
- option proto 'udp'
- option dest_port '68'
- option target 'ACCEPT'
- option family 'ipv4'
- config rule
- option name 'Allow-Ping'
- option src 'wan0'
- option proto 'icmp'
- option icmp_type 'echo-request'
- option family 'ipv4'
- option target 'ACCEPT'
- config rule
- option name 'Allow-DHCPv6'
- option src 'wan'
- option proto 'udp'
- option src_ip 'fe80::/10'
- option src_port '547'
- option dest_ip 'fe80::/10'
- option dest_port '546'
- option family 'ipv6'
- option target 'ACCEPT'
- config rule
- option name 'Allow-ICMPv6-Input'
- option src 'wan0'
- option proto 'icmp'
- option icmp_type 'echo-request echo-reply destination-unreachable packet-too-big time-exceeded bad-header unknown-header-type router-solicitation neighbout'
- option limit '1000/sec'
- option family 'ipv6'
- option target 'ACCEPT'
- config rule
- option name 'Allow-ICMPv6-Forward'
- option src 'wan'
- option dest '*'
- option proto 'icmp'
- option icmp_type 'echo-request echo-reply destination-unreachable packet-too-big time-exceeded bad-header unknown-header-type'
- option limit '1000/sec'
- option family 'ipv6'
- option target 'ACCEPT'
- config include
- option path '/etc/firewall.user'</font>
复制代码 一键配置脚本代码示例
所有的配置操作均使用OpenWRT系统提供的uci命令,也是OpenWRT开发中比较正统的操作方法,当然也并不局限于此,如果不怕麻烦的话,直接修改配置文件也能达到同样效果。 |