Turn Your computer into a WiFi Access point / Hotspot in ubuntu linux
This guide will help you to turn your Laptop or wireless LAN capable desktop in to the hotspot. You already know Ubuntu OS has this feature , but it is working as Ad-Hoc hotspot which cannot connect be connect your android smart phone, I Phone, DLNA TV or any other wireless device with your computer.
But this solution will work only for Atheros type wireless adapters and make sure you have the driver ath5k,ath9k,ath9k_htc , but don’t worry most of wireless adapters are atheros
sudo lshw | less
You can see at the bottem mine is ath9k_htc
2. You can check weather your wirless card supports AP mode with hotspad or not by this command
iw list
if it lists AP in "Supported interface modes" you
can proceed.
3. Now we need to install 2 additional tools to craete a hotspot
- hotspad (hotspot server)
- dnsmasq(dns dhcp server)
sudo apt-get install hostpad dnsmasq4. You must stop these services before you proceed
sudo service hostapd stop5. And disable these starting on system startup
sudo service dnsmasq stop
sudo update-rc.d hostapd disable6. We need to add following lines to bottem of dnsmasq.conf file
sudo update-rc.d dnsmasq disable
sudo gedit /etc/dnsmasq.conf
# Bind to only one interfaceyou can change the DHCP range as you wish
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
7. We need to create hostapd.conf file
sudo gedit /etc/hostapd.confadd these lines
# Define interface
interface=wlan0
# Select driver
driver=nl80211
# Set access point name
ssid=rocknirmana
# 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=12345678
you can change the ssid by replacing “rocknirmana” at the 6th line and change the password by replacing the “12345678” at the bottom line
8. Now create file named start.sh in anywhere in your directories , i created it in my home folder
sudo gedit /home/username/start.shreplace your username with “username” and type following code in start.sh and save it
#!/bin/bashyou need to change ppp0 in 10th and 15th line with your internet connection interface , you can check your internet connected interface by “ifconfig” command , i’m using mobile broadband therefor every mobile broadband uses point to point protocol , so mine is ppp0,
# 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 ppp0 -j MASQUERADE
# Run access point daemon
sudo hostapd /etc/hostapd.conf
# Stop
# Disable NAT
sudo iptables -D POSTROUTING -t nat -o ppp0 -j MASQUERADE
# Disable routing
sudo sysctl net.ipv4.ip_forward=0
# Disable DHCP/DNS server
sudo service dnsmasq stop
sudo service hostapd stop
example
eth0 for ethernet 0
8. Finallay you have to run this script manually to start the hotspot by typing
sudo sh /home/username/start.shReplace your username with “username”