openwrt网络设置
来源:互联网 发布:ubuntu设置中文失败 编辑:程序博客网 时间:2024/05/18 13:27
OpenWrt的网络配置文件是/etc/config/network
,它负责交换芯片VLAN、网络接口和路由的配置。
此文件在编辑和保存之后需要执行
/etc/init.d/network reload命令.在变更生效前,停止和重启网络,目的是为了避免重启路由器. * https://dev.openwrt.org/browser/branches/attitude_adjustment/package/base-files/files/etc/config/network
- https://dev.openwrt.org/browser/trunk/package/base-files/files/etc/config/network
可以参考 netifd
节
下面是网络配置需要定义的节类型。通常情况下,一台路由器的最简网络配置包括至少2个interfaces(lan
和wan
),如果硬件支持,还包括一个switch。
switch
switch
节负责交换芯片VLAN的划分。在OpenWrt系统内部,每个VLAN都会有一个独立的interface与它对应,即便它们实际上属于同一个硬件。需要注意的是,不是所有被OpenWrt系统支持的设备都含有可编程的交换芯片,因此这个节在某些平台上不会出现。
现在有2个不同的配置格式在使用,一个是/proc/switch/
的API,另一个是新的基于swconfig的switch架构。
/proc/switch
这个变种只出现在Broadcom设备上,比如WRT54GL。
一个典型的配置就像这样:
config 'switch' 'eth0' option 'vlan0' '0 1 2 3 5*' option 'vlan1' '4 5'
其中,eth0
标识符指明这个节对应的交换芯片。VLAN的定义方法是显然的,一般来说,0、1、2、3是路由器LAN口,4是路由器WAN口,5表示CPU,而5*表示这个接口是trunk。更多的信息请参考 switch documentation。
swconfig
新的swconfig框架将取代老式switch配置。现在它正被一些设备如D-Link DIR-300使用。
基于Swconfig的配置是一种全新的格式,即每个VLAN都使用一个节。下面的例子说明了运行在D-Link DIR-300设备上的Kamikaze 8.09分支所使用的标准配置:
config 'switch' 'eth0' option 'reset' '1' option 'enable_vlan' '1'config 'switch_vlan' 'eth0_1' option 'device' 'eth0' option 'vlan' '1' option 'ports' '0 1 2 3 5t'config 'switch_vlan' 'eth0_2' option 'device' 'eth0' option 'vlan' '2' option 'ports' '4 5t'
通用的属性仍然在switch节定义,各VLAN相关属性定义在各自的switch_vlan节中,它们通过指定device属性使系统得悉它使用的交换芯片。完整的格式请参看switch documentation。
Interfaces
interface
类型的节声明了逻辑网络接口,可以为这些接口指定IP地址、别名、物理网络接口名称、路由规则及防火墙规则。
一个最简的interface节包含以下行:
config 'interface' 'wan' option 'proto' 'dhcp' option 'ifname' 'eth0.1'
wan
是唯一的 逻辑网络接口名称dhcp
指定接口协议,这里是dhcpeth0.1
是相关联的物理网络接口名称(用ifconfig可看到)
接口协议可以是以下之一:
static
静态ipdhcp
动态ipppp
PPP 协议 - 拨号MODEM连接pppoe
以太网上的PPP协议 - DSL宽带连接pppoa
ATM上的PPP协议 - 使用内建MODEM的DSL连接3g
使用3G上网卡的CDMA, UMTS 或 GPRS 连接pptp
通过PPtP VPN的连接none
不指定任何协议针对指定协议的类型,还需要额外的选项,参看下表。在Required字段标记"yes"的选项必须在interface节中定义,标记"no"选项的可以省略。
所有协议类型的有效选项
ifname
interface name(s)yes(*)(none)物理接口名称。如果type选项被设为bridge,需要指定一个接口列表.(*) This option may be empty or missing if only a wireless interface references this network
type
stringno(none)如果设置为"bridge",将建立一个包含ifname所述接口的网桥stp
booleanno0
启用生成树协议,只对网桥有效macaddr
mac addressno(none)指定接口MAC地址mtu
numberno(none)指定接口最大传输单元(MTU)auto
booleanno0
for proto none
, else 1
指定是否在引导成功后打开这个接口"static"协议
ipaddr
ip addressyes, if no ip6addr
is set(none)IP地址netmask
netmaskyes, if no ip6addr
is set(none)子网掩码gateway
ip addressno(none)默认路由bcast
ip addressno(none)广播地址 (不设置会自动生成)ip6addr
ipv6 addressyes, if no ipaddr
is set(none)为接口指派给定的IPv6 地址 (CIDR notation)ip6gw
ipv6 addressno(none)为接口指派给定的IPv6默认网关dns
list of ip addressesno(none)DNS服务器(1个或多个)"dhcp"协议
gateway
stringno(none)如果设置为0.0.0.0,将设置DHCP协议获取的默认网关dns
list of ip addressesno(none)指定DNS服务器(1个或多个)"ppp" (Modem上的PPP)协议
要使用PPP,必须安装ppp
软件包。
device
file pathyes(none)MODEM设备节点username
stringno(?)(none)用于PAP/CHAP认证的用户名password
stringno(?)(none)用于PAP/CHAP authentication的密码connect
file pathno(none)自定义PPP连接脚本路径disconnect
file pathno(none)自定义PPP断开连接脚本路径keepalive
numberno(none)Number of connection failures before reconnectdemand
numberno(none)Number of seconds to wait before closing the connection due to inactivitydefaultroute
booleanno1
Replace existing default route on PPP connectpeerdns
booleanno1
Use peer-assigned DNS server(s)dns
list of ip addressesno(none)Override peer-assigned DNS server(s)ipv6
booleanno0
为PPP连接启用IPv6pppd_options
stringno(none)传递给pppd守护进程的额外命令行参数"pppoe" (以太网的PPP)协议
要使用PPPoE,必须安装ppp-mod-pppoe
软件包.
username
stringno(?)(none)用于PAP/CHAP认证的用户名password
stringno(?)(none)用于PAP/CHAP认证的密码connect
file pathno(none)自定义PPP连接脚本路径disconnect
file pathno(none)自定义PPP断开连接脚本路径keepalive
numberno(none)Number of connection failures before reconnectdemand
numberno(none)Number of seconds to wait before closing the connection due to inactivitydefaultroute
booleanno1
Replace existing default route on PPP connectpeerdns
booleanno1
Use peer-assigned DNS server(s)dns
list of ip addressesno(none)Override peer-assigned DNS server(s)ipv6
booleanno0
为PPP连接启用IPv6pppd_options
stringno(none)传递给pppd守护进程的额外命令行参数"pppoa" (ATM上的PPP)协议
要使用PPPoA,必须安装 ppp-mod-pppoa
软件包.
unit
numberyes(none)br2684 interface numbervci
numberno35
PPPoA VCIvpi
numberno8
PPPoA VPIatmdev
numberno(none)ATM PVC numberencaps
stringnollc
PPPoA encapsulation mode: 'llc' (LLC) or 'vc' (VC)payload
stringnobridged
PPPoA forwarding mode: 'routed' or 'bridged'username
stringno(?)(none)用于PAP/CHAP认证的用户名password
stringno(?)(none)用于PAP/CHAP认证的密码connect
file pathno(none)自定义PPP连接脚本路径disconnect
file pathno(none)自定义PPP断开连接脚本路径keepalive
numberno(none)Number of connection failures before reconnectdemand
numberno(none)Number of seconds to wait before closing the connection due to inactivitydefaultroute
booleanno1
Replace existing default route on PPP connectpeerdns
booleanno1
Use peer-assigned DNS server(s)dns
list of ip addressesno(none)Override peer-assigned DNS server(s)ipv6
booleanno0
为PPP连接启用IPv6pppd_options
stringno(none)传递给pppd守护进程的额外命令行参数"3g" (PPP over EV-DO, CDMA, UMTS or GRPS)协议
要使用3G,必须安装 comgt
软件包.
device
file pathyes(none)Modem设备节点service
stringyesgprs
3G设备类型: evdo
, cdma
, umts
或 gprs
apn
stringyes(none)Used APNpincode
numberno(none)解锁SIM卡的PIN码maxwait
numberno20
等待Modem就绪的时间(秒)username
stringno(?)(none)用于PAP/CHAP认证的用户名password
stringno(?)(none)用于PAP/CHAP认证的密码keepalive
numberno(none)Number of connection failures before reconnectdemand
numberno(none)Number of seconds to wait before closing the connection due to inactivitydefaultroute
booleanno1
Replace existing default route on PPP connectpeerdns
booleanno1
Use peer-assigned DNS server(s)dns
list of ip addressesno(none)Override peer-assigned DNS server(s)ipv6
booleanno0
为PPP连接启用IPv6"pptp" (Point-to-Point Tunneling Protocol)协议
要使用PPtP,必须安装 pptp
软件包.
server
ip addressyes(none)远程PPtP服务器ipproto
stringnodhcp
建立PPtP隧道前用来获取IP连通性的协议username
stringno(?)(none)用于PAP/CHAP认证的用户名password
stringno(?)(none)用于PAP/CHAP认证的密码Additionally all options defined for the corresponding ipproto
can be specified别名
Alias sections can be used to define further IPv4 and IPv6 addresses for interfaces. They also allow combinations like DHCP on the main interface and a static IPv6 address in the alias, for example to deploy IPv6 on wan while keeping normal internet connectivity. Each interface can have multiple aliases attached to it.
别名最小的声明包含以下行:
config 'alias' option 'interface' 'lan' option 'proto' 'static' option 'ipaddr' '10.0.0.1' option 'netmask' '255.255.255.0'
lan
is the logical interface name of the parent interfacestatic
is the alias interface protocol10.0.0.1
specifies the alias ip address255.255.255.0
specifies the alias netmask
At the time of writing, only the static
protocol type is allowed for aliases. Defined options for alias
sections are listed below.
interface
stringyes(none)Specifies the logical interface name of the parent (or master) interface this alias is belonging to, must refer to one of the defined interface
sectionsproto
stringyes(none)Specifies the alias interface protocolipaddr
ip addressyes, if no ip6addr
is set(none)IP addressnetmask
netmaskyes, if no ip6addr
is set(none)Netmaskgateway
ip addressno(none)Default gatewaybcast
ip addressno(none)Broadcast address (autogenerated if not set)ip6addr
ipv6 addressyes, if no ipaddr
is set(none)IPv6 address (CIDR notation)ip6gw
ipv6 addressno(none)IPv6 default gatewaydns
list of ip addressesno(none)DNS server(s)IPv4 Routes
It is possible to define arbitary IPv4 routes on specific interfaces using route
sections. As for aliases, multiple sections can be attached to an interface.
一个minimial的例子类似如下:
config 'route' option 'interface' 'lan' option 'target' '172.16.123.0' option 'netmask' '255.255.255.0'
lan
is the logical interface name of the parent interface172.16.123.0
is the network address of the route255.255.255.0
specifies the route netmask
Legal options for IPv4 routes are:
interface
stringyes(none)Specifies the logical interface name of the parent (or master) interface this route is belonging to, must refer to one of the defined interface
sectionstarget
ip addressyes(none)Network addressnetmask
netmaskno(none)Route netmask. If ommitted, 255.255.255.255
is assumed which makes target
a host addressgateway
ip addressno(none)Network gateway. If ommitted, the gateway
from the parent interface is taken, if set to 0.0.0.0
no gateway will be specified for the routemetric
numberno0
Specifies the route metric to useIPv6路由
IPv6 routes可指定定义一个或多个route6
的sections.
一个minimial的例子类似如下:
config 'route6' option 'interface' 'lan' option 'target' '2001:0DB8:100:F00:BA3::1/64' option 'gateway' '2001:0DB8:99::1'
lan
is the logical interface name of the parent interface2001:0DB8:100:F00:BA3::1/64
is the routed IPv6 subnet in CIDR notation2001:0DB8:99::1
specifies the IPv6 gateway for this route
Legal options for IPv6 routes are:
interface
stringyes(none)Specifies the logical interface name of the parent (or master) interface this route is belonging to, must refer to one of the defined interface
sectionstarget
ipv6 addressyes(none)IPv6 network addressgateway
ipv6 addressno(none)IPv6 gateway. If ommitted, the gateway
from the parent interface is takenmetric
numberno0
Specifies the route metric to use例子
下面是特殊的,非标准接口配置的几个例子。
Bridge without IP
config 'interface' 'example' option 'type' 'bridge' option 'proto' 'none' option 'ifname' 'eth0 eth1' option 'auto' '1'
DHCP without default gateway
config 'interface' 'example' option 'proto' 'dhcp' option 'ifname' 'eth0' option 'gateway' '0.0.0.0'
DHCP及IPv6
config 'interface' 'example' option 'proto' 'dhcp' option 'ifname' 'eth0'config 'alias' option 'interface' 'example' option 'proto' 'static' option 'ip6addr' '2001:0DB8:100:F00:BA3::1'
静态IP配置和默认网关与非零十进制
config 'interface' 'example' option 'proto' 'static' option 'ifname' 'eth0' option 'ipaddr' '192.168.1.200' option 'netmask' '255.255.255.0' option 'dns' '192.168.1.1'config 'route' option 'interface' 'example' option 'target' '0.0.0.0' option 'netmask' '0.0.0.0' option 'gateway' '192.168.1.1' option 'metric' '100'
PPtP-over-PPPoE internet connection
config 'interface' 'wan'
option 'proto' 'pppoe'
option 'ifname' 'eth1'
option 'username' 'user'
option 'password' 'pass'
option 'timeout' '10'
config 'interface' 'vpn'
option 'proto' 'pptp'
option 'ifname' 'vpn'
option 'username' 'vpnuser'
option 'password' 'vpnpass'
option 'server' 'vpn.example.org'
:!: Additionally the "wan" firewall zone must include both interfaces in /etc/config/firewall:
config 'zone'
option 'name' 'wan'
option 'network' 'wan vpn'
option 'input' 'REJECT'
option 'forward' 'REJECT'
option 'output' 'ACCEPT'
option 'masq' '1'
http://wiki.openwrt.org/zh-cn/doc/uci/network
- openwrt网络设置
- openwrt uci 设置网络命令
- OpenWRT 教程 之 设置网络和无线
- 【openwrt新手】 uci 设置网络命令
- openwrt设置网络失败后的处理
- 使用openwrt设置Guest Wifi网络
- 使用openwrt设置Guest Wifi网络
- openwrt下的网络设置过程
- OPENWRT使用命令行设置无线和有线网络
- OPENWRT使用命令行设置无线和有线网络
- OPENWRT使用命令行设置无线和有线网络
- OPENWRT使用命令行设置无线和有线网络
- OPENWRT使用命令行设置无线和有线网络
- OpenWrt网络结构
- openwrt 的网络问题
- openwrt dns服务器设置
- openwrt中继设置方法
- OpenWRT网页设置
- 项目经理应该把 30% 的时间用在编程上
- Android LayoutInflater原理分析,带你一步步深入了解View(一)
- Android开发之如何保证Service不被杀掉(broadcast+system/app)
- Android游戏开发十日通(6)- 太空大战
- error: start and/or end address not on sector boundary解决
- openwrt网络设置
- awk中RS,ORS,FS,OFS区别与联系
- Git SSH Key 生成步骤
- Android.mk
- Quartz2D使用(截屏)
- 第17周项目2.2 引用做形参实现排序
- 用WebStorm编辑Markdown
- 少编码多思考:代码越多 问题越多
- 保存CBitmap图片到硬盘的方法