Setting up a Raspberry Pi as a PMS Server, Wireless Router and WiFi Access Point

Setting up a Raspberry Pi as a PMS Server, Wireless Router and WiFi Access Point Creating bootable SD Card and USB Hard Disk Drive It is recommended t...
2 downloads 0 Views 69KB Size
Setting up a Raspberry Pi as a PMS Server, Wireless Router and WiFi Access Point Creating bootable SD Card and USB Hard Disk Drive It is recommended that you: • •

Use a Class 10 SD Card for speed and stability (a 4Gb card is sufficient for this, as we will be running from the USB hard disk drive), Use a powered USB hub if using a 2.5 or 3.5 USB hard disk drive, the Pi hasn’t really enough power for stability, if using an SSD hard disk drive then the Pi should be OK to supply power.

Follow the instructions at http://raspberrypihobbyist.blogspot.co.uk/2013/07/running-from-externalhard-drive.html to create your SD card and prepare your USB disk drive. When you reach the part where you modify the boot configuration: sudo nano /boot/cmdline.txt I would suggest deleting the existing line and replacing it with this: dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/sda2 rootfstype=ext4 elevator=deadline rootwait

Install Plex Media Server   Navigate to your home folder: 
 cd ~ Download the latest ARM Debian Plex Media Server from dev2day. sudo wget https://dev2day.de/plex-latest   Install the package: 
 sudo dpkg -i plex-latest   Install codecs and software for transcoding: 
 sudo apt-get install mkvtoolnix libexpat1 ffmpeg   Reboot. 
 sudo reboot or sudo shutdown -r now   If you need to update PMS in the future just do the following (dev2day seem to keep up to date with latest PMS releases): sudo wget https://dev2day.de/plex-latest  

1 of 6

Install the package: 
 sudo dpkg -i plex-latest Plex Media Server will now be running, you can start or stop the service by entering the commands:   sudo service plexmediaserver start or sudo service plexmediaserver stop or sudo service plexmediaserver restart  

Install the software that will act as the Access Point sudo apt-get update sudo apt-get install hostapd isc-dhcp-server (Note: If you get the following error, don’t worry, carry on!) [FAIL] Starting ISC DHCP server: dhcpd[....] check syslog for diagnostics. ... failed! failed! If you have a WiFi adapter with the RTL8188CUS Chipset (for example Edimax) you will need to replace a binary with modified binary for hostapd to work (thanks to Dave Conroy) if you don’t, please skip this part (in italics). To download and replace the installed binary version of hostapd we just installed, they need to issue the following commands: wget http://www.daveconroy.com/wp3/wp-content/uploads/2013/07/hostapd.zip unzip hostapd.zip sudo mv /usr/sbin/hostapd /usr/sbin/hostapd.bak sudo mv hostapd /usr/sbin/hostapd.edimax sudo ln -sf /usr/sbin/hostapd.edimax /usr/sbin/hostapd sudo chown root.root /usr/sbin/hostapd sudo chmod 755 /usr/sbin/hostapd

Set up DHCP Server Next we will edit /etc/dhcp/dhcpd.conf file, to  allow wifi connections to automatically get IP addresses, DNS, etc. 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 add a # to the beginning of the line. Find the line that says: #authoritative;

2 of 6

and remove the # . Then scroll down to the bottom and add the following lines: subnet 192.168.10.0 netmask 255.255.255.0 { range 192.168.10.10 192.168.10.50; option broadcast-address 192.168.10.255; option routers 192.168.10.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 Next we will edit /etc/default/isc-dhcp-server. sudo nano /etc/default/isc-dhcp-server Find the line that says: INTERFACES="" and update it to: INTERFACES="wlan0" Save the file by typing in Control-X then Y then return Set up wlan0 for a static IP If you happen to have wlan0 active because you set it up or are not sure, run: sudo ifdown wlan0 Next we will set up the wlan0 connection to have a static ip address. sudo nano /etc/network/interfaces Remove the contents of the file and add the following: auto lo iface lo inet loopback iface eth0 inet dhcp allow-hotplug wlan0 iface wlan0 inet static address 192.168.10.1 netmask 255.255.255.0 up iptables-restore < /etc/iptables.ipv4.nat

3 of 6

Save the file by typing in Control-X then Y then return Assign a static IP address to the wifi adapter by running sudo ifconfig wlan0 192.168.10.1 Reboot. 
 sudo reboot or sudo shutdown -r now

Configure the Access Point Create a new file by running: sudo nano /etc/hostapd/hostapd.conf Add the following, the text after ssid= will be the network broadcast name. The password is set with the text after wpa_passphrase= make this something you can remember you will need it to connect your devices to this network. This assumes that you have the Edimax WiFi adapter mentioned above and you have installed the modified driver, if not insert the appropriate driver for your adapter in driver=. interface=wlan0 driver=rtl871xdrv ssid=PMSPi channel=6 wmm_enabled=1 macaddr_acl=0 auth_algs=1 wpa=1 wpa_passphrase=raspberry wpa_key_mgmt=WPA-PSK wpa_pairwise=TKIP rsn_pairwise=CCMP Save the file by typing in Control-X then Y then return Next we have to tell the Pi where the configuration file is.  sudo nano /etc/default/hostapd Find the line that says: #DAEMON_CONF="" Remove the # in front of it and edit it so it says: DAEMON_CONF=“/etc/hostapd/hostapd.conf" Save the file by typing in Control-X then Y then return.

4 of 6

Configure Network Address Translation NAT will allows clients to connect to and have addresses assigned by the WiFi network we have created. sudo nano /etc/sysctl.conf At the bottom add the following on a new line: net.ipv4.ip_forward=1 Save the file by typing in Control-X then Y then return. This will start IP forwarding on boot up To start IP forwarding now: sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward" to activate it immediately. To enable you to connect to your normal router by Ethernet cable to update the Pi or remotely connect via SSH for maintenance we need 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 To check whats in the tables: sudo iptables -t nat -S sudo iptables -S To ensure that this is done on reboot: sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"

Testing To run hostapd with the modified configuration file: sudo /usr/sbin/hostapd /etc/hostapd/hostapd.conf This will configure and use wlan0. Check with another device that you see your SSID show up.  If so, you have successfully set up the access point.

5 of 6

Connect to PMSPi with the password you set before (raspberry, if you didn’t change it in the hostapd config), some debug text will be displayed. Cancel the test by typing Control-C to get back to the Pi command line

Finally... Set up a 'daemon' - so that everything starts when the Pi boots. sudo service hostapd start sudo service isc-dhcp-server start

If you need to check the status of the host AP server and the DHCP server use: sudo service hostapd status sudo service isc-dhcp-server status To start the daemon services and confirm that they both start successfully The following will make sure everything starts on boot: sudo update-rc.d hostapd enable sudo update-rc.d isc-dhcp-server enable Reboot the Pi and check everything is working. Don’t forget to set up directories in your Home directory to feed the libraries in Plex Media Server, e.g. movies, tvshows, photos, music and copy your media into them. All you need to do now is configure PMS through the Plex Web interface.

6 of 6