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://ubuntuforums.org/showthread.php?p=11890695#post11890695
http://ubuntuforums.org/showthread.php?p=11890408#post11890408
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:)
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! 🙂
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.
Install firestarter and share connection. Firewall blocking connection.
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.
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 😉
Hi, here is a much simpler way:
http://www.howtogeek.com/116409/how-to-turn-your-ubuntu-laptop-into-a-wireless-access-point/
That method apparently supports only one device at a time. I’m not sure though
Thanks for your response. As I’m trying to connect through data card which network manager doesn’t recognise that method is not working 😦
What is the name of your data-card? How do you connect to the internet through Linux?
Unfortunately the easy method does not work for me while this one does.
that one is to setup an ad hoc network.
whereas this one is to set up infrastructure network.
Thanks a lot dude. Now i can use hispeed internt without paying for exorbitant 3g prices. 🙂 \m/
I followed the instructions but my tablet struck at “obtaining IP address”. Please guide me
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?
I can connect to my office wifi. Even my phone strucks at the same point while trying to connect 😦
my phone too 😦
i am using dell inspiron 5220 laptop,can i use the same procedure in my laptop
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.
You have to start the dhcpd…./etc/inid.d/isc-dhcp-server start | restart
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
thankyu for safe my head 😉
now I can connected to android,,
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..
Same as Nam above. Phone get connected to wifi, but it can’t connect to internet, Ubuntu 12.04. Any ideas?
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.
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
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
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
A perfect solution. Just awesome!!
This is an awesome article bro, It works like charm, thank you so much 🙂
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 ?
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
Just need to use “sudo hostapd hostapd.conf” after bootup… and it work for me.. Tnx.
You then just need to automate the starting up of hostapd during bootup.
I have done that, but my other devices don’t discover the wifi, so I need to run this after boot…
Great 😀
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.
Is there any GUI way for doing this?
Not that I know of, But its a good idea. Maybe i will write one in python as my next programming project.
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.
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
I just use wordpress.
“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!!
How to stop the hotspot ??? It’s always runnning and draining my my battery .
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!
This works perfect. Thanks for it.
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.
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?
Sorry I am not a big blogger. I am just using wordpress