Setting up a Raspberry Pi 3 as a WiFi media server
So, until now, on long trips, I had setup a small netbook running Ubuntu with a DLNA media server, with external HD attached with the media files. And a WiFi router to provide the wireless network so my kids could watch videos on their tablets. Not only was this setup big and bulky, but it took quite a bit of time to setup for long trips as well as boot it and shut it down whenever we needed to shut off the car, as it was all running on a power inverter.
Here, we are going to setup the Raspberry Pi 3 to use the internal WiFi as an access point for the tablets to attach to as well as a DHCP server, so they receive an IP address, and finally, install a DLNA media server to serve the media files.
Install Raspbian Lite since we don’t need a GUI. The easiest way to work with this is to connect it via wired LAN and ssh into it using putty. Just make sure you install ssh and enable it.
Quick notes: still under construction
sudo su –
apt-get install ssh
service ssh start
systemctl enable ssh
fix arrow keys and stuff in vim:
vi .vimrc
set nocompatible
apt-get update
apt-get install hostapd isc-dhcp-server
vi /etc/dhcp/dhcpd.conf
# out options
Remove # from athoritative
add this to the bottom:
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;
}
vi /etc/default/isc-dhcp-server
Change to : INTERFACES=”wlan0″
ifdown wlan0
vi /etc/network/interfaces
# out everything wlan0 related except for allow-hotplug wlan0
add:
iface wlan0 inet static
address 192.168.20.1
netmask 255.255.255.0
ifconfig wlan0 192.168.20.1
vi /etc/hostapd/hostapd.conf
interface=wlan0
ssid=media
country_code=US
hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=WIFI-PASSWORD
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP
wpa_group_rekey=86400
ieee80211n=1
wme_enabled=1
Of course, change the SSID and PW to whatever you want it to be.
vi /etc/default/hostapd
change to:
DAEMON_CONF=/etc/hostapd/hostapd.conf
Start the DHCP server so it can provide an IP:
service isc-dhcp-server start
Now test the WiFi AP
/usr/sbin/hostapd /etc/hostapd/hostapd.conf
Search your WiFi and attempt to connec to it. You should get an IP address, but you may get a warning that the internet doesn’t work.. which it won’t because we don’t actually care about that.
Press CNTL-C to exit and start it as a service
service hostapd start
Set it to start both of these services automatically on bootup.
systemctl enable hostapd
systemctl enable isc-dhcp-server
Next will be to install the DLNA server.
apt-get install minidlna If your external HD with your media on it is NTFS, you need this for read/write access. apt-get install ntfs-3g vi /etc/fstab add this: /dev/sda1 /media/hdd ntfs-3g defaults 0 0 where the /dev/sda1 is your external HD. Use this to find out:
fdisk -l vi /etc/minidlna.conf add this: media_dir=V,/media/hdd with the path to your files friendly_name=Media inotify=yes model_name=Raspberry Pi Media to something else cause that name is just to long! systemctl start minidlna test that you can see it and it works systemctl enable minidlna
Adding routing for a second WiFi interface. I'm not sure all the notes are here, but I purchased a USB WiFi adapter to allow the Raspberry Pi to connect to another Wireless network so I could update it and transfer files to it without having to remove the external USB hard drive. Later, I realized, it would be nice to allow it to connect to my phones hotspot on trips and then allow the kids tablets to also access the internet while being connected to the media server's WiFi. So, I just needed to add some routing and persistent iptables.
# apt-get install -y netfilter-persistent iptables-persistent
# vi /etc/sysctl.d/routed-ap.conf
Add this:
net.ipv4.ip_forward=1
Save that, do this:
# iptables -t nat -A POSTROUTING -o wlan1 -j MASQUERADE