DD-WRT中的repeater bridge联网方式,在OpenWRT中称为routed client mode masqueraded。实现原理是这样的:

OpenWRT的网络分为device => interface => network => zone这四层。device是指物理的设备,比如radio0这样的无线网卡。interface是wlan0,或者wlan0-1这样通过无线网卡驱动虚拟出来的接口。这个虚拟出来的接口可以用来做为ap,也就是提供无线,或者做为sta(station),也就是连接进已经存在的无线网络。network是OpenWRT对于interface的一个分组。比如你有eth1, eth2, eth3, eth4四个独立的有线网卡提供的interface,但是设置了一个bridge把这四个独立的interface桥接到了一起,然后它们都从属于一个network。在network上配置的是对于network内的interface怎么获取ip。zone是OpenWRT为了方便管理iptables规则建立的更高层次的抽象。zone可以包含一个或者多个network,定义了iptables规则是否要在不同zone之间做forward还是masquerade。masquerade就是所谓的NAT(NAPT),也就是用一个外网ip给多个内网客户端提供上外网的服务,每次连接都会分配一个端口用于让连接的下行流量可以映射回内网的客户端。

所以fqrouter的无线连接互联网其实就是有两个zone,一个叫lan,一个叫wan。然后设置了从lan到wan的masquerade规则,这样所有连接到lan的机器都可以通过wan NAT出去。

fuyfu-NAT1

fuyfu-NAT1

然后在lan这个zone下面有只有一个network,名字也叫lan。wan这个zone下面也只有一个network,名字叫wan。network配置(/etc/config/network)如下:

config interface ‘lan’

option ifname ‘eth0’

option type ‘bridge’

option proto ‘static’

option ipaddr ‘192.168.1.1’

option netmask ‘255.255.255.0’

config interface ‘wan’

option proto ‘dhcp’

同时由于dhcp的配置(/etc/config/dhcp)的配置中打开了lan的dhcp。所以所有连接进lan的机器都会被dhcp分配一个192.168.1.x网段的ip,而路由器自身的ip被静态设置为了192.168.1.1。wan口因为是用无线连接进上级无线的网络,所以ip是通过dhcp由上级无线分配的。

在network下面是一个或者多个interface。在我们这个例子中,lan下面的interface有两个,一个是703n的有线网口eth0,另外一个是无线名称是fqrouter-703n的无线wlan0。wan下面的interface只有一个就是连接着上级无线的wlan0-1。有线网口interface配置是与network在一起的,前面的lan network的ifname eth0就是有限网口的配置了。无线网的interface都是在/etc/config/wireless中配置的:

config wifi-device ‘radio0’

option type ‘mac80211’

option channel ‘11’

option phy ‘phy0’

option hwmode ‘11ng’

option htmode ‘HT20’

list ht_capab ‘SHORT-GI-20’

list ht_capab ‘SHORT-GI-40’

list ht_capab ‘RX-STBC1’

list ht_capab ‘DSSS_CCK-40’

option txpower ‘27’

option country ‘US’

config wifi-iface

option device ‘radio0’

option network ‘lan’

option mode ‘ap’

option ssid ‘fqrouter-703n’

option encryption ‘psk2’

option key ‘1234567891’

config wifi-iface

option network ‘wan’

option ssid ‘your-upstream-wifi’

option encryption ‘psk2’

option device ‘radio0’

option mode ‘sta’

option bssid ‘20:DC:E6:FE:0D:C0’

option key ‘your-upstream-wifi-password’

option disabled ‘0’

wifi-iface就是我们配置的无线interface。其中一个ssid是fqrouter-703n的无线interface属于network lan。另外一个ssid是你上级无线的那个无线interface属于network wan。而两个interface的device都是radio0,所以都是同一个无线设备虚拟出来的。

所以fqrouter做的无线配置界面其实就是提供了一个比Luci更简单的界面配置这两个wifi-iface。

fuyufu.com