openwrt学习
config interface \
option ifname \option proto \
option ipaddr \option netmask \
option gateway \
option dns \
其中ifname指定linux接口名,如果使用bridge接口则将ifname设置为接口列表,同时添加option type “bridge”。
可通过添加vlanid来支持vlan功能如eth0.1,具体参照switch一节。
此配置是一个简单的eth0静态配置,proto指定了接口使用的协议,支持none、static、dhcp,可通过install额外的包来支持其他的协议。
Static
当为static时,ipaddr与netmask必填,而gateway与dns可选,支持多个DNS服务器,中间以空格隔开即可,如:option dns \
如:
config interface \ option ifname \ option proto \
...
option dns \
DHCP
DHCP当前仅接受ipaddr与hostname选项。其中ipaddr指定了dhcp server的地址,而hostname指定了客户的的hostname标识,两者均可选。
config interface \ option ifname \ option proto \
option ipaddr \ option hostname \
PPPOE
PPP基础的协议,如PPPOE、PPTP支持下列选项: Username:PPP用户名,用于PAP认证 Password:PPP密码
Keepalived:使用LCP ping PPP服务器,保活值,缺省间隔为5. Demand:按需拨友,值指定了最大空闲时间。 Server:对端PPTP服务器IP地址
版权所有?2012 成都科技有限公司
第 13 页 共 29 页
openwrt学习
MTU设置
对所有协议,均可指定MTU,通过设置mtu选项即可,如: config interface \ option ifname \ option proto \ option username \ option password \ option mtu
1492 (optional)
设置静态路由
Setting up static routes
可对指定的接口添加静态路由,在接口配置后会自动添加,举例配置: config route foo
option interface lan option target 1.1.1.0
option netmask 255.255.255.0 option gateway 192.168.1.1
其中route节的名称可选,interface、target、gateway选项是必须的。如果netmsk不填,则默认为主机路由。
设置交换机
Setting up the switch (currently broadcom only) 设置交换机,当前仅broadcom支持。 略
IPV6设置
Setting up IPv6 connectivity 略
版权所有?2012 成都科技有限公司
第 14 页 共 29 页
openwrt学习
Init_script.tex
功能脚本
由于openwrt使用自己的初始script系统,所有的init script必须使用/etc/rc.common作为wrapper安装在/etc/init.d/
如/etc/init.d/httpd: #!/bin/sh /etc/rc.common
# Copyright (C) 2006 OpenWrt.org
START=50 start() {
[ -d /www ] && httpd -p 80 -h /www -r OpenWrt }
stop() {
killall httpd }
从上可以看出,script本身并不解析命令行参数,而是由/etc/rc.common来完成。 Start和stop是最基本的功能,几乎所有init script都要提供。Start是在运行/etc/init.d/httpd start时来调用,可以是系统启动时,或用户手动运行此脚本时。
通过/etc/init.d/
/etc/rc.common说明
#!/bin/sh # Copyright (C) 2006-2011 OpenWrt.org
. $IPKG_INSTROOT/lib/functions.sh . $IPKG_INSTROOT/lib/functions/service.sh initscript=$1 action=${2:-help} shift 2
start() { return 0
版权所有?2012 成都科技有限公司
第 15 页 共 29 页
openwrt学习
} stop() { return 0 } reload() {
return 1 }
restart() { trap '' TERM stop \ start \
} boot() { start \
} shutdown() {
stop } disable() { 禁止服务开启
name=\ rm -f \
rm -f \ }
enable() { 开启服务 name=\
disable [ -n \
echo \ return 1 [ \] && ln \
[
\
]
&&
ln
\
-s -s
\\
}
}
enabled() { name=\
版权所有?2012 成都科技有限公司
第 16 页 共 29 页
相关推荐: