Skip to content

Instantly share code, notes, and snippets.

@jspw
Created March 20, 2020 11:30
Show Gist options
  • Save jspw/4a86210ce22580c742ec487166efdf79 to your computer and use it in GitHub Desktop.
Save jspw/4a86210ce22580c742ec487166efdf79 to your computer and use it in GitHub Desktop.
Manually create a hotspot in your linux(debian) machine

Manually create a hotspot in your linux(debian) machine :

  • Install hostapd(hotspot server) and dnsmasq (dns dhcp server) : sudo dhclient eth0 or sudo dhclient wlan0

  • Prevent the installed services starting at the start up :

    • sudo service hostapd stop
    • sudo service dnsmasq stop
    • sudo update-rc.d hostapd disable
    • sudo update-rc.d dnsmasq disable
  • Setup the configuration file of dnsmasq : sudo gedit /etc/dnsmasq.conf

    • paste the code below :

        # Bind to only one interface
        bind-interfaces
        interface=wlan0
        dhcp-range=192.168.150.2,192.168.150.10
      
  • Setup the configuration file of hostapd : sudo gedit /etc/hostapd.conf

    • paste the code below :

        interface=wlan0
        driver=nl80211
        ssid=JackSparrow
        hw_mode=g
        channel=11
        wpa=1
        wpa_passphrase=test12345
        wpa_key_mgmt=WPA-PSK
        wpa_pairwise=TKIP CCMP
        wpa_ptk_rekey=600
        macaddr_acl=0
      

You should change the ssid and wpa_passphrase to your preferences

  • Create hotspot.sh file :sudo gedit hotspot.sh

    • paste the code below :

          #!/bin/bash
          # Start
          sudo ifconfig wlan0 192.168.150.1
          sudo service dnsmasq restart
          sudo sysctl net.ipv4.ip_forward=1
          sudo iptables -t nat -A POSTROUTING -o eth0-j MASQUERADE
          sudo hostapd /etc/hostapd.conf
          sudo iptables -D POSTROUTING -t nat -o eth0-j MASQUERADE
          sudo sysctl net.ipv4.ip_forward=0
          sudo service dnsmasq stop
          sudo service hostapd stop
      
  • Now, execute the shell script : sh hotspot.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment