Introduction: Raspberry Pi WAP FIle Server
Hello fellow instructors.
This tutorial is going to show you how to set up your raspberry pi as a wireless access point file server.
What you will need to know:
- How to use Terminal on linux and on another device (eg: a device with mac, windows or linux on it). If you do not know how to use terminal you can use this website to teach yourself http://linuxcommand.org/ .
- How to use nano text. Nano text is primarily a simple text edit software, where you use the arrow keys instead of your mouse. If you want to learn more about nano text you can click here http://www.howtogeek.com/howto/42980/the-beginners...
I used the following pages as a guide to create this tutorial:
https://learn.adafruit.com/setting-up-a-raspberry-...
and
Step 1: What You Will Need
Raspberry Pi model B+ (or B)- Ethernet is required (I will be using the model 2)
Ethernet cable
WiFi adapter (Not all WiFi adapters work)
SD Card (4GB or greater) with Raspbian on it. You can either DIY it or buy a ready-made Raspbian card
Power supply for your Pi & a Micro USB cable
A USB or Hard Drive
Another device that can access a Samba Sever (Eg: Mac, windows or a IPhone)
Step 2: Download the Software
First off you will need to install the software onto the Pi that will act as the 'hostap' (host access point) You need internet access so plug the ethernet cable into Pi and open Terminal and type into the
sudo apt-get update
This downloads the package lists from the repositories and updates them to get information on the newest versions of packages and their dependencies.
And then type
sudo apt-get install hostapd isc-dhcp-server
THis will download the packages for the host access point.
Step 3: Set Up the DHCP
Next we will edit /etc/dhcp/dhcpd.conf, a file that sets up our DHCP server - this allows wifi connections to automatically get IP addresses, DNS, etc.
Run this command to edit the file
sudo nano /etc/dhcp/dhcpd.conf
Find the lines that say
option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;
and change them to add a # in the beginning, commenting them out. Then find the lines that say
# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative;
And get rid of the # in front of the #authoritative so it will look like this
authoritative;
Scroll down to the bottom and type
subnet 192.168.42.0 netmask 255.255.255.0 { range 192.168.42.10 192.168.42.50; option broadcast-address 192.168.42.255; option routers 192.168.42.1; default-lease-time 600; max-lease-time 7200; option domain-name "local"; option domain-name-servers 8.8.8.8, 8.8.4.4;}
Save the file by typing in Control-X then Y then return, Then run this line
sudo nano /etc/default/isc-dhcp-server
and scroll down to INTERFACES="" and update it to say INTERFACES="wlan0"
close and then save the file
Step 4: Set Up Wlan0 for Static IP
Next we will set up the wlan0 connection to be static and incoming. run sudo nano /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
iface wlan0 inet static
address 192.168.42.1
netmask 255.255.255.0
After allow-hotplug wlan0 - see below for an example of what it should look like. Any other lines afterwards should have a # in front to disable them
Save the file (Control-X Y ) Assign a static IP address to the wifi adapter by running
sudo ifconfig wlan0 192.168.42.1
Step 5: 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 nano /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=
<pre>interface=wlan0<br>driver=rtl871xdrv ssid=Pi_AP hw_mode=g channel=6 macaddr_acl=0 auth_algs=1 ignore_broadcast_ssid=0 wpa=2 wpa_passphrase=Raspberry wpa_key_mgmt=WPA-PSK wpa_pairwise=TKIP rsn_pairwise=CCMP
Save as usual. Make sure each line has no extra spaces or tabs at the end or beginning. Now we will tell the Pi where to find this configuration file. Run sudo nano /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
Step 6: 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 nano /etc/sysctl.conf
Scroll to the bottom and add
net.ipv4.ip_forward=1
on a new line. Save the file. This will start IP forwarding on boot up
Also run
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
to activate it immediately
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<br>sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT<br>sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT<br>
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"<br>
then run
sudo nano /etc/network/interfaces
and add
up iptables-restore < /etc/iptables.ipv4.nat
to the very end
Step 7: First Time Running the WAP
Run
sudo /usr/sbin/hostapd /etc/hostapd/hostapd.conf
To manually run hostapd with the 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.
Now we are going to make it a program that will start when the Pi boots. Run the following commands
sudo service hostapd start sudo service isc-dhcp-server start
you can always check the status of the host AP server and the DHCP server with sudo service hostapd status
sudo service isc-dhcp-server status
To start the daemon services. Verify that they both start successfully (no 'failure' or 'errors')Then to make it so it runs every time on boot
sudo update-rc.d hostapd enable sudo update-rc.d isc-dhcp-server enable
Step 8: Connecting and Testing
Now that you have everything running, use another device to log into the wifi. If you can't connect at all, something is wrong with hostapd or you have entered code wrong.
Open command line or terminal on your computer and type ifconfig for mac/linux or ipconfig for windows. You should have IP address in the 192.168.42.10-50 range.
Now it is time to set up the file server.
Step 9: Preparing and Mounting the External Hard Drives
Back on your raspberry pi you will need to plug in a external hard drive or usb into the PI. To add in support to Rasbian for NTFS-formatted disks put in the line below into terminal.
sudo apt-get install ntfs-3g
This will take a minute or two for the packages to download, unpack, and install.
Next put in
sudo fdisk -l
When you type this you should see a min of two disk. The second disk should be the USB or hard drive that you have put in.
Before we can mount the drives we need to make a directory to the drives. To make this simple i will be making the name of the disk USBHDD1
Go into the command line and type
sudo mkdir /media/USBHDD1
After this you can now mount the external drive. In the command line enter:
sudo mount -t auto /dev/sda1 /media/USBHDD1
Now that we have mounted the drive. We can add in a specific directory to hold the folder.
Enter the command
sudo mkdir /media/USBHDD1/shares
Step 10: Downloading and Configuring Samba
Now you will have to install samba. Samba is software that can be run on a platform other than Microsoft Windows, for example, UNIX, Linux, IBM System 390, OpenVMS, and other operating systems. Samba uses the TCP/IP protocol that is installed on the host server. When correctly configured, it allows that host to interact with a Microsoft Windows client or server as if it is a Windows file and print server.
Type the following to install samba onto your Pi
sudo apt-get install samba samba-common-bin
When prompted to continue type Y and enter. Sit back and relax as everything unpacks and installs.
Once done installing Samba it is now time to edit the config file. Type in the command line :
sudo nano /etc/samba/smb.conf
next stop is to turn on user authentication for our samba storage, otherwise anyone with general access to our network (like guest Wi-Fi users) will be able to walk right in. Scroll down in the Samba config file until you get to the section that reads ####Authentication##### and remove the # symbol from the security = user line (by highlighting it with the cursor and pressing delete) to enable username/password verification for the Samba shares.
[Backup]<br>comment = Backup <br>Folderpath = /media/USBHDD1/shares<br>valid users = @users force group = users create mask = 0660 directory mask = 0771 read only = no
Press CTRL+X to exit, press Y when asked if you want to keep changes and overwrite the existing configuration file. When back at the command prompt enter the following command to restart Samba:
sudo /etc/init.d/samba restart
Step 11: Creating Accounts
Now we need to add in a user that can access the Pi’s samba shares. You can make your username and password whatever you wish. To do so type the following commands:
sudo useradd backups -m -G users<br>sudo passwd backups
Terminal will then pop up saying to type in the password twice to confirm.
Step 12: Making the Raspberry Pi an Actual Server
Now that the accounts are set up we can finally make the raspberry pi a actual file server. First start off by typing in this command:
sudo smbpasswd -a backups
Enter the password for the account that you have made when prompted. Once you have made a user account and password you will not need to touch samba again. You can now go over to any samba-capable machine on the network that is connected to the Pi.
I will be using my iphone with a app called RemoteFileManagerFree on my IPhone (due to implications with my laptop from where i am doing this tutorial). If you want to know how to connect to a file server on a windows machine follow this tutorial http://mediawiki.middlebury.edu/wiki/LIS/Using_Fil... If your using a mac use this tutorial https://support.apple.com/kb/PH10644?locale=en_US
Step 13: Connecting to the File Server (Remote FIles Free)
When you open the app you will be met with a screen that has local, photo libary and favorites. Click the top right + button and select Network Share. Fill in the Display name as what ever you want (I made mine backups) The IP of the Pi ( you can check what your IP is by typing ifconfig into terminal on the PI. Scroll down to wlan0 and it should be next to inet addr:) Put the IP address in there and then press save.
Click on the newly created network on the app and type the username and password you created into it. Congratulations you have now connected to the file server. You can now upload and download files onto your PI.