Tell me more ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

How to setup a wi-fi hotspot (access point mode)?

Point to be noted: Wireless hotspot aren't same as ad hoc networks. Significant difference is there. In short, adhoc networks aren't supported in some android model, windows mobile (and may be ios devices too) where as wifi hotspot does.

share|improve this question

2 Answers

up vote 19 down vote accepted

Here is a brief tutorial about setting up new wireless hotspot in with ubuntu 12.04 and sharing internet using it.

Hardware used for testing : Dell XPS L502 (Intel Centrino 1030 wireless card)

Though this tutorial is tested in intel centrino wireless card, it should be applicable to all cards whose drivers uses mac80211 framework. (See the card testing part in answer)

Whether your wireless card support Access Point mode.

First thing to be done is perform the test whether your wireless card support going into wireless access point mode. As told earlier following test is for mac80211 framework based driver.

Install iw & execute following

sudo aptitude install iw
iw list

Look for supported interface section, where it should be a entry called AP like below

Supported interface modes:
         * IBSS
         * managed
         * AP
         * AP/VLAN
         * monitor
         * mesh point

If your driver doesn't shows this AP, It doesn't mean it can't create wireless hotspot. But those cards aren't in scope of this tutorial. For more tests follow ubuntu documentation on master mode.

The setup is divided in three sections,

  1. Setup & host a wireless network
  2. IP address setup
  3. Internet sharing

1.Setup and host a network

  • Software required: hostapd Install hostapd (install it)
  • Press alt + F2 and type gksu gedit & press enter. We are going to edit a lot of files.
  • In gedit, press ctrl+o, ctrl + l & paste it in location box hostapd-minimal.conf. Press enter.
  • Paste below code,

    interface=wlan0 
    driver=nl80211 
    ssid=test 
    hw_mode=g 
    channel=1 
    macaddr_acl=0 
    auth_algs=1 
    ignore_broadcast_ssid=0 
    wpa=3 
    wpa_passphrase=1234567890 
    wpa_key_mgmt=WPA-PSK 
    wpa_pairwise=TKIP 
    rsn_pairwise=CCMP
    

Changes you need to do:

  1. Change interface=wlan0 to your wireless card name. (If you have one wireless card it should be wlan0)
  2. ssid=test. test is the name of yout hosted network.
  3. wpa_passphrase=1234567890, 1234567890 is the password of your network.

The configuration above creates a wpa & wpa2 enabled access point in g mode. A more detailed instruction to build configuration file can be found here

Now start the hostapd. Using the following command,

sudo hostapd hostapd-minimal.conf

It should start a wireless network. In your mobile device now you can see a wireless network and can authenticate. But the device won't get ip address. Press ctrl+c to stop it.

If you get any error, possibly your card doesn't support g mode. Try with other >modes. Guide

Part 2: Set up dhcp server for ip address management

Install isc-dhcp-server Install isc-dhcp-server

In gedit, press ctrl + o , in location box paste /etc/dhcp/dhcpd.conf Find (ctrl+f) below lines and put # before it. It should look like after editing

# option definitions common to all supported networks…
#option domain-name “example.org”;
#option domain-name-servers ns1.example.org, ns2.example.org;

Again comment out following lines too

#default-lease-time 600;
#max-lease-time 7200;

Add following lines at end

subnet 10.10.0.0 netmask 255.255.255.0 {
        range 10.10.0.2 10.10.0.16;
        option domain-name-servers 8.8.4.4, 208.67.222.222;
        option routers 10.10.0.1;
}

Range describe how long the address pool will be. you need to adjust subnet value also. This config can assigne ip upto 15 devices

Again press ctrl+o in gedit and paste following in location bar /etc/network/interfaces,Add below

auto wlan0
iface wlan0 inet static
address 10.10.0.1
netmask 255.255.255.0

wlan0 is your wireless interface. Change it accordingly.

Note: After reboot the wireless will be shown as not managed. So you can't use any other wi-fi network. To get wireless with normal behaviour, put # before those newly added line and execute sudo start networking

now run

sudo start isc-dhcp-server

sudo hostapd hostapd-minimal.conf

At this point , your mobile device will see a network, authenticate it & after authentication it will get ip address something like 10.10.0.2.

Setup internet connection settings

For Internet connection sharing we need ip forwarding and ip masquerading. Enable ip forwarding : execute

echo 1| sudo tee /proc/sys/net/ipv4/ip_forward

Now say you are using to a dial up/usb modem connection to connect to INTERNET. You need to get the logical interface name. For that execute ifconfig

For dialup/usb modem: it should be ppp0. If you want to share Ethernet connection you should use ethXwhere X is your ethernet device number.

Now once you get the interface name execute sudo iptables -t nat -A POSTROUTING -s 10.10.0.0/16 -o ppp0 -j MASQUERADE

The ppp0 in above command is the interface whose internet connection you are sharing over wireless.

If you have edited upto /etc/network/interfaces you can use this script to start the service. Edit it if you are not sharing ppp0. if you are using script and want to stop the server, use sudo killall hostapd


I will try to update script later, to try if I can automate all the steps.

Please feel free to edit it to make it more useful.


Great helps from :

share|improve this answer
I could connect to hotspot and authenticate. But I am not able to receive an IP. Could you help me out? – neo Mar 2 at 14:30
@neo have youcommented out the lines in config – Web-E Mar 2 at 15:25
I did. I actually tried the whole process twice, just to make sure I did not do it wrong the first time. – neo Mar 3 at 14:07
Neo is right. There is something definitely wrong with ubuntu. This has recently stopped working! – Indian Apr 5 at 19:09

Command for getting YOUR Wireless driver name:

sudo lshw -xml | xpath -q -e "//node[@id='network' and ./capabilities/capability[@id='wireless']]/configuration/setting[@id='driver']/@value" | cut -d"\"" -f2

Tested on Ubuntu 13.04. Uses: http://manpages.ubuntu.com/manpages/raring/man1/xpath.1p.html However, it found "iwlwifi" driver name. So I'm following workaround described in this discussion: http://ubuntuforums.org/archive/index.php/t-1962267.html

Simply: still using driver=nl80211

share|improve this answer

protected by Community Nov 18 '12 at 22:02

This question is protected to prevent "thanks!", "me too!", or spam answers by new users. To answer it, you must have earned at least 10 reputation on this site.

Not the answer you're looking for? Browse other questions tagged or ask your own question.