Ubuntu 12.04 – setting up my Wifi Hotspot

1 May

Please Note: As the Title suggests – I am a newbie, Please do not expect in-depth computer support. I can only say that the setup below really does work on my netbook. Perhaps it will work on yours too!

 

The first thing I wanted to do after installing Ubuntu 12.04 is setup a wifi hotspot. I have a Samsung Netbook N130. I use a usb-modem to connect to the internet. I have a single data contract with Vodacom and I want all my devices to use this data at the same time.

Gathering information:

Opening a terminal and typing the following command :

#lspci

Showed me that I have a :

 Network controller: Atheros Communications Inc. AR9285 Wireless Network Adapter (PCI-Express)

#lsmod

Shows that it uses the ath9k drivers (this information may help you to google for setup information specific to your machine.)

Also

#iwconfig

will give you the name of your wireless adapter name for example:

“wlan0 “or “wlan1” (note that the “0” and “1” are numbers not letters)

Installing Programs

I then installed 2 programs via apt. In a terminal enter the following command:

#sudo apt-get install dhcp3-server

#sudo apt-get install hostapd

Editing Configuration Files

In a terminal:

#sudo gedit

This will bring up the editor with root privileges so that you can edit system files. (WARNING – editing system files can damage your system. Please do not edit system files unless you have made a backup of them first)

Open / Create the following files editing:

1. /etc/hostapd/hostapd.conf

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

Please note: the “ssid” in this case “my_hotspot” is the name of the network that will show up on the device or laptop that will connect to the hotspot. The passphrase is a password – you can change this to any other 10 digit number. The device / laptop that wants to connect will have to enter this password.

Save the file.

2. /etc/default/isc-dhcp-server

Edit the line that says

INTERFACES=””

To

INTERFACES=”wlan0″

Or change the “wlan0” to “wlan1” or whatever the wireless adapter name you have (see above section on gathering information.)

3. /etc/dhcp/dhcpd.conf

Make sure the follow lines are Commented out ( put a hash “#”  sign at the beginning of the line ) the following lines:

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

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

Add the following lines to the file (copy and paste)

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;
}

(Note: the only other line in this whole config file that is uncommented is :

ddns-update-style none;)

4. /etc/default/hostapd

Add the following lines to the bottom of the file. Make sure similar lines are commented.

RUN_DAEMON=”yes”
DAEMON_CONF=”/etc/hostapd/hostapd.conf”
DAEMON_OPTS=”-dd”

(Note: This file makes sure hostapd program starts on bootup with your edited configuration files loaded)

5. /etc/network/interfaces

This is how my interfaces file looks:

auto lo
iface lo inet loopback

auto wlan0
iface wlan0 inet static
 address 10.10.0.1
 netmask 255.255.255.0

(Note: Again you must change every “wlan0” to the name of your adapter. This file may have more entries for other network adapters. Just make sure you edit the section of the wireless adapter you want to use. This file will automatically configure the wireless network adapter’s network address at bootup time.)

At this stage you can reboot. And hopefully any device / laptop should connect to your wifi hotspots network via the network manager applet. On these devices search for the network “my_hotspot” and type in the password.

At this stage however you cannot access the Internet. Which brings us to another important step:

Internet connection Sharing.

You will need to ask yourself the following information. How do I connect to the internet on my ubuntu computer / laptop? In my case I use a usb 3G modem. You need to know the name of the network adapter that you connect to the internet on. > This must be different from the network adapter you configured above. (ie wlan0)

Connect to the internet, and in a terminal type:

#ifconfig

On my netbook, one of the entries is for adapter “ppp0” this is the network adapter for my usb modem and the connection to the internet. The following steps use “ppp0” however you can swap it for your adapter name:

To share the internet connection we have to do a thing called “ip masquerading”.

First we have to allow ip forwarding:

#sudo gedit

edit /etc/sysctl.conf

Make sure the following line is uncommented and reads

net.ipv4.ip_forward=1

Save and close gedit. (reboot)

After reboot: Connect to the Internet and In a terminal type:

# sudo iptables -t nat -A POSTROUTING -s 10.10.0.0/16 -o ppp0 -j MASQUERADE

(Note the “ppp0” adapter name in the above line. The 10.10.0.0 is the ip address of your network that you configured in steps 3 and 5 above. Your wifi hotspot will thus share the internet with up to 15 machines that are given the ip addresses 10.10.0.2 to 10.10.0.16)

All devices and laptops should now be able to browse the internet and download email. If this works we have to make this permanent:

#sudo gedit

edit /etc/rc.local

add this line just before exit 0″

iptables -t nat -A POSTROUTING -s 10.10.0.0/16 -o ppp0 -j MASQUERADE

Reboot / Connect to the internet and Enjoy your wifi hotspot.

Acknowledgements

When configuring and setting up mine I used and adapted the following  Howto’s and forums:

http://exain.wordpress.com/2011/03/31/making-a-wifi-hotspot-access-point-using-linux-wifi-lan-cardusb-adapter/

http://ubuntuforums.org/showthread.php?p=11890695#post11890695

http://ubuntuforums.org/showthread.php?p=11890408#post11890408

55 Responses to “Ubuntu 12.04 – setting up my Wifi Hotspot”

  1. Денис Тужик May 4, 2012 at 7:50 pm #

    Great article but I want to add some corrections in it.
    There are two typos:
    1st it must be /etc/dhcp/dhcpd.conf
    2nd it must be /etc/default/hostapd

    They are a bit misleading 🙂

    And I can’t get my internet connection working at all, I don’t know why.
    Maybe you could help me.

    I guess it’s about ip masquerading, cause before this step everything goes ok, my samsung galaxy note connects to my hotspot,it get’s an 10.10.0.2 ip, then i’ve tried second device, it also works.

    But nothing happens after masquerading ip’s.
    sysctl.conf ip_forward preference is set.
    but it doesn’t work.

    I’ve thought because the dhcp server isn’t stopped before masquerading, but then I’ve tried to configure /etc/rc.local file, and it also didn’t wokred.

    Help me please, if you can, cause it’s freaking me out and i don’t know what to do.
    I’ve tried to redo all the tutorial, but it didn’t work either.

    I’m using an Ubuntu 12.04 desktop, a vpn connection to the internet through the eth0 adapter (I’ve changed the name of the adapter from ppp0 to eth0).

    If you need some more information write me on my email.
    Hope you’ll help me:)

    • Fleegle July 14, 2012 at 12:25 am #

      Worked perfect!! Hello! Денис Тужик, iptables -t nat -A POSTROUTING -s 10.10.0.0/16 -o ppp0 -j MASQUERADE, did you change ppp0 to your output interface, for example eth0 (or the interface where you connect the cable)? i don’t know if you resolved the problem, but just in case! 🙂

  2. Nam May 23, 2012 at 4:33 pm #

    The same problem. My Android phone get connected to wifi hotspot, but it can’t connect to Internet. I tried to ping google from my phone, didn’t succeed. I’m using Ubuntu 12.04.

    • Ioki October 22, 2012 at 9:34 pm #

      Install firestarter and share connection. Firewall blocking connection.

  3. Kidder June 2, 2012 at 7:01 am #

    Good article, but I give up editing these files and correcting their mistakes and errors to no avail. I am going to go learn .NET and develop an indie game for Xbox 360.

  4. bison July 28, 2012 at 10:42 am #

    At first, it wouldnt work for me too.
    THEN I found why: INTERFACES=”wlan0″
    I copied it, but look at the first AND last character… they are ” AND ″
    What we REALLY need is ”
    THATS the reason why its not working!
    I found the error in the ‘/var/log/syslog’ log with “Not configured to listen on any interfaces!”
    That was my hint to fix it.
    But ignoring this mistake produced by my own lazyness, its a GREAT “all foo in one article” article 😉

    • Aki August 9, 2012 at 11:01 pm #

      That method apparently supports only one device at a time. I’m not sure though

      • Pavan August 27, 2012 at 11:16 am #

        Thanks for your response. As I’m trying to connect through data card which network manager doesn’t recognise that method is not working 😦

      • thenewbieblog September 4, 2012 at 11:12 am #

        What is the name of your data-card? How do you connect to the internet through Linux?

    • Foxy August 27, 2012 at 2:40 am #

      Unfortunately the easy method does not work for me while this one does.

    • billiska September 23, 2012 at 4:38 pm #

      that one is to setup an ad hoc network.
      whereas this one is to set up infrastructure network.

  5. Aki August 9, 2012 at 11:02 pm #

    Thanks a lot dude. Now i can use hispeed internt without paying for exorbitant 3g prices. 🙂 \m/

  6. Pavan August 24, 2012 at 8:37 pm #

    I followed the instructions but my tablet struck at “obtaining IP address”. Please guide me

    • thenewbieblog August 27, 2012 at 10:20 am #

      Not an expert myself.

      Is it just your tablet that is finding it difficult to connect? Do you have another laptop etc that you can try it on?

      • Pavan August 27, 2012 at 11:20 am #

        I can connect to my office wifi. Even my phone strucks at the same point while trying to connect 😦

      • Pavan August 27, 2012 at 11:21 am #

        my phone too 😦

      • naveen May 10, 2013 at 6:45 pm #

        i am using dell inspiron 5220 laptop,can i use the same procedure in my laptop

      • thenewbieblog May 30, 2013 at 10:54 pm #

        It should work as long as you have a modem that connects to a mobile network and a wifi interface. I use my samsung netbook as a router to provide internet sharing to my wifes laptop, 2 cellphones and an android tablet.

    • Fleegle August 27, 2012 at 11:30 pm #

      You have to start the dhcpd…./etc/inid.d/isc-dhcp-server start | restart

  7. chfrag September 3, 2012 at 3:18 pm #

    Thanks a lot! It worked great and out of the box on a fresh Ubuntu 12.04 installation with a usb tllink wireless card. My ARCHOS 101 G9 connected without any problems

  8. adoet_t September 6, 2012 at 10:08 am #

    thankyu for safe my head 😉
    now I can connected to android,,

  9. arjunkn September 27, 2012 at 9:11 am #

    Tahnks man its realy worked for me… everything is ok i got connected my android to wifi, obtained IP. but it showing loading all the time.. the browser, fb app evrythng… can you help me..

  10. Domi October 6, 2012 at 10:02 pm #

    Same as Nam above. Phone get connected to wifi, but it can’t connect to internet, Ubuntu 12.04. Any ideas?

    • Krishna May 17, 2014 at 12:33 am #

      I am also having the same problem. Connected to wifi, but not able to browse internet. 12.04 itself !! Plz help if you have figured it out.

  11. joejohnson October 20, 2012 at 10:36 pm #

    i got stuck in the IP forwarding i looked at my logs and noticed this [UFW BLOCK] IN= OUT=wlan0 SRC=10.10.0.1 so i turned off my firewall and my android can access the internet… how do i add the rule to the IP tables to allow out

  12. joejohnson October 20, 2012 at 10:45 pm #

    i got stuck in the IP forwarding i looked at my logs and noticed this [UFW BLOCK] IN= OUT=wlan0 SRC=10.10.0.1 so i turned off my firewall and my android can access the internet now… how do i add the rule to the IP tables to allow out

  13. http://tinyurl.com/exclsimon35656 January 16, 2013 at 8:33 am #

    Your personal posting, “Ubuntu 12.04 – setting up
    my Wifi Hotspot | thenewbieblog” was in fact
    well worth commenting on! Really wished to mention u
    really did a tremendous job. Thank you -Leonor

  14. Lipin March 7, 2013 at 1:32 pm #

    A perfect solution. Just awesome!!

  15. රැපා March 8, 2013 at 5:13 pm #

    This is an awesome article bro, It works like charm, thank you so much 🙂

  16. promach March 13, 2013 at 12:15 pm #

    Mar 13 15:09:13 dell rtkit-daemon[1585]: Supervising 6 threads of 2 processes of 2 users.
    Mar 13 15:09:15 dell ntpdate[1669]: adjust time server 91.189.94.4 offset 0.340063 sec
    Mar 13 15:09:24 dell NetworkManager[849]: (wlan0): IP6 addrconf timed out or failed.
    Mar 13 15:09:24 dell NetworkManager[849]: Activation (wlan0) Stage 4 of 5 (IPv6 Configure Timeout) scheduled…
    Mar 13 15:09:24 dell NetworkManager[849]: Activation (wlan0) Stage 4 of 5 (IPv6 Configure Timeout) started…
    Mar 13 15:09:24 dell NetworkManager[849]: Activation (wlan0) Stage 4 of 5 (IPv6 Configure Timeout) complete.
    Mar 13 15:09:26 dell goa[1965]: goa-daemon version 3.4.0 starting [main.c:112, main()]
    Mar 13 15:09:27 dell kernel: [ 46.168993] audit_printk_skb: 39 callbacks suppressed
    Mar 13 15:09:27 dell kernel: [ 46.169000] type=1400 audit(1363158567.011:25): apparmor=”DENIED” operation=”open” parent=1 profile=”/usr/lib/telepathy/mission-control-5″ name=”/usr/share/gvfs/remote-volume-monitors/” pid=1960 comm=”mission-control” requested_mask=”r” denied_mask=”r” fsuid=1000 ouid=0
    Mar 13 15:09:56 dell avahi-daemon[682]: Invalid response packet from host fe80::2a6a:baff:fe77:5460.

    I cannot even detect the hotspot from another laptop.
    WHY ?

    • promach March 13, 2013 at 12:26 pm #

      dell@dell:~$ sudo hostapd -dd /etc/hostapd/hostapd.conf
      Configuration file: /etc/hostapd/hostapd.conf
      nl80211: Register Action command failed: ret=-114 (Operation already in progress)
      nl80211: Register Action match – hexdump(len=1): 06
      nl80211: Failed to register Action frame processing – ignore for now
      nl80211: Add own interface ifindex 3
      nl80211: Failed to set interface 3 to mode 3: -95 (Operation not supported)
      nl80211: Failed to set interface 3 to mode 3: -95 (Operation not supported)
      nl80211: Interface mode change to 3 from 0 failed
      nl80211: Failed to set interface wlan0 into AP mode
      nl80211 driver initialization failed.
      ELOOP: remaining socket: sock=4 eloop_data=0x96cc900 user_data=0x96ccea0 handler=0x807c5e0
      ELOOP: remaining socket: sock=6 eloop_data=0x96ceca8 user_data=(nil) handler=0x8086770

      dell@dell:~$ cat /etc/hostapd/hostapd.conf
      interface=wlan0
      driver=nl80211
      ssid=my_hotspot
      channel=1
      hw_mode=g
      auth_algs=1
      wpa=3
      wpa_passphrase=1234567890
      wpa_key_mgmt=WPA-PSK
      wpa_pairwise=TKIP CCMP
      rsn_pairwise=CCMP

  17. Akhil March 26, 2013 at 2:22 am #

    Just need to use “sudo hostapd hostapd.conf” after bootup… and it work for me.. Tnx.

    • thenewbieblog March 26, 2013 at 11:27 am #

      You then just need to automate the starting up of hostapd during bootup.

      • Akhil Buckal March 26, 2013 at 11:31 am #

        I have done that, but my other devices don’t discover the wifi, so I need to run this after boot…

  18. Firgiawan Eka Prasetyo April 9, 2013 at 10:00 am #

    Great 😀

  19. Srikanth M April 19, 2013 at 2:03 pm #

    I configured every thing as you said but it was not working as expected.
    The platform is an ARM board with Ubuntu 12.04 server version running on it. When i rechecked everything I found that its running in “runlevel 2” i changed it to “runlevel 3” now its working fine.

    This information might be useful to people who want to configure Wifi hotspot on embedded devices.

  20. Ade Malsasa Akbar April 28, 2013 at 1:39 pm #

    Is there any GUI way for doing this?

    • thenewbieblog April 28, 2013 at 10:15 pm #

      Not that I know of, But its a good idea. Maybe i will write one in python as my next programming project.

      • Ade Malsasa Akbar April 29, 2013 at 12:02 am #

        Really? I wanna be the first downloader! Truly! Can you reply into this comment anytime you have finished the GUI app one? You know? This such program is needed by many users in Indonesia.

  21. source May 27, 2013 at 11:52 pm #

    Excellent blog here! Also your site loads up very fast!
    What host are you using? Can I get your affiliate link
    to your host? I wish my website loaded up as quickly as
    yours lol

  22. Vishnuprakash February 22, 2014 at 7:30 pm #

    “At this stage you can reboot. And hopefully any device / laptop should connect to your wifi hotspots network via the network manager applet. On these devices search for the network “my_hotspot” and type in the password.

    At this stage however you cannot access the Internet. Which brings us to another important step:”

    Got struck after this step.i have followed the steps as mentioned above and after the reboot process,My device doesn’t recognise the wifi network as stated above.Help!!

  23. tarun March 3, 2014 at 9:59 am #

    How to stop the hotspot ??? It’s always runnning and draining my my battery .

  24. newspecies April 11, 2014 at 4:49 am #

    i have to connect to a proxy network to access network. Can you please tell me which command will change? I think this command will change # sudo iptables -t nat -A POSTROUTING -s 10.10.0.0/16 -o ppp0 -j MASQUERADE

    Thanks for any help in advance!

  25. Peter July 10, 2014 at 6:16 pm #

    This works perfect. Thanks for it.

  26. asterisk Setup ubuntu August 8, 2014 at 4:37 am #

    Hi, I do believe this is a great site. I stumbledupon it 😉
    I’m going to return once again sjnce I bookmarked it. Monjey
    aand freeddom is thhe best way to change, may you bee rich and continue to guide other people.

  27. vintage burberry scarf September 23, 2014 at 1:02 pm #

    I’m curious to find outt whatt blog platform you
    are utilizing? I’m having some small security problems with myy latest blog and I would like to find something more safe.
    Do you have any recommendations?

    • thenewbieblog September 30, 2014 at 9:59 pm #

      Sorry I am not a big blogger. I am just using wordpress

Trackbacks/Pingbacks

  1. Sharing Internet over Wifi Between Ubuntu and Android « GEEK PEEK - September 19, 2012

    […] https://thenewbieblog.wordpress.com/2012/05/01/wifi-hotspot-setup-on-ubuntu/ […]

  2. Share computer’s internet through wifi using hostapd « Neppramod’s Weblog - November 23, 2012

    […] Ubuntu 12.04 – setting up my Wifi Hotspot https://thenewbieblog.wordpress.com/2012/05/01/wifi-hotspot-setup-on-ubuntu/ 2. Hostapd : The Linux Way to create Virtual Wifi Access Point […]

  3. WiFi AP con Ubuntu 12.10 | Forever Ubuntu - February 25, 2013

    […] Fuente […]

  4. Sharing Internet over Wifi Between Ubuntu and Android » Monsieur Yusro - July 17, 2013

    […] https://thenewbieblog.wordpress.com/2012/05/01/wifi-hotspot-setup-on-ubuntu/ […]

  5. Whether your wireless card support Access Point mode. | Lufang's Vision - December 22, 2013

    […] https://thenewbieblog.wordpress.com/2012/05/01/wifi-hotspot-setup-on-ubuntu/ […]

  6. Unable to obtain IP in AP mode | CL-UAT - December 25, 2014

    […] setup an access point, using Raling RT5370 USB Dongle on a Debian system, I followed the following tutorial, until “Internet connection Sharing.”, I don’t want to share internet, so I skip […]

Leave a reply to arjunkn Cancel reply