Table of contents
In this tutorial we will setup an initial network configuration for OpenWrt on your ESPRESSObin. For following this tutorial, it is presumed you have booted OpenWrt on your ESPRESSObin as instructed in Boot from MicroSD card/USB stick - OpenWrt.
We will start by setting up ESPRESSObin as a network client with no routing. If you have already configured this, please skip the next step and move to Routing section.
Network client
Connect one end of an Ethernet cable to the WAN port on ESPRESSObin and the other end to your router or IP switch. Connect to the ESPRESSObin console as described in Quick User Guide. Central network configuration in OpenWrt is configured in the /etc/config/network configuration file through which users can define interface configuration, network routes and switch VLANs. Here, however, we will cover only a basic routing setup.
So, open the file:
root@OpenWrt:/# vi /etc/config/network
and append the following section at the end of the file:
config interface 'wan' option ifname 'wan' option proto 'dhcp'
where:
- 'wan' is a unique logical interface name
- 'dhcp' specifies the interface protocol or DHCP in the example above
- 'wan' specifies the physical interface associated with this section
save your changes to the file and exit the editor. Now we need to restart the network for the changes to take effect:
root@OpenWrt:/# /etc/init.d/network restart root@OpenWrt:/# [ 12.578049] dsa dsa@0 wan: Link is Down [ 12.957444] mvneta d0030000.ethernet eth0: Link is Up - 1Gbps/Full - flow control off [ 12.965498] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready [ 13.586806] dsa dsa@0 wan: Link is Up - 100Mbps/Full - flow control rx/tx [ 13.593611] IPv6: ADDRCONF(NETDEV_CHANGE): wan: link becomes ready
and your 'wan' interface should now be up. Check that everything is working, e.g. ping Google:
root@OpenWrt:/# ping 8.8.8.8 PING 8.8.8.8 (8.8.8.8): 56 data bytes 64 bytes from 8.8.8.8: seq=0 ttl=56 time=53.772 ms 64 bytes from 8.8.8.8: seq=1 ttl=56 time=48.490 ms 64 bytes from 8.8.8.8: seq=2 ttl=56 time=49.152 ms ^C --- 8.8.8.8 ping statistics --- 3 packets transmitted, 3 packets received, 0% packet loss round-trip min/avg/max = 48.490/50.471/53.772 ms
Routing
Now connect one end of an Ethernet cable into one of the LAN ports on your ESPRESSObin and the other end to your laptop. Again, we will open /etc/network/config and add the following section for a bridged interface:
config interface 'lan' option type 'bridge' option ifname 'lan0 lan1' option proto 'static' option ipaddr '192.168.1.1' option netmask '255.255.255.0' option ip6assign '60'
where:
- 'lan' is a unique logical interface name
- with 'bridge' we specify that we will be creating a bridge containing given ifnames 'lan0' and 'lan1'
- 'lan0' and 'lan1' are the physical interfaces we will assign to this section
- 'static' specifies the interface protocol, or static configuration with fixed addresses and netmask in this example
- with 'ipaddr' and 'netmask' options we specify the static IP address and netmask to be used for this interface
- with '60' we delegate a prefix size used for this interface
again, restart your network with:
root@OpenWrt:/# /etc/init.d/network restart [ 1580.713088] dsa dsa@0 lan1: Link is Up - 1Gbps/Full - flow control rx/tx [ 1580.728456] br-lan: port 2(lan1) entered blocking state [ 1580.733529] br-lan: port 2(lan1) entered forwarding state [ 1580.740946] IPv6: ADDRCONF(NETDEV_CHANGE): br-lan: link becomes ready
and your ESPRESSObin should now act as a gateway between your laptop and the Internet. Check that everything is working, i.e. from the console ping your laptop:
root@OpenWrt:/# ping 192.168.1.134 PING 192.168.1.134 (192.168.1.134): 56 data bytes 64 bytes from 192.168.1.134: seq=0 ttl=64 time=0.601 ms 64 bytes from 192.168.1.134: seq=1 ttl=64 time=0.510 ms 64 bytes from 192.168.1.134: seq=2 ttl=64 time=0.466 ms ^C --- 192.168.1.134 ping statistics --- 3 packets transmitted, 3 packets received, 0% packet loss round-trip min/avg/max = 0.466/0.525/0.601 ms
To summarize, our /etc/config/network file looks like this:
config interface 'loopback' option ifname 'lo' option proto 'static' option ipaddr '127.0.0.1' option netmask '255.0.0.0' config globals 'globals' option default_ps '0' option ula_prefix 'fdd3:01f8:6843::/48' config interface 'lan' option type 'bridge' option ifname 'lan0 lan1' option proto 'static' option ipaddr '192.168.1.1' option netmask '255.255.255.0' option ip6assign '60' config interface 'wan' option ifname 'wan' option proto 'dhcp'
More complex network setups for OpenWrt on ESPRESSObin should be up on the Wiki soon. For a list of network configuration options and examples, consult the official OpenWrt Wiki.
Configuring Marvell Avastar® 88W8897 WiFi module
See Configuring wireless network on ESPRESSObin.
LuCI
Network configuration shown above can be also made using LuCI, the default web user interface for OpenWrt. In order to use LuCI, it needs to be enabled and compiled. While in the OpenWrt directory, invoke menuconfig:
user@laptop:/opt/openwrt/openwrt-dd$ make menuconfig
Go to the LuCI menu and for base packages select the luci package under Collections submenu :
LuCI ---> 1. Collections ---> <*> luci
LuCI is quite modular and has a large number of additional modules which can be selected if needed.
Once the new image is built and flashed onto ESPRESSObin, LuCI can be accessed through the browser by typing the IP address of the board (192.168.1.1 by default) in the URL bar.