OpenWrt the detailed process of the wired network setup

Source: Internet
Author: User
Tags pings

Under Openwrt\trunk\target\linux\ramips\base-files\etc\uci-defaults\02_network, the settings for the network are indicated

The following script is called: \openwrt\trunk\package\base-files\files\lib

. /lib/>openwrt\trunk\package\base-files\files\lib\
. /lib/>openwrt\trunk\target\linux\ramips\base-files\lib\
. /lib/functions/>openwrt\trunk\package\base-files\files\lib\functions\ setting up the network:

<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= ' '
set network.lan.netmask= ' '
set network.lan.ip6assign= '

If you want to add a gateway, as follows:

Set network.lan.gateway= ' '
set network.lan.dns= ' '

Here, Eth0.proto has a simple static configuration to describe the protocol used by the interface, and the default image usually provides ' none ', ' Static ', ' DHCP ' and ' PPPoE ' mode. Other ways, you can install additional protocols by loading packages.

When using the ' static ' method as in this example, IPADDR and netmask are mandatory, and gateway and DNS are optional. You can specify more than one DNS server, separated by a space.

DHCP can now only set ipaddr (the IP address that you want to request from the server) and hostname (the client hostname tag), both of which are optional. The PPP protocol family accepts the following options:

PPP-based protocol (PPPoE, PPTP, ...) accepts the following options: username
The PPP username (usually with PAP authentication) password
The PPP password keepalive
Ping PPP Server (using LCP). This option defines the maximum number of failed pings before a re-connect. This ping interval defaults to 5, but you can modify the KeepAlive value by attaching ",". 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 is changed by appending "," to the KeepAlive value demand
Use Dial on Demand (value specifies the maximum idle time. Server: (PPTP)
Remote PPTP server IP The remotely PPTP server IP

For all types of protocols, you can set the MTU by setting the MTU option. set static routes setting up static routes

You can set a static route for a specific interface, which will show the effect after the interface is configured.

Join as simple as the following:

Config Route foo
Option interface LAN
Option Target
Option Netmask
Option Gateway

The name in the route segment is optional, and the Interface,target and gateway options are mandatory. Not using the netmask option will cause the route to be set to the host route.

The name for the route sections is optional, the interface, Targetand gateway options are mandatory. Leaving out the netmaskoption would turn the route into a host route.

Set up the 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 '

So the RT5350 network settings are as follows:

Ramips_setup_interfaces under the Openwrt\trunk\target\linux\ramips\base-files\etc\uci-defaults\02_network file:

		rt3x5x= ' cat/proc/cpuinfo | egrep "(rt3.5| RT5350) "'
		if [-N ' ${rt3x5x} ']; then
			Ucidef_set_interfaces_lan_wan" eth0.1 "" eth0.2 "

Ramips_setup_rt3x5x_vlans ()
	if [!-x/sbin/swconfig]; then
		# legacy Default
		Ucidef_set_interfaces_ Lan_wan "eth0.1" "eth0.2"
	local wanports= "
	local lanports=" "for
	Port in 5 4 3 2 1 0; Do
  if [' Swconfig dev rt305x port $port get Disable ' = "1"]; Then
		if [' Swconfig dev rt305x port $port get lan ' = "0"], then
			wanports= "$port $wanports "
			lanports=" $port $lanports "
	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"

		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"

As can be seen from the default configuration, ports 0, 1, 2, 3 belong to Vlan0, Port 4 belongs to Vlan1, and line 2nd indicates that the VLAN0 is set
is LAN, ports 0, 1, 2, 3 are LANs, and line 10th indicates that the VLAN1 is set to Wan, and Port 4 is WAN.
Option Ports ' 0 1 2 3 6t ' because the Board Development Board only applies VLAN port 3 and Port 4
The 0,1,2 of this line is removed, so that a two VLAN is configured, Port 3 as the first VLAN, and Port 4 as the 2nd VLAN, so that the network ring
The environment is well-equipped. Port 3 is a LAN and Port 4 is a WAN.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.