raspberry pi installation without keyboard / mouse and hostapd access point configuration

As my home gateway I am using Raspberry PI Model B Raspberry PI Model B, which serves as gateway between internal home network and internet. I configured it to have three network interfaces, it comes with one RJ-45, I turned one usb port using USB to RJ45 another one, and second USB port is used for wireless adapter as I use it at same time as wireless access point.

Recently memory card inside it died and I had to rebuild all stuff with new card, and luckily ( at least one good thing ) same day Raspbian Jessie was released so it saved my time to do upgrade to it. If you want to download Respbian Jessie, go at this link download raspbian I will not go here in details how to transfer image to card, but tl;dr, you will need to dd it

First annoying thing when it comes to Raspberry PI and using it in my opinion is that you have to have keyboard and HDMI cable in order to connect it to see screen and proceed with configuration. I find it really bad, so I was started looking around ( at this stage I already dd-ed image to card! ) how to avoid this. You will need to do two things in order to boot Raspbian directly and connect to it via SSH without connecting to it directly.

#mkdir a
#mount /dev/sdb1 a 

Edit this file and add there ip address you want it bring up on boot. In my case I have inside my home network IP addresses from 192.168.11.X segment, so in my case I had below ( assuming my other machine had address from same network )

cat cmdline.txt
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait ip=192.168.11.115

Important: Ensure in above file, that ip=x.x.x.x is in same line as rest of options in cmdline.txt file, if you have new line – it will fail during boot and ip will not be up.
Unmount first partition, and mount second

 # mount /dev/sdb2 a

On this partition,edit /usr/bin/raspbi-config and change

INTERACTIVE=True

to

INTERACTIVE=False

this will ensure that there will not be interactive menu when RPI starts, it will proceed with booting, with this you will get chance to connect via ssh to machine, and you can run raspbi-config ( do not forget to revert Interactive=True ) later.

From this point, you should have access to system, connect using default user pi and password raspberry

Now, I needed to configure Edimax EW-7811un Edimax EW-7811un – Edimax web site to turn my raspberry pi into access point for wireless network. This card needs small hacking.

First, get driver from Edimax web, here is link Edimax EW-7811un driver

You will need to build driver, the whole process is listed below

#mkdir /home/edimax
#cd /home/edimax

#wget www.edimax.com/edimax/mw/cufiles/files/download/Driver_Utility/transfer/Wireless/NIC/EW-7811Un/EW-7811Un_Linux_driver_v1.0.0.5.zip
#unzip EW-7811Un_Linux_driver_v1.0.0.5.zip
#cd EW-7811Un_Linux_driver_v1.0.0.5/
#unzip EW-7811Un_USB_linux_v4.0.2_9000.20130911.zip
#cd RTL8188C_8192C_USB_linux_v4.0.2_9000.20130911/wpa_supplicant_hostapd
#tar -xaf wpa_supplicant_hostapd-0.8_rtw_r7475.20130812.tar.gz
#cd wpa_supplicant_hostapd-0.8_rtw_r7475.20130812/wpa_supplicant
#make; make install

Next you will need to edit /etc/init.d/hostapd and change binary path to DAEMON_SBIN=/usr/local/bin/hostapd

configure /etc/hostapd/hostapd.conf to something like

#cat /etc/hostapd/hostapd.conf 
interface=wlan0
ssid=
channel=1
wmm_enabled=0
wpa=1
hw_mode=g
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
auth_algs=1
macaddr_acl=0 
wpa_passphrase=

configure /etc/network/interfaces

#cat /etc/network/interfaces, in my case I have
auto lo

iface lo inet loopback
iface eth0 inet static
	address 192.168.XX.XXX
	netmask 255.255.255.240

auto wlan0
allow-hotplug wlan0
iface wlan0 inet static
	address 10.10.XX.XX
	netmask 255.255.255.0

I also configured dhcpd server to serve ip addresses to devices on wlan

# aptitute install isc-dhcp-server
# cat /etc/dhcp/dhcpd.conf

cat /etc/dhcp/dhcpd.conf 
option domain-name "elvirhome.local";
option domain-name-servers 10.10.10.1;

subnet 10.10.10.0 netmask 255.255.255.0 {
  range 10.10.10.2 10.10.10.10;
  option routers 10.10.10.1;
}

#cat /etc/default/isc-dhcp-server
INTERFACES="wlan0"

I also configured bind for my internal network, I used instructions from Debian bind9 configuration with addition of some local tweaks, but instructions at this link are good to make you running bind in matter of minutes!

After this, start isc-dhcp-server,bind and hostapd services

#systemctl start isc-dhcp-server.service ; systemctl start hostapd.service; systemctl start bind9 

I have custom iptables firewall rules script, obviously you will need to write your custom to allow traffic from internal network to outside network.That would be nice homework!I might publish mine… but will need to edit it and make readable
At this stage,services should be up and running and if you try to connect from your phone, you will see wireless network with ID specified above,authenticate with password you specified, if all is ok, then connection to outside world via raspberry pi should work like a charm.

Advertisements

#edimax-ew-7811un, #hostapd, #linux, #raspberry-pi, #wirelles-connection