"Play to open source" Bananapi r2--third article based on OPENWRT development of a simple router

Source: Internet
Author: User
Tags get ip

On an explanation of R2 's network port configuration, this article we use Bananapi R2 as an example to implement a simple router; what kind of function should a simple router have? The simplest of these three functions is wan+lan+ap.

First of all, the Wan+lan function, R2 has been the default, and then we use the Bridge (bridge) to build a wireless hotspot (Ap).

    • Open AP Mode on R2 mt6625 (wireless chip on R2)
Jack@jack:wmt_loader &-p/etc/firmware &echo A >/dev/wmtwifi &
    • Once opened, you can see that a virtual network port has been generated ap0
root@lede:/#ifconfig-aap0 Link encap:ethernet HWaddr Geneva: ,: A: 4a:ba: -Broadcast multicast MTU: theMetric:1RX Packets:0Errors0Dropped0Overruns:0Frame0TX Packets:0Errors0Dropped0Overruns:0Carrier0Collisions:0Txqueuelen: +RX Bytes:0(0.0B) TX Bytes:0(0.0B
    • Next, we need to create a wireless hotspot, here I use HOSTAPD (soft AP) way to create, here I extend the knowledge of HOSTAPD:
    for 802.11 802. 1x/wpa/wpa2/eap authenticators, RADIUS client, EAP server, and RADIUS authentication server. The current version supports Linux (Host AP, Madwifi, mac80211-based drivers) and FreeBSD (net80211). Simply put, HOSTAPD is a user The daemon for Space 1, the AP (access point) follows some of the IEEE's Network and security protocols. HOSTAPD official website: https://w1.fi/hostapd/HOSTAPD Related information: https://w1.fi/cgit/hostap/ PLAIN/HOSTAPD Callout 1: User space is relative to the kernel space to distinguish between, our usual operation is basically in the user space to do, simple understanding is our usual operation of the Linux system GUI, command line, Shell script, The C program that compiles and runs, and so on, is the behavior in user space. 
    • The following is a simple configuration of HOSTAPD:
Cat hostapd.conf Interface=ap0        #网口是ap0bridge=br-lan  #网桥是br-lanssid=bpi_r2          #SSID即无线信号的名称是BPI-r2driver=nl80211  #使用的驱动是nl80211 country_code  =Cnhw_mode =g                #使用的是2.4Gchannel=1                #信道是1wpa_key_mgmt=wpa-PSK     # Encryption algorithm wpa_passphrase=ledetest  #创建的无线AP密码  

For more information about the hostapd.conf file, please see here: w1.fi/cgit/hostap/plain/hostapd/hostapd.conf
    • After the configuration is complete, perform "hostapd-d hostapd.conf" to create the wireless hotspot:
root@lede:~# HOSTAPD-d hostapd.conf Configurationfile: hostapd.conf[6102.269958] Br-lan:port5(AP0) entered blocking state[6102.275130] Br-lan:port5(AP0) entered disabled state[6102.280499] Device Ap0 entered promiscuous mode[6102.285076] Br-lan:port5(AP0) entered blocking state[6102.290176] Br-lan:port5(AP0) entered forwarding stateap0:interface State uninitialized-country_updateusing interface ap0 with Hwaddr Geneva: ,: A: 4a:ba: -and SSID"BPI_R2"Ap0:interface State Country_update-Enabledap0:ap-enabled
    • Look at the print log, you can see the hot spot and create the success, next I use the Windows system notebook to connect:

The connection is successful, it seems that OpenWrt has already configured the DHCP service, here is a simple extension of the DHCP service:

DHCP (Dynamic Host configuration Protocol) dynamically hosts the protocol, in fact, simply speaking, is the device connected to the local area network, you can dynamically acquire a protocol to the IP.
If the DHCP service is not configured, the device will not get IP when it is connected to the LAN, and it will not be able to access the Internet.
    • Let's take a look at the DHCP service on R2:
root@lede:~#Cat/etc/config/DHCP config DNSMASQ #dnsmasq是一个轻量级的dhcp, DNS service option domainneeded'1'option Boguspriv'1'option Filterwin2k'0'option Localise_queries'1'option Rebind_protection'1'option Rebind_localhost'1'option Local'/lan/'option Domain'LAN'option Expandhosts'1'option Nonegcache'0'option authoritative'1'option Readethers'1'option Leasefile'/tmp/dhcp.leases'option Resolvfile'/tmp/resolv.conf.auto'option Nonwildcard'1'option LocalService'1'Config DHCP'LAN'Option Interface'LAN'option Start' -'option Limit' Max'option Leasetime'12h'option DHCPv6'Server'option RA'Server'Config DHCP'Wan'Option Interface'Wan'option Ignore'1'config ODHCPD'ODHCPD'option Maindhcp'0'option Leasefile'/TMP/HOSTS/ODHCPD'option Leasetrigger'/usr/sbin/odhcpd-update'option LogLevel'4'

At first glance, the DHCP configuration here is a bit daunting, but you don't have to worry too much, let's take a quick look at this DHCP configuration:

we'll skip DNSMASQ and ODHCPD for a moment, and we'll add a little explanation later. There are two interfaces configured here"LAN"And"Wan"For DHCP, both interfaces must also be in the/etc/config/defined in the network. The "WAN" configuration is simple enough to explain the configuration of the LAN:
Config DHCP'LAN'Option Interface'LAN'#必须是在/etc/config/option start defined in the network' -'#从x. x.x.100 Start assigning IP option limit' Max'#一共有150个IP, which means the configuration here is x.x.x. --x.x.x.249option Leasetime'12h'#最长连接时间 Option DHCPv6'Server' option RA'server '#服务定义的模式是IPv6 (RA & DHCPV6)

For more details, refer to this: openwrt.org/docs/guide-user/base-system/dhcp

Next I use the phone to connect, and then test R2 wireless network speed, of course, this speed is associated with the bandwidth of R2 connection, I am here;

It seems that the Internet speed is relatively fast; now we have successfully deployed a openwrt with basic routing capability on the R2.

Next someone may encounter this problem, my R2 shutdown or restart, before the configuration of the environment is not, but also reconfigure, there is no way to start after the boot to automatically configure the environment I want?

The answer is of course:

    • First create a script that launches the AP
Vim Setup. SH          #!/bin/&3-p/etc/firmware &sleep5 Echo A >/dev/wmtwifi &Sleep5-D hostapd.conf
    • And then add the setup.sh to the OpenWrt boot file.
root@lede:~# vim/etc/file/root/             #我的setup. SH is placed in the/root directory, so first enter the/root directory sleep  6               #这里sleep 6s is due to other services in the system init completed  . /setup. sh &0
    • And then set up a box, and then the antenna, that's what it means.

Now, a simple router product is complete. Finally, some people may ask, since is to do a router product, it is impossible to always use the command line to operate it, and then how to have a Web page to configure it.

That's right, to implement the Web page to the router configuration, here have to mention OpenWrt Good helper Luci, then next we will see what is Luci, and how to configure.

you are welcome to criticize correct, please indicate the source, thank you.

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: info-contact@alibabacloud.com 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.