Automation of everything …

Automation of everything …

VirtualBox admin using phpvirtualbox (2017)

Following on from my previous guide VirtualBox admin using phpVirtualBox, Smart Guide Pty Ltd have taken over support and released a new version ūüôā

This guide explains how you can run administer VirtualBox 5.2 on a headless Ubuntu server. Normally you use the VirtualBox GUI to manage your virtual machines, but a server does not have a desktop environment.

1. Preliminary:
– Install your server environment (I chose Ubuntu)
– Install VirtualBox 5.2 (VirtualBox 5.2 on Ubuntu 17.10)

2 Start VirtualBox Web Services
Create the file /etc/default/virtualbox and put the line VBOXWEB_USER=vbox in it (so that the VirtualBox SOAP API which is called vboxwebsrv runs as the user vbox):

echo '# virtualbox defaults file' | sudo tee /etc/default/virtualbox
echo 'VBOXWEB_USER=vbox' | sudo tee -a /etc/default/virtualbox

Next create the system startup links for vboxwebsrv and start it:
sudo systemctl enable vboxweb-service
sudo systemctl start vboxweb-service

3 Install Apache2
We need a web server with PHP support to serve phpVirtualBox. Install Apache and PHP as follows:
sudo apt -y install apache2 libapache2-mod-php7.1 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libapr1 php7.1-common php7.1-mysql php7.1-soap php-pear wget

Restart Apache:
sudo systemctl restart apache2.service

4 Download and configure phpvirtualbox

cd /usr/share/
sudo git clone https://github.com/phpvirtualbox/phpvirtualbox.git
cd phpvirtualbox
sudo cp config.php-example config.php

Edit config.php:
– update username/password to match headless system user already created
– set Display guest additions version of a running VM on its Details tab to true
– Enable startup / shutdown configuration.
– Enable advanced configuration items

Copy site details to Apache2

sudo cp phpvirtualbox.conf /etc/apache2/conf-available/

Modify Apache configuration to allow remote connections:
sudo vi /etc/apache2/conf-available/phpvirtualbox.conf
– Comment out the line “Require local” (line 11)
– Also at the time of my installation there is a bug in the config file, change line 6 to read “DirectoryIndex index.html”

Enable the phpVirtualBox web site:
sudo a2enconf phpvirtualbox

Restart Apache2:
sudo service apache2 reload

4. Clean up and reboot
As good practice I always update and clean up before rebooting when installing new software

sudo apt update && sudo apt upgrade
sudo apt clean && sudo apt autoclean && sudo apt autoremove

sudo reboot now

5. Check the system
That’s it already – you can now open a browser and access phpVirtualBox as follows:
eg: http://host.lab.local/phpvirtualbox/
or By IP:
eg: http://192.168.1.1/phpvirtualbox/

Default logon is admin:admin

6. Change password:
File Menu -> Change Password

VirtualBox 5.2 headless on Ubuntu 17.10

Following on from my previous guide VirtualBox Headless on Ubuntu 16.04 I have now updated this for Ubuntu 17.10 as I got a new server ūüôā

This guide explains how you can run virtual machines with VirtualBox 5.2 on a headless Ubuntu 17.10 server. Normally you use the VirtualBox GUI to manage your virtual machines, but a server does not have a desktop environment. Fortunately, VirtualBox comes with a tool called VBoxHeadless that allows you to connect to the virtual machines over a remote desktop connection, so there’s no need for the VirtualBox GUI.

1 Preliminary Note
I have tested this on a freshly installed Ubuntu 17.10 server (host system) where I’m logged in as a normal user.

The only option chosen during the install was SSHD Server.

After initial boot, I usually add a few standard things:

sudo apt-get install -y vim-nox

Ensure everything is updated:

sudo apt update && sudo apt upgrade && sudo apt dist-upgrade

Ensure everything is tidied up:

sudo apt clean && sudo apt autoclean && sudo apt autoremove

Install Linux headers:
(The dkms package ensures that the VirtualBox host kernel modules are properly updated if the Linux kernel version changes.)

sudo apt -y install gcc make linux-headers-$(uname -r) dkms

2 Installing VirtualBox
To install VirtualBox 5.2 on our Ubuntu 17.10 server …

Download the VirtualBox public key:

wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add -
wget -q https://www.virtualbox.org/download/oracle_vbox.asc -O- | sudo apt-key add -

Add VirtualBox sources to apt :

sudo sh -c 'echo "deb http://download.virtualbox.org/virtualbox/debian $(lsb_release -sc) contrib" | sudo tee /etc/apt/sources.list.d/virtualbox.list'

Unfortunately at the time of writing there is no Artful release of VirtualBox 5.2, so I had to use the one from Zesty.

To do this I modified the “/etc/apt/sources.list.d/virtualbox.list” file by commenting out the exiting line and adding

deb http://download.virtualbox.org/virtualbox/debian zesty contrib

… and update our package database:
sudo apt-get update

Install VirtualBox 5.2:
sudo apt install -y virtualbox-5.2

3 Installing VirtualBox Extensions
VirtualBox has “extension packs” that provide functionality like remote desktop connection support (VRDP).
VBOXVERSION=`VBoxManage --version | sed -r 's/([0-9])\.([0-9])\.([0-9]{1,2}).*/\1.\2.\3/'`
wget -q -N "http://download.virtualbox.org/virtualbox/$VBOXVERSION/Oracle_VM_VirtualBox_Extension_Pack-$VBOXVERSION.vbox-extpack"
sudo VBoxManage extpack install --replace Oracle*.vbox-extpack

Agree to the terms and install.

8. Add headless user
– Add a vbox user
sudo adduser vbox
– Add the user to the vboxusers group:
sudo adduser vbox vboxusers

9. Configure autostart
Modify the file /etc/default/virtualbox and add a few variables.

VBOXAUTOSTART_DB which contains an absolute path to the autostart database directory and
VBOXAUTOSTART_CONFIG which contains the location of the autostart config settings.


echo 'VBOXAUTOSTART_DB=/etc/vbox' | sudo tee -a /etc/default/virtualbox
echo 'VBOXAUTOSTART_CONFIG=/etc/vbox/autostart.cfg' | sudo tee -a /etc/default/virtualbox

Create the autostart.cfg file
NB: You may need to change the username or add others, depending on your installation.

echo '# Default policy is to deny starting a VM, the other option is "allow".' | sudo tee /etc/vbox/autostart.cfg
echo 'default_policy = deny' | sudo tee -a /etc/vbox/autostart.cfg
echo '# Create an entry for each user allowed to run autostart' | sudo tee -a /etc/vbox/autostart.cfg
echo 'vbox = {' | sudo tee -a /etc/vbox/autostart.cfg
echo 'allow = true' | sudo tee -a /etc/vbox/autostart.cfg
echo '}' | sudo tee -a /etc/vbox/autostart.cfg

If you are the only user you can just add the line default_policy = allow to the autostart.cfg file.

Set permissions on directory to the vboxuser group and make sure users can write to the directory as well as sticky bit.
sudo chgrp vboxusers /etc/vbox
sudo chmod 1775 /etc/vbox

Add each of the users to the vboxusers group.
sudo usermod -a -G vboxusers USERNAME
(replace USERNAME with the username)
NOTE: If you have changed group permissions for the current user, log out and back in again to refresh the permissions.

Create start/stop files
cd /etc/vbox
sudo touch vbox.start
sudo touch vbox.stop

And change owner with:
sudo chown vbox:vboxusers vbox.start
sudo chown vbox:vboxusers vbox.stop

Enable autostart/autostop:
Every user who wants to enable autostart for individual machines has to set the path to the autostart database directory with

su vbox VBoxManage setproperty autostartdbpath /etc/vbox

and enable autostart/autostop for an individual VM with
NB: The VM needs to be shut down for this command
VBoxManage modifyvm gitlab --autostart-enabled on --autostop-type acpishutdown

NB: autostop types: disabled, savestate, poweroff, acpishutdown
This will create a myuserid.start file in /etc/vbox directory

Now restart the vboxautostart-service to read in the changes.
sudo service vboxautostart-service restart

9. Clean up and reboot
As good practice I always update and clean up before rebooting when installing new software

sudo apt update && sudo apt upgrade
sudo apt clean && sudo apt autoclean && sudo apt autoremove

sudo reboot now

VirtualBox install/update Guest Additions

1. Make guest additions iso available on host server
VBoxManage storageattach "" --storagectl IDE --port 0 --device 0 --type dvddrive --medium /usr/share/virtualbox/VBoxGuestAdditions.iso

2. Mount cdrom and install/update guest additions in guest
sudo mount /dev/cdrom /media/cdrom
sudo bash /media/cdrom/VBoxLinuxAdditions.run
sudo umount /media/cdom

3. Reboot guest to ensure everything is loaded.
sudo reboot now

4. Remove CD iso
VBoxManage storageattach "" --storagectl IDE --port 0 --device 0 --medium "none"

VirtualBox headless VM autostart

1. Modify the file /etc/default/virtualbox and add a few variables.

VBOXAUTOSTART_DB which contains an absolute path to the autostart database directory and
VBOXAUTOSTART_CONFIG which contains the location of the autostart config settings.


echo 'VBOXAUTOSTART_DB=/etc/vbox' | sudo tee -a /etc/default/virtualbox
echo 'VBOXAUTOSTART_CONFIG=/etc/vbox/autostart.cfg' | sudo tee -a /etc/default/virtualbox

2. Create the autostart.cfg file
NB: You may need to change the username or add others, depending on your installation.

echo '# Default policy is to deny starting a VM, the other option is "allow".' | sudo tee /etc/vbox/autostart.cfg
echo 'default_policy = deny' | sudo tee -a /etc/vbox/autostart.cfg
echo '# Create an entry for each user allowed to run autostart' | sudo tee -a /etc/vbox/autostart.cfg
echo 'vbox = {' | sudo tee -a /etc/vbox/autostart.cfg
echo 'allow = true' | sudo tee -a /etc/vbox/autostart.cfg
echo '}' | sudo tee -a /etc/vbox/autostart.cfg

If you are the only user you can just add the line default_policy = allow to the autostart.cfg file.

3. Clean up permissions
Set permissions on directory to the vboxuser group and make sure users can write to the directory as well as sticky bit.
sudo chgrp vboxusers /etc/vbox
sudo chmod 1775 /etc/vbox

Add each of the users to the vboxusers group.
sudo usermod -a -G vboxusers USERNAME
(replace USERNAME with the username)
NOTE: If you have changed group permissions for the current user, log out and back in again to refresh the permissions.

4. Create start/stop files
cd /etc/vbox
sudo touch vbox.start
sudo touch vbox.stop

And change owner with:
sudo chown vbox:vboxusers vbox.start
sudo chown vbox:vboxusers vbox.stop

4. Enable autostart/autostop
Every user who wants to enable autostart for individual machines has to set the path to the autostart database directory with

VBoxManage setproperty autostartdbpath /etc/vbox

and enable autostart/autostop for an individual VM with
NB: The VM needs to be shut down for this command
VBoxManage modifyvm gitlab --autostart-enabled on --autostop-type acpishutdown

NB: autostopo types: disabled, savestate, poweroff, acpishutdown
This will create a myuserid.start file in /etc/vbox directory

Now restart the vboxautostart-service to read in the changes.
sudo service vboxautostart-service restart

5. Reboot and test
Reboot your system and your VM(s) should start

VirtualBox admin using phpvirtualbox

1 Add a vbox user
sudo adduser vbox
Now we must add the user to the vboxusers group:
sudo adduser vbox vboxusers

2 Start VirtualBox Web Services
Create the file /etc/default/virtualbox and put the line VBOXWEB_USER=vbox in it (so that the VirtualBox SOAP API which is called vboxwebsrv runs as the user vbox):

echo '# virtualbox defaults file' | sudo tee /etc/default/virtualbox
echo 'VBOXWEB_USER=vbox' | sudo tee -a /etc/default/virtualbox

Next create the system startup links for vboxwebsrv and start it:
sudo systemctl enable vboxweb-service
sudo systemctl start vboxweb-service

3 Install Apache2
We need a web server with PHP support to serve phpVirtualBox. Install Apache and PHP as follows:
sudo apt-get -y install apache2 libapache2-mod-php7.0 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libapr1 php7.0-common php7.0-mysql php7.0-soap php-pear wget

Restart Apache:
sudo systemctl restart apache2.service

4 Download and install phpvirtualbox
I want to serve phpVirtualBox from Apache’s default virtual host with the document root /var/www/html (I will install it in /var/www/html/phpvirtualbox):
cd /var/www/html

sudo wget http://downloads.sourceforge.net/project/phpvirtualbox/phpvirtualbox-5.0-5.zip

Ensure zip/unzip are installed:
sudo apt install -y zip unzip

Unzip phpVirtualBox and rename the phpvirtualbox-5.0-5 to phpvirtualbox for ease of use:
sudo unzip phpvirtualbox-5.0-5.zip

Create a link to our served directory so we preserve original packaging for easier upgrades
sudo ln -s phpvirtualbox-5.0-5 phpvirtualbox

Next go to the /var/www/phpvirtualbox/ directory…
cd /var/www/html/phpvirtualbox/

… and create the file config.php by copying it from config.php-example:
sudo cp config.php-example config.php

Open config.php and fill in the password you created earlier for the vbox system user:
sudo vi config.php

[...]
/* Username / Password for system user that runs VirtualBox */
var $username = 'vbox';
var $password = 'pass';
[...]

Clean up Apache2 file privileges:
sudo chown www-data:www-data -R .

4. Clean up and reboot
As good practice I always update and clean up before rebooting when installing new software
sudo apt update
sudo apt upgrade -y
sudo apt autoremove -y
sudo apt autoclean -y

sudo reboot now

5. Check the system
That’s it already – you can now open a browser and access phpVirtualBox as follows:
eg: http://www.example.com/phpvirtualbox/
or By IP:
eg: http://192.168.1.1/phpvirtualbox/

Default logon is admin:admin

Raspberry Pi Nukkit

sudo mkdir /home/nukkit

sudo adduser nukkit

sudo chown -R nukkit:nukkit /home/nukkit/

su – nukkit

wget http://ci.mengcraft.com:8080/job/nukkit/lastSuccessfulBuild/artifact/target/nukkit-1.0-SNAPSHOT.jar

java -jar nukkit-1.0-SNAPSHOT.jar

And follow through the initial setup.

test it ..

sudo update-rc.d nukkit defaults

 

Raspberry PI Mini DLNA Server

how to make a raspberry pi media server using MiniDLNA. This will allow you to stream your photos, videos and music around your network.

Step 1: What you will need

  • Raspberry pi (I’m using a model A)
  • Another computer if you want to SSH into your pi
  • Hard drive with your media
  • SD card for the raspberry pi operating system
  • Raspberry pi wifi dongle (you can also use Ethernet)\
  • A power supply for the raspberry pi (a minimum of 1 AMP and 5 Volts for the Raspberry Pi model B)
  • A powered USB hub

Step 2: Updating and Installing

To begin we can SSH into our raspberry pi by using a program like putty. After we have done this I recommend updating and upgrading your raspberry pi. You can do this by using the following commands.

sudo apt-get update

sudo apt-get upgrade

Once this is finished we can install the media server software. Use the next command to do this.

sudo apt-get install minidlna

After you enter this command you will probably be asking if you want to continue. Just press y and then enter. Once that has finished installing it is time for the next step.

Step 3: Connecting the hard drive

Before we can start our media server we need some media of course. So what we are going to do is make it so that our media hard drive is mounted on start-up.

To do this the first thing we need to do is plug in our media drive. Make sure you plug it into the powered USB hub and not directly into the raspberry pi because sometimes that can cause problems. Once you have done this we need to go back to putty or whatever SSH client you are using and type in:

sudo fdisk -l

What this does is it shows use important information about the drives that are connected to our raspberry pi. In the picture I have circled the name of my drive in white. In my case it was /dev/sda1. I know this because where I have circled in green says that the drive /dev/sda has 1000 GB which is the size of my drive. In red I have circled the format of the drive which we will need in the next step. You are going to need to know the name of your drive and the format of your drive in the following steps so it is probably a good idea to write them down somewhere.

Step 4: Mounting the drive on startup

We need to have our media drive to be mounted on startup so that we can access its contents. To do this we are going to need to make a folder to mount it to. You can do that by using this command:

sudo mkdir /media/HDD

What this command does is makes a folder called HDD in the media directory. So once we have made this folder we need to give it read write permissions. We can do this by using this command:

sudo chmod 777 /media/HDD

This command command tells the folder HDD that it has all permission. This means that it has read and write permissions which is what we wanted.

Now we need to edit the fstab file. This is the file that the raspberry pi operating system refers to when it is looking to see which dives to mount at startup so we need to put our media drive in that file. We can do that by using the command:

sudo nano /etc/fstab

Once in this file you will notice that it is not the same as Microsoft Word which you might be familiar to. You need to use the arrow keys to navigate around. So go to the bottom of this file and you are going to add this line:

/dev/sda1    /media/HDD   vfat    defaults     0        2

Ok so the line that you just added might be a bit confusing so I will try to explain it. The first part where is says /dev/sda1 is the is the name of the hard drive that you want to add. Remember from the previous step. The next part is the place where you are going to mount it to. Then we have the format of the hard drive. In this case it is fat32. And finally the 0 and 2 at the end are permissions.

Now it you reboot the raspberry pi:

sudo reboot

and move into the directory /media/HDD

cd /media/HDD

And run this command:

ls

You should be able to see all the files on your hard drive.

Step 5: Configuring MiniDLNA

To start configuring MiniDLNA we need to edit the config file. This can be done by using this command:

sudo nano /etc/minidlna.conf

Once you have that file open we are going to need to change that part that looks like this:

# * “A” for audio (eg. media_dir=A,/var/lib/minidlna/music)
# * “P” for pictures (eg. media_dir=P,/var/lib/minidlna/pictures)
# * “V” for video (eg. media_dir=V,/var/lib/minidlna/videos)

to this:

media_dir=A,/media/HDD/Music
media_dir=P,/media/HDD/Pictures
media_dir=V,/media/HDD/Movies

and this:

# Name that the DLNA server presents to clients.
#friendly_name=

to this:

# Name that the DLNA server presents to clients.
friendly_name=RASPI MINIDLNA

and this:

media_dir=/var/lib/minidlna

#db_dir=/var/lib/minidlna

to this:

media_dir=/media/HDD

db_dir=/media/HDD

In the line above where I have put RASPI MINIDLNA can be whatever you want.

Then press control x to exit and press y if it asks if you want to “save modified buffers” then press enter to confirm.

Now that we have configured MiniDLNA we have to refresh it. To do this you can run the following commands:

sudo service minidlna restart
sudo service minidlna force-reload

Now if you hop back onto a windows computer or any Upnp compatible device you should be able to see your server. On window if you click on start then computer then on the left hand side click on network you should be able to see your raspberry pi Minidlna server called RASPI MINIDLNA under the media devices section.

Step 6: Your done!

Congratulations you have successfully created a raspberry pi MiniDLNA server.

 

Raspberry PI RDP

How to Setup Remote Desktop from a Windows Machine to your Raspberry Pi – Step by Step Guide

As I mentioned in the previous post I recently found the need to be able to remote desktop to my Raspberry Pi.  This is a step by step guide on how to set it up.

What does this guide help me do?

It will let you control your Raspberry Pi from another machine.  Meaning that the Raspberry Pi will not need to be connected to a monitor, keyboard or mouse.

Before we get started a few clarifications:

  • This guide is to set up remote desktop from another computer on your home network to your Raspberry Pi.
  • It does not explain how to connect to your Pi from outside your home network.
  • The instructions are for connecting from a windows machine.

What do I need before I get started?

  1. A Raspberry Pi running the latest¬†Raspbian ‚Äúwheezy‚ÄĚ image (at time of writing¬†2012-09-18-wheezy-raspbian.zip). ¬†It should work with other Linux versions too, but that is the one I have tested with.
  2. The Raspberry Pi should be connected to your home network and have a internet connection.
  3. A second machine running windows that you want to use connect from which is connected to the same home network.

The Steps

Raspberry Pi Setup

So first we need to install some software on¬†the¬†Raspberry Pi, but don’t worry it is very easy!
  1. Start up your Pi to the terminal prompt.
  2. Type the following command “sudo apt-get install xrdp”
  3. If¬†promoted¬†enter your password (the default is “raspberry”)
  4. Type “Y” and press enter.
  5. This is now installing xrdp onto your Pi which is the software we are going to use for the remote desktop connection.  Wait for it to complete.
  6. Restart your Pi.  We are going to check that xrdp is going to start up automatically.
  7. When your Pi has booted to the command prompt look for [ ok ] Starting Remote Desktop Protocol server : xrdp sesman.  This shows you that xrdp is installed and automatically starting up on start up of your Pi
  8. The last step is to make a note of the IP address of your Pi which should also be displayed on the start up screen.  In my case below it is 192.168.1.9.  This is the address of your Pi on your network and what we will use to connect to your Pi from the second machine.

Second Machine Setup

1. Launch Remote Desktop Connection which can be found at Start->All Programs->Accessories->Remote Desktop Connection
2. Type in the IP Address for your Pi which you noted above.
3. Click Connect (you may get a security warning at this stage just click OK if you do.  After all it is your Pi on your network so nothing to worry about security wise).
4. Leave the Module on the default of sesman-Xvnc and enter your username and password for your Pi. ¬†(The default is pi and raspberry if you haven’t¬†changed¬†them).
5. Click OK and after a few moments you should be greeted my your Raspberry Pi’s desktop!
6. ¬†When you are finished simply¬†log-out¬†from the Pi’s¬†desktop.

 

Raspberry PI NAT (for WiFi Router)

Configure Network Address Translation

Setting up NAT will allow multiple clients to connect to the WiFi and have all the data ‘tunneled’ through the single Ethernet IP. (But you should do it even if only one client is going to connect)

Run

sudo vi /etc/sysctl.conf

uncomment this line (or scroll to the bottom and add if it is not there!)

net.ipv4.ip_forward=1

Save the file. This will start IP forwarding on boot up.

To reload the file without rebooting .. 
sudo sysctl -p

Run the following commands to create the network translation between the ethernet port eth0 and the wifi port wlan0

sudo iptables t nat A POSTROUTING o eth0 j MASQUERADE

sudo iptables A FORWARD i eth0 o wlan0 m state state RELATED,ESTABLISHED j ACCEPT

sudo iptables A FORWARD i wlan0 o eth0 j ACCEPT

You can check to see whats in the tables with

sudo iptables -t nat -S
sudo iptables -S

To make this happen on reboot (so you don’t have to type it every time) run

sudo sh -c “iptables-save > /etc/iptables.ipv4.nat”

run

sudo vi /etc/network/interfaces

and add

up iptables-restore < /etc/iptables.ipv4.nat

to the very end

Raspberry PI WiFi Router (hostapd)

Check WLAN drivers

Check that your Pi sees your USB WiFi dongle

lsusb

If it is a Realtek chipset RTL8192EU, you will see something like:

Bus 001 Device 004: ID 0bda:818b Realtek Semiconductor Corp.

the 818b indicates the RTL8192EU chipset.

Unfortunately this chipset is currently not ‘officially’ supported by Rasbian, but MrEngman over at raspberrypi.org maintains a good library of drivers (https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=127214).

 

First be sure of the kernel version you are running:

uname -a

resulted, for me in,

4.4.13-v7+ #894

So i grabbed the driver and installed it with:

wget https://dl.dropboxusercontent.com/u/80256631/8192eu-4.4.13-v7-894.tar.gz
tar xzf 8192eu-4.4.13-v7-894.tar.gz sudo 
./install.sh

sudo apt-get install hostapd

 

Set up wlan0 for static IP

If you happen to have wlan0 active because you set it up, run

sudo ifdown wlan0


Next we will set up the wlan0 connection to be static and incoming. run

sudo vi /etc/network/interfaces to edit the file

Find the line auto wlan0 and add a # in front of the line, and in front of every line afterwards. If you don’t have that line, just make sure it looks like the screenshot below in the end! Basically just remove any old wlan0 configuration settings, we’ll be changing them up

Depending on your existing setup/distribution there might be more or less text and it may vary a little bit

Add the lines

allow-hotplug wlan0
iface wlan0 inet static
address 192.168.77.254
netmask 255.255.255.0
network 192.168.77.0
broadcast 192.168.77.255
#gateway 192.168.77.254
#wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf

Any other lines afterwards should have a # in front to disable them.

After that, re-enable the wlan0 interface and check if you have your IP set it up on interface

sudo ifup wlan0

sudo ifconfig wlan0
pi@nissanpi:~ $ ifconfig wlan0
wlan0 Link encap:Ethernet HWaddr e8:4e:06:13:f2:a9
 inet addr:172.16.77.254 Bcast:172.16.77.255 Mask:255.255.255.0
 inet6 addr: fe80::c318:331c:4663:3977/64 Scope:Link
 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
 RX packets:4311 errors:0 dropped:0 overruns:0 frame:0
 TX packets:8497 errors:0 dropped:0 overruns:0 carrier:0
 collisions:0 txqueuelen:1000
 RX bytes:369129 (360.4 KiB) TX bytes:9830120 (9.3 MiB)

pi@nissanpi:~ $

Configure Access Point

Now we can configure the access point details. We will set up a password-protected network so only people with the password can connect.

Create a new file by running

sudo vi /etc/hostapd/hostapd.conf

Paste the following in, you can change the text after ssid= to another name, that will be the network broadcast name. The password can be changed with the text after wpa_passphrase=

  1. # This is the name of the WiFi interface we configured above
    interface=wlan0
    
    # Use the nl80211 driver with the brcmfmac driver
    driver=nl80211
    
    # This is the name of the network
    ssid=Pi3-AP
    
    # Use the 2.4GHz band
    hw_mode=g
    
    # Use channel 6
    channel=6
    
    # Enable 802.11n
    ieee80211n=1
    
    # Enable WMM
    wmm_enabled=1
    
    # Enable 40MHz channels with 20ns guard interval
    ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]
    
    # Accept all MAC addresses
    macaddr_acl=0
    
    # Use WPA authentication
    auth_algs=1
    
    # Require clients to know the network name
    ignore_broadcast_ssid=0
    
    # Use WPA2
    wpa=2
    
    # Use a pre-shared key
    wpa_key_mgmt=WPA-PSK
    
    # The network passphrase
    wpa_passphrase=raspberry
    
    # Use AES, instead of TKIP
    rsn_pairwise=CCMP
    
Drivers:
РAdafruit wifi adapters driver=rtl871xdrv (may also require a specific hostapd app!)
РMany others (including RT5370) driver=nl80211
To view your USB adaptors:
sudo lsusb
pi@nissanpi:~ $ sudo lsusb
Bus 001 Device 006: ID 05ac:0256 Apple, Inc.
Bus 001 Device 004: ID 148f:5370 Ralink Technology, Corp. RT5370 Wireless Adapter
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp. LAN9500 Ethernet 10/100 Adapter / SMSC9512/9514 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
pi@nissanpi:~ $
 Now we will tell the Pi where to find this configuration file. Run

sudo vi /etc/default/hostapd

Find the line

#DAEMON_CONF=””
and edit it so it says
DAEMON_CONF=”/etc/hostapd/hostapd.conf”
Don’t forget to remove the # in front to activate it!Then save the file

Finally we can test the access point host! Run

sudo /usr/sbin/hostapd /etc/hostapd/hostapd.conf

To manually run hostapd with our configuration file. You should see it set up and use wlan0 then you can check with another wifi computer that you see your SSID show up. If so, you have successfully set up the access point.

You can try connecting and disconnecting from the Pi_AP with the password you set before (probably Raspberry if you copied our hostapd config), debug text will display on the Pi console but you won’t be able to connect through to the Ethernet connection yet.
Cancel the test by typing Control-C in the Pi console to get back to the Pi command line

Finishing up!

OK now that we know it works, time to set it up as a ‘daemon’ – a program that will start when the Pi boots.
Run the following command

sudo service hostapd start

you can always check the status of the host AP server with

sudo service hostapd status

To start the daemon services. Verify that they start successfully (no ‘failure’ or ‘errors’)
Then to make it so it runs every time on boot

sudo update-rc.d hostapd enable

© 2018: Forester IT | Easy Theme by: D5 Creation | Powered by: WordPress