November 18, 2019, 07:40:55 am

News:

Have you visited the Allwinner Chipset wiki? - http://linux-sunxi.org/


Cubieboard 2 Router with Wlan setup with Cubian r4

Started by vtlonn, December 31, 2013, 03:58:35 pm

Previous topic - Next topic

vtlonn

December 31, 2013, 03:58:35 pm Last Edit: December 31, 2013, 04:04:44 pm by vtlonn
This is a basic networking setup for any home or small office. You have an internet connection from your ISP and you want to share it for all your devices in your home. I know that there are loads of different solutions for this task, most of them much easier to set up and maintain, but then again that wasn't the point.

What i thought was this could be useful if you had to go to place where there is a Lan connection available, but no wifi or you would just want to set up your own private lan.

Most of the blogs posts I came across were meant for Raspberry Pi and none of them were about setting a router with both WLAN and LAN. I think I did make the exactly same setup with my Raspberry Pi, but I didn't document the whole process, but I'm pretty sure that this will work also on the Pi.

So the idea is the connect to the internet through eth0 and bridge eth1 and wlan0 together under connection bridge br0. Then we will add a dhcp server for the LAN and configure WLAN settings so that it will have WPA2 encryption.

I used for this setup the following components:

A Cubieboard 2 with Cubian R4 installed on microSD

D-Link DWA121 Wireless N 150 Micro Usb Wlan adapter

Apple USB Ethernet Adapter MC704ZM/A

So first I installed LXDE, because I intend to use Firestarter to config the DHCP-server and Firestarter needs to be started first time through the graphical interface and run the wizard in order to generate the config files. I haven't had the time or interest to learn Iptables and how to config it, so I have used Firestarter to add rules to Iptables  since it's simple to use and enabling NAT for connection sharing with the wizard is very easy.

So I have installed Cubian R4 on MicroSD card, added my own userprofile and removed the default user cubie

run:

sudo apt-get install xserver-xorg-core xinit xserver-xorg-video-sunximali sunxi-disp-test lxde

to install LXDE and X to Cubian and after installation has finished run to add yourself to the video usergroup.

sudo usermod -a -G video YOURUSERNAME

After this install hostapd:

sudo apt-get install hostapd

and create a configuration file for it:

sudo nano /etc/hostapd/hostapd.conf

and insert the following configs:


interface=wlan0

driver= nl80211

bridge=br0

ssid=YourSSID

hw_mode=g

channel=6

wmm_enabled=1

wpa=2

wpa_passphrase=Yourpassphares

wpa_key_mgmt=WPA-PSK

wpa_pairwise=TKIP

rsn_pairwise=CCMP

auth_algs=1

macaddr_acl=0


Now we need to install the software to allow us to bridge the internal network adapters eth1 and wlan0.
sudo apt-get install bridge-utils

Now edit the config for the for Hostapd that enables the AP mode for the wlan0.
sudo nano /etc/default/hostapd

find the line that says DAEMON_CONF="" and change it to the following:
DAEMON_CONF="/etc/hostapd/hostapd.conf"

then enter command to enable NAT:
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"

and edit sysctl.conf to enable NAT:
sudo nano /etc/sysctl.conf

and find the line net.ipv4.ip_forward and edit it to match the following:
net.ipv4.ip_forward=1

Now we need to install firestarter that has a GUI for creating and editing iptables rules. It's also pretty handy when you want to add new rules through command line since it's configuration files are in my opinion pretty easy to understand after having few examples to look at.
sudo apt-get install firestarter

We also need a DHCP server to give connected clients an IP address:
sudo apt-get install dhcp3-server

Firestarter is a bit outdated since it allows only root to access its configuration so we need to set a password for root:
sudo passwd root

Firestarter isn't updated on the fact that dhcp-server package has moved its config file to /etc/dhcp/ so we need to backup the default config file and make a symbolic to point to /etc/
Use the following commands to achieve this:
cd /etc/dhcp/
sudo mv dhcpd.conf dhcpd.conf.bak
sudo ln -s /etc/dhcpd.conf dhcpd.conf

Now restart your cubieboard and it should start straight to LXDE. If not use:
sudo service lightdm start

Now in LXDE start Firestarter. It will ask for root password. The setup wizard should start automatically.
Set eth0 as the adapter that connects to internet, Br0 as the adapter that is connected to the internal network. Check "enable internet connection sharing" and check "Enable DHCP for local network."
Set IP-range start 192.168.1.100 and
Ip-range end 192.168.1.254
nameserver 8.8.8.8

Now you can open ports for example for SSH server in Firestarter GUI. This is a good way for Firestarter to generate lines in it's own config so that you can easily see how you can open ports through the command line.
Firestarter configs are at /etc/firestarter/inbound/ , use sudo su first to access root.

Now open command prompt in LXDE and disable LightDM from starting automatically:
sudo update-rc.d lightdm disable

Now reboot Cubian from command line:
sudo reboot

Cubian should restart to command line with the new LAN setup.

I have also added this guide to my blog at blog.pelipalvelin.com

Please comment for any mistakes I made and I will edit them to the original post.
Thanks.

vandreus

i have trouble with firestarter, when i start it, it says that bridge br0 is not ready
i assume i have to create the bridge of wan0 and eth1, can you just explain how did you do.
i wanna follow your threat point by point, coz i have the same wifi dongle and i couldn't get it working as AP following other instructions.