如何修改Openwrt 默认配置将AP改成AP+STA模式

      Openwrt 灵活的配置,可以将其改变配置变成AP+STA模式(即无线中继模式),并通过连接上行路由器,使STA连接该设备AP就能直接上网。

中继组网模式:

如何修改Openwrt 默认配置将AP改成AP+STA模式_第1张图片

所有修改都在如下红色部分

修改文件列表:

  • /etc/config/network
  • /etc/config/wireless
  • /etc/config/dhcp
  • /etc/config/firewall

 

第一步:修改dhcp配置 文件选项

  • /etc/config/dhcp

将设置为 option rebind_protection '0'

config dnsmasq

        option domainneeded '1'

        option boguspriv '1'

        option filterwin2k '0'

        option localise_queries '1'

        option rebind_protection '0' # 从1 设置为 0

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

        option ra 'hybrid'

        option ndp 'hybrid'

 

第二步:修改防火墙配置,添加STA 无线接口的配置项

/etc/config/firewall

config defaults

        option syn_flood '1'

        option input 'ACCEPT'

        option output 'ACCEPT'

        option forward 'REJECT'

 

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'

        list network 'wwan' # 在此处添加 wireless wan

        option input 'REJECT'

        option output 'ACCEPT'

        option forward 'REJECT'

        option masq '1'

        option mtu_fix '1'

 

第三步:修改网络配置,添加STA 无线接口的配置项和修改网关IP网段

  • /etc/config/network

config interface 'lan'

        option ifname 'eth0'

        option type 'bridge'

        option proto 'static'

        option ipaddr '192.168.2.1' # 注意上行路由IP是多少网段,如果跟上行有冲突这里修改一下,不要跟上行同一网段

        option netmask '255.255.255.0'

        option ip6assign '60'

 

config interface 'wan'

        option ifname 'eth1'

        option proto 'dhcp'

 

# add wireless station interface 在此处加上无线网络配置

config interface 'wwan'

        option proto 'dhcp'

 

config interface 'wan6'

        option ifname '@wan'

        option proto 'dhcpv6'

 

 

第四步:修改无线配置添加STA模式选项

  • /etc/config/wireless

onfig wifi-device 'radio0'

        option type 'mac80211'

        option channel '11'

        option hwmode '11ng'

        option path 'platform/qca953x_wmac'

        list ht_capab 'LDPC'

        list ht_capab 'SHORT-GI-20'

        list ht_capab 'SHORT-GI-40'

        list ht_capab 'TX-STBC'

        list ht_capab 'RX-STBC1'

        list ht_capab 'DSSS_CCK-40'

        option htmode 'HT20'

 

#添加无线STA模式的配置接口,这里ssid 是你要连接的上行路由的SSID,以及他的密码和加密类型。

config wifi-iface

        option device 'radio0'

        option network 'wwan'

        option mode 'sta'

        option ssid 'uplink_AP_SSID'

        option key '12345678'

        option encryption 'psk2'

 

config wifi-iface

        option device 'radio0'

        option network 'lan'

        option mode 'ap'

        option ssid 'OpenWrt'

        option encryption 'none'

 

第五步:重启WiFi

$ wifi up

查看进程和配置汇总是否获取上行IP地址

如下图:已成功启动相关进程

  $ ps

如下图: 成功从上行路由获取到IP地址:   

$ ifconfig

如何修改Openwrt 默认配置将AP改成AP+STA模式_第2张图片

Ping 外网是否通:

$ping www.baidu.com

如何修改Openwrt 默认配置将AP改成AP+STA模式_第3张图片

 

如果不通,查看路由表是否正确:

如何修改Openwrt 默认配置将AP改成AP+STA模式_第4张图片

上行网关是192.168.10.253, 192.168.2.0 是本地AP网段,192.168.10.0 是STA连接上行网段。

如果路由表没有,手动添加一条路由规则。

命令:

添加或者删除一条静态路由:

route add/del -net 192.168.10.0 netmask 255.255.255.0 wlan0

 

配置完成,现在可以用手机连接你的Repeater 直接上网。

 

 

以上是手动在板子中进行配置的。如下介绍高通QSDK 中配置

DHCP:

\qsdk_qca4531_cus531nand_code\qsdk\package\network\services\dnsmasq\files dhcp.conf

option rebind_protection 0

 

network 路径:

network 是通过脚本uci-defaults.sh生成的。

..\qsdk_qca4531_cus531nand_code\qsdk\package\base-files\files\lib\functions\uci-defaults.sh

 

ucidef_set_interface_lan() {

local ifname=$1

 

uci batch <

set network.lan='interface'

set network.lan.ifname='$ifname'

set network.lan.type='bridge'

set network.lan.proto='static'

set network.lan.ipaddr='192.168.2.1' // 在此处修改IP地址

set network.lan.netmask='255.255.255.0'

set network.lan.ip6assign='60'

EOF

}

 

ucidef_set_interface_wan() {

local ifname=$1

 

uci batch <

set network.wan='interface'

set network.wan.ifname='$ifname'

set network.wan.proto='dhcp'

set network.wan6='interface'

set network.wan6.ifname='@wan'

set network.wan6.proto='dhcpv6'

set network.wwan='interface' // 在此处修改

set network.wwan.proto='dhcp'

EOF

}

 

Firewall 路径:

..\qsdk\package\network\config\firewall\files\ firewall.config

加入 list network 'wwan'

如何修改Openwrt 默认配置将AP改成AP+STA模式_第5张图片

Wireless 配置 :

qca/feeds/wlan-open/mac80211/files/lib/wifi/mac80211.sh

 

config wifi-device  radio$devidx

option type     mac80211

option channel  ${channel}

option hwmode 11${mode_11n}${mode_band}

$dev_id

$ht_capab

# REMOVE THIS LINE TO ENABLE WIFI:

# option disabled 1

 

config wifi-iface

option device   radio$devidx

option network  lan

option mode     ap

option ssid     OpenWrt66666

option encryption none

 

#在此处加入

config wifi-iface

        option device 'radio0'

        option network 'wwan'

        option mode 'sta'

        option ssid 'hui_ui'

        option key 'ui12345678'

        option encryption 'psk2'

 

EOF

 

 

你可能感兴趣的:(无线通讯)