小编给大家分享一下OpenWRT如何启用工作模式开关和联网,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!
主要配置 rc.local 脚本,内容如下:
read_gpio() { (echo $1 > /sys/class/gpio/export) >& /dev/null (echo "in" > /sys/class/gpio/gpio$1/direction) >& /dev/null return `cat /sys/class/gpio/gpio$1/value`; } read_gpio 19; v=$?; read_gpio 20; v=$v$?; read_gpio 21; v=$v$?; read_gpio 22; v=$v$?; read_gpio 23; v=$v$?; case "$v" in 10001) v="ap";; 11001) v="repeater";; 01001) v="hotspot";; 11000) v="4th";; *) v="error";; esac cp /etc/config/$v/* /etc/config/ logger working mode: $v exit 0
原理是开机自动复制配置文件覆盖到 /etc/config/ 下,配置文件不需要全部,只要 firewall、network 和 wireless 就行了。按工作模式命名,创建三个目录:
mkdir /etc/config/ap mkdir /etc/config/repeater mkdir /etc/config/hotspot
后面,我们会把配置文件写好了,放在这些目录里。下面以 ap 为例,此模式是网口做 WAN,无线做 LAN,WAN 以 ADSL 接入为例,其它情况自行变通:
uci set wireless.@wifi-device[0].disabled=0; uci set wireless.@wifi-iface[0].ssid='umu618.com'; uci set wireless.@wifi-iface[0].encryption='psk2+ccmp'; uci set wireless.@wifi-iface[0].key='WiFi 密码'; uci commit wireless; wifi uci delete network.lan.ifname uci delete network.lan.type uci add network interface uci rename network.@interface[-1]='wan' uci set network.@interface[-1].ifname='eth2' uci set network.@interface[-1]._orig_ifname='eth2' uci set network.@interface[-1]._orig_bridge='false' uci set network.@interface[-1].proto='pppoe' uci set network.@interface[-1].username='宽带账号' uci set network.@interface[-1].password='宽带密码' uci commit network cp /etc/config/firewall /etc/config/ap/ cp /etc/config/network /etc/config/ap/ cp /etc/config/wireless /etc/config/ap/
再来说一下 repeater,网口做 LAN,无线做一个 AP Client 和一个 AP。注意,以下命令以初始化的配置文件为基础,请事先备份、还原,不要在配置过前面的 ap 模式后直接继续配置,可能会有问题。
uci add network interface uci rename network.@interface[-1]='wwan' uci set network.@interface[-1].proto='dhcp' uci commit network uci set wireless.@wifi-device[0].disabled=0; uci set wireless.@wifi-iface[0].ssid='umu618.com'; uci set wireless.@wifi-iface[0].encryption='psk2+ccmp'; uci set wireless.@wifi-iface[0].key='WiFi 密码'; uci add wireless wifi-iface uci set wireless.@wifi-iface[-1].network='wwan' uci set wireless.@wifi-iface[-1].ssid='现有 WiFi 名字' uci set wireless.@wifi-iface[-1].device='radio0' uci set wireless.@wifi-iface[-1].mode='sta' uci set wireless.@wifi-iface[-1].bssid='现有无线路由器的 MAC 地址' uci set wireless.@wifi-iface[-1].encryption='psk2+ccmp' uci set wireless.@wifi-iface[-1].key='现有 WiFi 密码' uci commit wireless; wifi uci get firewall.@zone[1].network uci show firewall.@zone[1] uci set firewall.@zone[1].network='wan wan6 wwan' uci commit firewall /etc/init.d/firewall restart cp /etc/config/firewall /etc/config/repeater/ cp /etc/config/network /etc/config/repeater/ cp /etc/config/wireless /etc/config/repeater/
看完了这篇文章,相信你对“OpenWRT如何启用工作模式开关和联网”有了一定的了解,如果想了解更多相关知识,欢迎关注亿速云行业资讯频道,感谢各位的阅读!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。