Buildroot - initial network configuration

Here we will setup an initial network configuration for Buildroot on your ESPRESSObin. As mentioned in Quick User Guide, let us start by setting up ESPRESSObin as a network client with no routing. You can skip this step if you have already configured it.

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. In the Buildroot shell insert the following commands to configure eth0 interface to use DHCP for obtaining an IP address:

#ifconfig eth0 up
#dhclient wan
[  162.790397] IPv6: ADDRCONF(NETDEV_UP): wan: link is not ready
[  164.323110] dsa dsa@0 wan: Link is Down
[  165.331782] dsa dsa@0 wan: Link is Up - 100Mbps/Full - flow control rx/tx
[  165.338761] IPv6: ADDRCONF(NETDEV_CHANGE): wan: link becomes ready

using ifconfig command we can verify that the IP address has been obtained, e.g.:

# ifconfig 
eth0      Link encap:Ethernet  HWaddr F0:AD:4E:03:5F:30  
          inet6 addr: fe80::f2ad:4eff:fe03:5f30%8270400/64 Scope:Link
          RX packets:460 errors:0 dropped:0 overruns:0 frame:0
          TX packets:32 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:532 
          RX bytes:38118 (37.2 KiB)  TX bytes:3456 (3.3 KiB)

lo        Link encap:Local Loopback  
          inet addr:  Mask:
          inet6 addr: ::1%8272704/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:2 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:140 (140.0 B)  TX bytes:140 (140.0 B)

wan       Link encap:Ethernet  HWaddr F0:AD:4E:03:5F:30  
          inet addr:  Bcast:  Mask:
          inet6 addr: fe80::f2ad:4eff:fe03:5f30%8271552/64 Scope:Link
          RX packets:287 errors:0 dropped:0 overruns:0 frame:0
          TX packets:22 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:17784 (17.3 KiB)  TX bytes:1948 (1.9 KiB)

we can also ping any IP address on the web to check our Internet connection, e.g.

# ping www.google.com
PING www.google.com ( 56 data bytes
64 bytes from seq=0 ttl=54 time=49.404 ms
64 bytes from seq=1 ttl=54 time=48.036 ms
64 bytes from seq=2 ttl=54 time=48.721 ms
--- www.google.com ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 48.036/48.720/49.404 ms



To enable routing in Buildroot we again (as we did in Ubuntu - initial network configuration) need to enable NETFILTER/IPTABLES/NAT options in kernel configuration, so refer to that page if your kernel does not have them enabled.

When these options are included, we additionally need to enable dnsmasq in Buildroot source tree. Head to where you have setup Buildroot and issue make menuconfig:

espressobin@buildserver:~/buildroot$ make menuconfig

and in there search for and select BR2_PACKAGE_DNSMASQ:

Type  : boolean
Prompt: dnsmasq
    -> Target packages
(1)   -> Networking applications
  Defined at package/dnsmasq/Config.in:1

once dnsmasq is enabled, save and exit menuconfig. Now we rebuild Buildroot with:

espressobin@buildserver:~/buildroot$ make -j4

To copy dnsmasq binary to a microSD card already containing Buildroot we would mount the SD card and copy the binary located in /output/target/usr/sbin/ from our Buildroot source tree to /usr/sbin/ directory on our SD card:

espressobin@buildserver:~/buildroot/output/target/usr/sbin$ sudo cp dnsmasq /mnt/sdcard/usr/sbin/

Alternatively, you can replace your entire root file system on the SD card by again extracting rootfs.tar.gz from output/images/ directory as was shown in Boot from removable storage - Buildroot page. Also make sure to transfer kernel images with NETFILTER/NAT/IPTABLES options enabled to the SD card as well.

Exit the directory and unmount the SD card:

espressobin@buildserver:/mnt/sdcard$ cd
espressobin@buildserver:/$ sudo umount /mnt/sdcard

and insert the SD card in the microSD card slot in your ESPRESSObin. Follow booting procedure from Boot from removable storage - Buildroot. Once you get to Buildroot console and have the basic network client configuration from above set up, you can run the commands below (or put them in a file and run as script) to get routing functionality:

brctl addbr br0
ifconfig eth0 up
ifconfig wan up
ifconfig lan0 up
ifconfig lan1 up
brctl addif br0 lan0
brctl addif br0 lan1
ifconfig br0
dnsmasq --interface=br0 --dhcp-range=br0,,,12h
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o wan -j MASQUERADE
dhclient wan