openwrt下有线网设置详细过程

在openwrt\trunk\target\linux\ramips\base-files\etc\uci-defaults\02_network下,指明了网络的设置


会调用以下脚本: \openwrt\trunk\package\base-files\files\lib

. /lib/functions.sh  ------->openwrt\trunk\package\base-files\files\lib\functions.sh
. /lib/ramips.sh     ------->openwrt\trunk\target\linux\ramips\base-files\lib\ramips.sh
. /lib/functions/uci-defaults.sh    ---------->openwrt\trunk\package\base-files\files\lib\functions\uci-defaults.sh     设置网络:


<pre name="code" class="cpp">ucidef_set_interface_lan() {
	local ifname=$1

	uci batch <<EOF
set network.lan='interface'
set network.lan.ifname='$ifname'
set network.lan.force_link=1
set network.lan.type='bridge'
set network.lan.proto='static'
set network.lan.ipaddr='192.168.1.1'
set network.lan.netmask='255.255.255.0'
set network.lan.ip6assign='60'
EOF
}


 如果要加网关,如下: 

set network.lan.gateway='192.168.1.254'
set network.lan.dns='8.8.8.8'

这里对eth0.proto有一个简单的静态配置来描述该接口所使用的协议,默认的Image中通常会提供'none' 'static''dhcp''pppoe'方式。其他方式,可以通过加载包来安装其他协议。

像例子中这样使用'static'方法时,ipaddr和netmask是强制的,gateway和dns是可选的。你可以指定不止一个的DNS server,用空格分开。

DHCP目前只可以设置ipaddr(希望从server请求的IP地址)和hostname(客户端主机名标签),两者都是可选的。PPP协议族接受如下选项:

基于PPP 的协议(pppoepptp, ...) 接受下列选项:

  • username 
    The PPP username (usually with PAP authentication)
  • password 
    The PPP password
  • keepalive 
    Ping PPP server(使用LCP)。这个选项定义了重连前的失败ping最大个数。这个ping间隔默认为5,但是可以通过附加"," 来修改keepalive 值。Ping the PPP server (using LCP). The value of this option specifies the maximum number of failed pings before reconnecting. The ping interval defaults to 5, but can be changed by appending "," to the keepalive value
  • demand 
    Use Dial on Demand (value specifies the maximum idle time.
  • server: (pptp) 
    远程pptp server IP The remote pptp server IP

对于所有类型的协议,都可以通过设置mtu选项来设置MTU。 

设置静态路由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段中的name是可选的,interface,target和gateway选项是强制的。不使用netmask选项将会使该route设置成host route。

The name for the route section is 可选的, the interfacetargetand gateway options are mandatory. Leaving out the netmaskoption will turn the route into a host route.



设置 WAN:

ucidef_set_interface_wan() {
	local ifname=$1

	uci batch <<EOF
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'
EOF
}


故RT5350的网络设置如下:

在  openwrt\trunk\target\linux\ramips\base-files\etc\uci-defaults\02_network文件下的ramips_setup_interfaces:

	*)
		RT3X5X=`cat /proc/cpuinfo | egrep "(RT3.5|RT5350)"`
		if [ -n "${RT3X5X}" ]; then
			ramips_setup_rt3x5x_vlans
		else
			ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
		fi
		;;

ramips_setup_rt3x5x_vlans()
{
	if [ ! -x /sbin/swconfig ]; then
		# legacy default
		ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
		return
	fi
	
	local wanports=""
	local lanports=""
	for port in 5 4 3 2 1 0; do
		if [ `swconfig dev rt305x port $port get disable` = "1" ]; then
			continue
		fi
		
		if [ `swconfig dev rt305x port $port get lan` = "0" ]; then
			wanports="$port $wanports"
		else
			lanports="$port $lanports"
		fi
		
	done
	
	
	ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
	ucidef_add_switch "rt305x" "1" "1"
	ucidef_add_switch_vlan "rt305x" "1" "$lanports 6t"
	ucidef_add_switch_vlan "rt305x" "2" "$wanports 6t"
}



















	 rt5350)
		ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
		ucidef_add_switch "switch0" "1" "1"
		ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 6t"
		ucidef_add_switch_vlan "switch0" "2" "4 6t"
		;;


从默认配置可以看出,端口 0、1、2、3 属于 vlan0,端口 4属于 vlan1;第 2行则说明是将 vlan0 设置
为 lan,则端口 0、1、2、3 为 LAN;第 10 行则说明将 vlan1 设置为 WAN,则端口 4 为 WAN。
因为板开发板仅适用 vlan端口 3 和端口 4,可以把 option ports '0 1 2 3 6t'
这一行的0,1,2去掉,这样就配置个两个 vlan,端口3作为第一个 vlan,端口4作为第2个 vlan,这样网络环
境就配置好了。端口3为 LAN,端口4为 WAN。

  • 1
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值