Skip to main content

Turn your Linux into a wifi hotspot for Android and Windows phones! (Ubuntu and Linux Mint)

This is one of the biggest problem linux users face i.e. to share your ethernet connection over wifi for your android or windows mobile device. Here is a simple step process to easily set up a hotspot on your laptop to connect your mobile devices to surf on the go!

1. We need to install 2 additional tools to make our hotspot work:
  • hostapd(hotspot server) 
  • dnsmasq(dns dhcp server)
Open the terminal (Ctrl+alt+T) and type: 
sudo apt-get install hostapd dnsmasq
and press enter. Wait for them to install.
 
2. Stop these services and prevent them from starting on system start up. To do that; open a terminal and type each command per line and press enter:
sudo service hostapd stop
sudo service dnsmasq stop
sudo update-rc.d hostapd disable
sudo update-rc.d dnsmasq disable
 
3. Now we need to set the configuration files for both the installed tools.
To open the config file of dnsmasq; open a terminal (Ctrl+alt+T) and type
sudo gedit /etc/dnsmasq.conf
As you press enter a window with some text will pop up. Ignore the text if you don't understand it and add these lines to the window opened.
Code:
# Bind to only one interface
bind-interfaces
# Choose interface for binding
interface=wlan0
# Specify range of IP addresses for DHCP leasses
dhcp-range=192.168.150.2,192.168.150.10


4.
To open the config file of hostapd; open a terminal (Ctrl+alt+T) and type
sudo gedit /etc/hostapd.conf

As soon as you press enter a blank window will appear. Add the following lines to the window opened.
Code:
# Define interface
interface=wlan0
# Select driver
driver=nl80211
# Set access point name
ssid=myhotspot
# Set access point harware mode to 802.11g
hw_mode=g
# Set WIFI channel (can be easily changed)
channel=6
# Enable WPA2 only (1 for WPA, 2 for WPA2, 3 for WPA + WPA2)
wpa=2
wpa_passphrase=mypassword


You can change ssid (name of the hotspot) and password to anything you want here in this file. The current config will create hotspot named myhotspot with the password as mypassword.

5. Now create a file anywhere with anyname.sh according to your preference. I recommend to create a startwifi.sh file in the home folder. To do this, open a terminal (Ctrl+alt+T) and type:
sudo gedit startwifi.sh
and a blank window will appear named startwifi.sh.


This file will hold the information to start the hotspot when you want to. Now add the following lines to this file and save the file.
Code:
#!/bin/bash
# Start
# Configure IP address for WLAN
sudo ifconfig wlan0 192.168.150.1
# Start DHCP/DNS server
sudo service dnsmasq restart
# Enable routing
sudo sysctl net.ipv4.ip_forward=1
# Enable NAT
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
# Run access point daemon
sudo hostapd /etc/hostapd.conf
# Stop
# Disable NAT
sudo iptables -D POSTROUTING -t nat -o eth0 -j MASQUERADE
# Disable routing
sudo sysctl net.ipv4.ip_forward=0
# Disable DHCP/DNS server
sudo service dnsmasq stop
sudo service hostapd stop


6. Finally you can start your hotspot by starting our script. Run it using the sh command in the terminal, for me it looks like this:

sh startwifi.sh
because I have it in my home folder.


Or you can make the file executable to double click and run. In order to do so, right-click the file and go to Properties and select the permissions tab. Mark the allow executing the file as a program and close the dialog. Now you may double click the file to run in terminal.

Comments

Popular posts from this blog

How to program pyramids using loops - 2

In this video tutorial, two of the more patterns have been discussed that relates to the similar pattern problems. What's different about these are that they also include spaces before the stars as a part of the pattern to be printed. Having this extra sub pattern to track spaces  in the desired pattern requires an extra loop to track and control it . For a brief review, We discussed that these patterns if observed carefully are just representation of tables i.e. a combination of rows and columns . And few of the cells in that table are populated with some data according to a logically programmed algorithm with represents a pattern. In these cases, the red triangles shows us the spaces represented by "sp" and therefore unlike the previous pattern these need to be managed by the loop as they occur before the stars in the pattern. So, taking the same approach of rows and columns managing loops, we will have an outer loop that tracks the rows which will start at 0...

Hello World in PHP!

PHP is one of the most powerful languages of the web. PHP is an application server as well as a programming language that has the capability to do loads of stuff like generate dynamic HTML, connect to databases, apply programming logic to the website code, server side scripting, form handling etc. It is one of the most widely used scripting languages. In order to get it running, you will need to have a basic setup preconfigured which we'll cover later in the course. Just to give you all a head's up, we will start with the trivial "HELLO WORLD" program. Test Code : ( Use this code to display Hello World! in the console ) <?php echo "Hello, World!"; ?> NOTE:  Don't worry about anything else you see on the screen just focus on the code and rest will be discussed later in the tutorials. Save the file as " H ello.php " in the DOCUMENT ROOT of your web-server; for XAMPP users like me its the HTDOCS folder in the installat...

Hello world in Java!

Java is one of the most commonly used programming languages in the world today. Most of the work you can ever think in the world of programming can be done using Java Programming. Java is used to program everything from small devices to heavy machines. Everything from your Smartphone to your ATM card is somehow supported by Java behind the scenes. In order to learn Java which you might have also heard as of the most popular Object oriented Programming language of the modern times, we must start with the trivial "HELLO WORLD" program. Test Code : ( Use this code to display Hello World! in the console ) public class Hello {     public static void main ( String args[] ) {         System.out.println( "Hello, World!" );     } } NOTE:  Don't worry about anything else you see on the screen just focus on the code and rest will be discussed later in the tutorials. Save the file as " H ello.java " ,  the .java exte...