Install Wifi Hotspot on Raspberry Pi—Ubuntu Mate

Install Wifi Hotspot on Raspberry Pi Ubuntu Mate 16.04. Turn your Raspberry Pi as a portable wifi hotspot. The internet connection is coming from Ethernet port or cable and share the connection to a wifi hotspot.

This tutorial starts from a freshly installed Ubuntu Mate operating system. Let’s begin
Turn on your Raspberry Pi, login and update it:

sudo apt-get update

Setting a static IP:
type:

ifconfig

Check the interface name of the ethernet and wifi. Usually its:
eth0 = ethernet wired connection
wlan0 = is the wifi interface name

Now, lets set IP address for these two interfaces:

sudo nano /etc/network/interfaces

Paste your desired IP. Below is my connection settings:

auto eth0
iface eth0 inet static
    address 192.168.5.200
    netmask 255.255.255.0
    gateway 192.168.5.1
    dns-nameservers 192.168.5.1

allow-hotplug wlan0
iface wlan0 inet static
    address 192.168.10.1
    netmask 255.255.255.0
    broadcast 192.168.10.255
    network 192.168.10.0

To apply these changes, we need to write a script:

sudo nano dn.sh

And paste this code:

#!/bin/bash  
systemctl stop NetworkManager.service
echo "Network Manager stopped"
systemctl disable NetworkManager.service 
echo "Network Manager disabled"
echo "Rebooting...."
reboot

What these codes do are stopping the network manager, disabling it and finally reboot the system. This is necessary so we will not get disconnected once the service stop.

Now let’s run the script:

sudo sh dn.sh

After reboot, delete the script.

sudo rm dn.sh

Installing Hostapd

sudo apt-get install hostapd

Stop the service and configure it:

sudo service hostapd stop

sudo nano /etc/hostapd/hostapd.conf

Paste the code below:

interface=wlan0
ssid=YOUR_WIFI_NAME
wpa_passphrase=WIFI_PASSWORD
hw_mode=g
ieee80211n=1
channel=6
wmm_enabled=1
ignore_broadcast_ssid=0
auth_algs=1
wpa=2
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP

Change the ssid and wpa_passphrase according to your preference. Save and exit

Now type:

sudo nano /etc/default/hostapd

Uncommend DAEMON_CONF=”” and add value: /etc/hostapd/hostapd.conf
You should see this

DAEMON_CONF="/etc/hostapd/hostapd.conf"

Start the hostapd service and check the wifi if you can see the SSID we created

sudo service hostapd start

Install DHCP server

sudo apt-get install isc-dhcp-server

Stop the service and keep the original copy of the configuration file of DHCP server

sudo service isc-dhcp-server stop

sudo mv /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.bak

Let’s create a new configuration:

sudo nano /etc/dhcp/dhcpd.conf

Paste this the below codes. This is my network details, please change this to fit in your network:

default-lease-time 600;
max-lease-time 7200;
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.10.255;
option routers 192.168.10.1;
option domain-name-servers 192.168.10.1,8.8.8.8;
option domain-name "diyhobi.com";

subnet 192.168.10.0 netmask 255.255.255.0 {
range 192.168.10.100 192.168.10.150;
}

Apply this changes to our Wifi interface named wlan0

sudo nano /etc/default/isc-dhcp-server

Below, add the wifi interface wlan0

INTERFACES="wlan0"

Start now the DHCP service.

sudo service isc-dhcp-server start

Activating the IPv4 forwaring

sudo nano /etc/sysctl.conf

Un-comment this line by removing #

net.ipv4.ip_forward=1

Save it:

sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"

Changing the Firewall

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

See the changes

sudo iptables -L -n -v

Save the rules

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

Lets make this rules loaded automatically every time the system reboot

sudo nano /etc/rc.local

Paste this code before “exit 0”

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

Please connect a device to the hotspot and browsing the internet.
You have successfully installed a hotspot in your Raspberry Pi

Please support us by subcribing to my Youtube channel. Enjoy