Make Hotspot using PiTalk and Raspberry Pi

Make Hotspot using PiTalk and Raspberry Pi

0 comments

In this tutorial, you will learn how to integrate PiTalk (Raspberry Pi 3G Module) with Raspberry Pi' WiFi to make your personal Internet hotspot. It can be used as a router to connect to the internet and also host a local area network.

  1. Connect your Raspberry Pi to the internet using WiFi or Ethernet.
  2. Install the required packages:
    sudo apt-get install dnsmasq hostapd 
  3. Configure 'wlan0' interface with a static IP. Open configuration file:
    sudo nano /etc/dhcpcd.conf
    and add the following line at the bottom:
    denyinterfaces wlan0
    Note: This must be above any 'interface' lines you may have added.
  4. Now configure static IP using the command:
    sudo nano /etc/network/interfaces
    and edit the file:
    allow-hotplug wlan0  
    iface wlan0 inet static  
        address 172.24.1.1
        netmask 255.255.255.0
        network 172.24.1.0
        broadcast 172.24.1.255
  5. Now we need to configure 'hostapd'. Create a configuration file by using the command:
    sudo nano /etc/hostapd/hostapd.conf
    and add the following content:
    # 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=PiTalk_WiFi
    
    # 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 
  6. Open up the default configuration file using:
    sudo nano /etc/default/hostapd
    and find the line
    #DAEMON_CONF=""
    and replace it with
    DAEMON_CONF="/etc/hostapd/hostapd.conf" 
  7. Configure 'dnsmasq' configuration file:
    sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig  
    sudo nano /etc/dnsmasq.conf
    and paste the following into the new file:

  8. interface=wlan0      
    # Use interface wlan0  
    listen-address=172.24.1.1 
    # Explicitly specify the address to listen on bind-interfaces      
    # Bind to the interface to make sure we aren't sending things elsewhere  
    server=8.8.8.8       # Forward DNS requests to Google DNS  
    domain-needed        # Don't forward short names  
    bogus-priv           # Never forward addresses in the non-routed address spaces.  
    dhcp-range=172.24.1.50,172.24.1.150,12h # Assign IP addresses between 172.24.1.50 and 172.24.1.150 with a 12 hour lease time  
  9. Now enable packet forwarding:
    sudo nano /etc/sysctl.conf
    and remove the '#' from the beginning of the line containing:
    net.ipv4.ip_forward=1
    Now reboot your Raspberry Pi or active it immediately with:
    sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
  10. Now we need to share our Raspberry Pi internet connection to our devices connected over WiFi by configuring:
    sudo iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE  
    sudo iptables -A FORWARD -i ppp0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT  
    sudo iptables -A FORWARD -i wlan0 -o ppp0 -j ACCEPT
  11. We need these rules to be applied every time we reboot the Raspberry Pi, so run the command to save the file:
    sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
    Now we need to run this after each reboot, so open the 'rc.local' file and add the following line just above the 'exit 0'
    iptables-restore < /etc/iptables.ipv4.nat
  12. Now to start the type of the services:
    sudo service hostapd start
    sudo service dnsmasq start
  13. Now to cross check everything configured correctly, reboot the Raspberry Pi:
    sudo reboot

Find out more PiTalk Smartphone Kits online on SB Components Shop.


    Make a PPP Internet Connection using PiTalk

    Introduction of an Intelligent Home Automation using Raspberry Pi

    Leave a comment

    Please note, comments need to be approved before they are published.