openWRT学习.docx
- 文档编号:5786502
- 上传时间:2023-01-01
- 格式:DOCX
- 页数:27
- 大小:32.58KB
openWRT学习.docx
《openWRT学习.docx》由会员分享,可在线阅读,更多相关《openWRT学习.docx(27页珍藏版)》请在冰豆网上搜索。
openWRT学习
OPENWRT学习总结
版本信息
版本
修订日期
修订人员
修订内容
审核人/日期/意见
1.0
2012-3-3
初始版本
Openwrt编译及烧写
Build.tex
Buildinganimage
Openwrt采用不同的方式来buildafirmware,从头开始来dowloading、patching、compiling一切,包括交叉编译器。
也就是说,openwrt不包含任何可执行程序,甚至源代码,他自动下载源代码、打补丁来满足指定平台,并编译。
通过修改template,我们就可以改变此过程中的任何步骤。
例如,如果一新的kernel发布了,只需要简单地修订其中的一个makefile文件就会download最新的kernel,patch,编译新的firmware映像。
这不仅适用于kernel,也适用于openwrt的所有模块,包含openwrt。
这使得openwrt保持最新的编译器、最新的内核及最新的应用。
DownloadOpenWrt
Openwrt的下载方式:
svncheckoutsvn:
//svn.openwrt.org/openwrt/trunkopenwrt-trunk
在https:
//dev.openwrt.org/上有一个trac接口,可用来检视svn提交及浏览源代码仓库。
Thedirectorystructure
有四个关键目录:
Tools、Toolchain、Package、Target。
tools和toolchain
其中tools和toolchain是通用工具,用来编译firmwareimage、编译器及C库。
其编译结果是三个新的目录:
build_dir/host,临时目录,用来buildtarget独立的工具;build_dir/toolchain-
Package
Package包目录,在openwrtfirmware中,所有模块均是.ipk,这种软件包可用来addtoiremware中来提供新的特性或去除以节省空间。
这些软件包也是在主干外维护的,并可通过packagefeed系统来获取到。
./scripts/feedsupdate
Thosepackagescanbeusedtoextendthefunctionalityofthebuildsystemandneedtobesymlinkedintothemaintrunk.Onceyoudothat,thepackageswillshowupinthemenuforconfiguration.Youwoulddosomethinglikethis:
./scripts/feedssearchnmap
Searchresultsinfeed'packages':
nmapNetworkexplorationand/orsecurityauditingutility
$./scripts/feedsinstallnmap
Toincludeallpackages,issuethefollowingcommand:
$makepackage/symlinks
Target
Target指的是嵌入式平台,包括特定嵌入式平台的内容。
其中target/linux目录,whichisbrokendownbyplatform
Target/image目录描述了怎么为特定平台打包firmware。
Target和package步骤均会使用build_dir/
BuildingOpenWrt
略
Creatingpackages
略
Creatingbinarypackages
略
Creatingkernelmodulespackages
略
Conventions
略
Troubleshooting
略
Usingbuildenvironments
略
Config.tex
配置文件结构
Structureoftheconfigurationfiles
配置文件分为sections和options/values对。
每一section有一type,但不一定需要name。
每一option有一个name和value,写在其所属于的section中。
语法如下:
config
option
每一参数应当是单一字符串,isformattedexactlylikeaparameterforashellfunction。
引号及特殊字符规则仍然适用,他们将被shell解释。
Parsingconfigurationfilesincustomscripts
为了loadconfigurationfiles,必须包含通用功能脚本:
./etc/functions.sh
这样就可以使用config_load
(这是最通用的使用方式)
Ifyouwanttousespecialcallbacksforsectionsand/oroptions,youneedtodefinethefollowingshellfunctionsbeforerunning\texttt{config\_load}(afterincluding\texttt{/etc/functions.sh}):
config_cb(){
localtype="$1"
localname="$2"
#commandstoberunforeverysection
}
option_cb(){
#commandstoberunforeveryoption
}
wireless.tex文档部分学习
WiFi配置文件为/etc/config/wireless。
当前支持broadcom、atheros、mac80211。
设备首次启动会检测无线卡类型,并创建一个默认配置文件(sampleconfigurationfile)。
每一无线驱动都有自己的配置脚本(/lib/wifi/driver_name.sh),用来处理驱动特定的选项及配置,脚本也会调用驱动特定的二进制如适用于broadcom的wlc,适用于atheros、mac80211的hostapd和wpa_supplicant。
这种结构(architecture)抽象了驱动配置。
通用的broadcom无线配置(略):
通用的mac80211无线配置(略):
通用的atheros无线配置:
configwifi-device"wifi0"
optiontype"atheros"
optionchannel"5"
optionhwmode"11g"
configwifi-iface
optiondevice"wifi0"
#optionnetworklan
optionmode"ap"
optionssid"OpenWrt"
optionhidden"0"
optionencryption"none"
通用的多radioatheros无线配置:
configwifi-devicewifi0
optiontypeatheros
optionchannel1
configwifi-iface
optiondevicewifi0
#optionnetworklan
optionmodeap
optionssidOpenWrt_private
optionhidden0
optionencryptionnone
configwifi-devicewifi1
optiontypeatheros
optionchannel11
configwifi-iface
optiondevicewifi1
#optionnetworklan
optionmodeap
optionssidOpenWrt_public
optionhidden1
optionencryptionnone
配置文件详述
配置文件有两部分,一是wifi-device,指的是物理wifi接口,而wifi-iface指的是其上的虚拟接口,即VAP。
整个的配置文件如下:
configwifi-devicewifidevicename
optiontypebroadcom,atheros,mac80211所支持的驱动类型
optioncountryus,uk,fr,de,etc.国家码
optionchannel1-14wifi信道,依赖于国家码
optionmaxassoc1-128(broadcomonly)关联的最大client数目,仅broadcom支持。
optiondistance1-n(meters)AP与最远的client的距离,仅atheros芯片支持
optionhwmode11b,11g,11a,11bg(atheros,mac80211)频率带宽,仅atheros支持。
optionrxantenna0,1,2(atheros,broadcom)接收端天线标识(Antennaidentifier)
optiontxantenna0,1,2(atheros,broadcom)发送端天线标识(Antennaidentifier)
optiontxpowertransmissionpowerindBm发射功率transmissionpower
configwifi-iface
optionnetworktheinterfaceyouwantwifitobridgewithwifi要使用的网络接口
optiondevicewifi0,wifi1,wifi2,wifiNwifi设备名
optionmodeap,sta,adhoc,monitor,mesh,orwds操作模式,有AP、clientmode、adhoc、monitor、meshpointmode(802.11s)及WDS点对点连接。
optiontxpower(deprecated)transmissionpowerindBm发送功率,应设置在wifi-device。
optionssidssidnameSSID名字
optionbssidbssidaddress用于WDS,设置为otherWDSunit的MAC地址
optionencryptionnone,wep,psk,psk2,wpa,wpa2加密设置,支持none、WEP、pre-sharedkey、及wparadius。
optionkeyencryptionkey
optionkey1key1
optionkey2key2
optionkey3key3
optionkey4key4
optionpassphrase0,10则将WPApsk为明文passphrase,1则为encodedpassphrase。
可通过wpa_passphrase工具产生加密的passphrase。
在passphrase包含特殊字符时有用。
此选项仅适用于mac80211或atheros。
optionserveripaddressradiusserverIP地址
optionportportradiusserver端口号,缺省为1812
optionhidden0,10为广播SSID,1为隐藏
optionisolate0,1(broadcom)无线客户端隔离功能,0要禁止隔离,1为开启,缺省为0.
optiondoth0,1(atheros,broadcom)Toggle802.11hmode,0为禁止802.11h,1为启用,缺省为0.
optionwmm0,1(atheros,broadcom)Toggle802.11emode,0为禁止,1为启用,缺省为0.
MeshPoint
MeshPoint(802.11s)仅mac80211驱动支持,需要安装iw包来建立meshlink。
Openwrt创建mshNmeshpoint接口,配置举例:
configwifi-device"wlan0"
optiontype"mac80211"
optionchannel"5"
configwifi-iface
optiondevice"wlan0"
optionnetworklan
optionmode"mesh"
optionmesh_id"OpenWrt"
WDS
WirelessDistributionSystem
WDS是个非标准模式,可工作在同类设备间,但不能工作在不同的设备如broadcom和atheros设备间。
UnencryptedWDSconnections
未加密的WDS配置如下,我们假定一端的BSSIDca:
fe:
ba:
be:
00:
01,而另一端为BSSIDca:
fe:
ba:
be:
00:
01:
configwifi-device"wl0"
optiontype"broadcom"
optionchannel"5"
configwifi-iface
optiondevice"wl0"
optionnetworklan
optionmode"ap"
optionssid"OpenWrt"
optionhidden"0"
optionencryption"none"
configwifi-iface
optiondevice"wl0"
optionnetworklan
optionmodewds
optionssid"OpenWrtWDS"
optionbssid"ca:
fe:
ba:
be:
00:
02"
EncryptedWDSconnections
可以加密wds连接,支持psk、psk2及psk+psk2模式,以下是一个使用AES加密算法的pre-sharedkey例子:
configwifi-devicewl0
optiontypebroadcom
optionchannel5
configwifi-iface
optiondevice"wl0"
optionnetworklan
optionmodeap
optionssid"OpenWrt"
optionencryptionpsk2
optionkey"
configwifi-iface
optiondevice"wl0"
optionnetworklan
optionmodewds
optionbssidca:
fe:
ba:
be:
00:
02
optionssid"OpenWrtWDS"
optionencryptionpsk2
optionkey"
802.1xconfigurations
配置略
EAP-PEAP
配置略
限制说明
Limitations
Therearecertainlimitationswhencombiningmodes.Onlythefollowingmodecombinationsaresupported:
WDSlinkscanonlybeusedinpureAPmodeandcannotuseWEP(exceptwhensharingthesettingswiththemasterinterface,whichisdoneautomatically).
VAPnumdefaultsto4,butcanbechangedbyloadingthemodulewiththemaxvaps=Nparameter.
Addinganewdriverconfiguration
具体添加方式略
Network-scripts.tex
Usingthenetworkscripts
为使用network,必须通过如下方式包含必须的shell脚本:
./etc/functions.sh#commonfunctions
include/lib/network#include/lib/network/*.sh
scan_interfaces#readandparsethenetworkconfig
有些协议,如PPP会在运行期间改变配置的接口名,如PPPOE会将eth0改为ppp0,因此要运行scan_interface,而不是从配置中直接读取。
运行scan_interface后,ifname选项将包含有效的接口名(用于iptraffic),如果物理设备名与此不同,则会保存在device选项中。
这意味着在scan_interface后运行config_get_lan_ifname,获取的结果可能与运行之前不同。
Writingprotocolhanders
添加协议处理
可通过在/lib/network下添加shell脚本来定制协议处理,脚本包含:
scan_
localconfig="$1"
#changetheinterfacenamesifnecessary
}
setup_interface_
localinterface="$1"
localconfig="$2"
#setuptheinterface
}
Network.tex
网络接口配置
网络配置文件为/etc/config/network,被分隔为多个接口配置。
每一个接口配置或直接就是ethernet/wifi接口(如eth0、wl0),或包含多个接口的桥接口。
如:
configinterface"lan"
optionifname"eth0"
optionproto"static"
optionipaddr"192.168.1.1"
optionnetmask"255.255.255.0"
optiongateway"192.168.1.254"
optiondns"192.168.1.254"
其中ifname指定linux接口名,如果使用bridge接口则将ifname设置为接口列表,同时添加optiontype“bridge”。
可通过添加vlanid来支持vlan功能如eth0.1,具体参照switch一节。
此配置是一个简单的eth0静态配置,proto指定了接口使用的协议,支持none、static、dhcp,可通过install额外的包来支持其他的协议。
Static
当为static时,ipaddr与netmask必填,而gateway与dns可选,支持多个DNS服务器,中间以空格隔开即可,如:
optiondns"192.168.1.254192.168.1.253"(optional)
如:
configinterface"lan"
optionifname"eth0"
optionproto"static"
...
optiondns"192.168.1.254192.168.1.253"(optional)
DHCP
DHCP当前仅接受ipaddr与hostname选项。
其中ipaddr指定了dhcpserver的地址,而hostname指定了客户的的hostname标识,两者均可选。
configinterface"lan"
optionifname"eth0"
optionproto"dhcp"
optionipaddr"192.168.1.1"(optional)
optionhostname"openwrt"(optional)
PPPOE
PPP基础的协议,如PPPOE、PPTP支持下列选项:
Username:
PPP用户名,用于PAP认证
Password:
PPP密码
Keepalived:
使用LCPpingPPP服务器,保活值,缺省间隔为5.
Demand:
按需拨友,值指定了最大空闲时间。
Server:
对端PPTP服务器IP地址
MTU设置
对所有协议,均可指定MTU,通过设置mtu选项即可,如:
configinterface"lan"
optionifname"eth0"
optionproto"pppoe"
optionusername"username"
optionpassword"openwrt"
optionmtu1492(optional)
设置静态路由
Settingupstaticroutes
可对指定的接口添加静态路由,在接口配置后会自动添加,举例配置:
configroutefoo
optioninterfacelan
optiontarget1.1.1.0
optionnetmask255.255.255.0
optiongateway192.168.1.1
其中route节的名称可选,interface
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- openWRT 学习