Share computer’s internet through wifi using hostapd

Share computer’s Internet to other wifi receiving devices (phones, laptops etc)

Host Operating System: Ubuntu 12.04

1. Find if your card is supported
2. Install necessary software
3. Configure
4. Connect

1. Find if your card is supported.

You have to have internet connected on the computer from devices other than wireless from which you want to share the internet. It will act as internet distributor not receiver. Make sure you have internet connected. Typical situation would be a internet connected through wired cable. In my case I am connected through DSL and it has interface ppp0. You might have internet on eth0 (see if it has an entry for inet addr). Though the card is eth0 my internet has interface as ppp0. You can check the interface using “ifconfig” command on the terminal.

a. Find if the wireless driver is supported by the sharing software (hostapd). Type this commands to find the Kernel drive in use. Here command follows the output of the program.

$ lspci -k | grep -A 3 -i "network"

02:00.0 Network controller: Intel Corporation Centrino Wireless-N 1030 (rev 34)
Subsystem: Intel Corporation Centrino Wireless-N 1030 BGN
Kernel driver in use: iwlwifi
Kernel modules: iwlwifi

As you can see the driver used in iwlwifi, lets find more information about this driver.

$ modinfo iwlwifi | grep 'depend'
depends: mac80211,cfg80211

I know mac80211 is supported by hostapd. Find out if the dependent driver is supported by hostpad with a simple google search or visit following sites.


2. Install necessary software
$ sudo apt-get install hostapd dhcp3-server

3. Configure

We need to configure two files (hostapd.conf and dhcpd.conf). Finally we will write a script that will start hostpad, load up drivers, start dhcp. Once you run the script you will be able to search for the wifi with given ssid, use a wpa password and start using this computers internet.

a. Edit /etc/hostapd/hostpad.conf with following settings (if you have interface other than wlan0 for wifi, want another name for ssid or passphrase do so below)

wpa_pairwise=TKIP CCMP

b. Edit /etc/dhcp/dhcpd.conf.

Comment all lines except

log-facility local7;
ddns-update-style none;
default-lease-time 600;
max-lease-time 7200;

Specially these lines

# option definitions common to all supported networks…
# option domain-name “”;
# option domain-name-servers,;

Add following lines to end of the file

option domain-name-servers, ;

subnet netmask {
option subnet-mask;
option broadcast-address;
option routers;

This file will provide the ip address to other devices in this range.

c. Create a start script e.g ~/bin/gohostapd with following text


rmmod iwlwifi
modprobe iwlwifi

iwconfig wlan0 mode Master freq 2.42G essid testhostapd
sleep 2
ifconfig wlan0

iptables -t nat -A POSTROUTING -s -o ppp0 -j MASQUERADE
iptables -A FORWARD -s -o ppp0 -j ACCEPT
iptables -A FORWARD -d -m state –state ESTABLISHED,RELATED -i ppp0 -j ACCEPT

echo 1 >/proc/sys/net/ipv4/conf/all/forwarding

echo ‘INTERFACES=wlan0’ >/etc/default/dhcp
dhcpd wlan0
hostapd -d /etc/hostapd/hostapd.conf

As you might have noted above we remove the wifi driver model before re-enabling it, so make sure you write your wifi driver name there. Similarly as value to essid type correct ssid (in our case it is testhostapd). If you wireless interface is other than wlan0, you know what to change it to. Here we share ppp0 internet, if you have another interface which has internet, choose than instead of ppp0. If you have different interfaces to get internet, you can always write copies of similar script to connect to each.

4. Connect

Whenever you want to share your computer’s internet (in this case ppp0) you just have to run the script (here gohostapd) as root (for first time chmod +x ~/bin/gohostapd to make it executable).

$ sudo ~/bin/gohostapd

In your other device (from where you want to use this computer’s internet), find the ssid, provide the password (WPA Personal), wait for ip address provided by dhcp. If the device does not get an ip it will not be able to connect, so make sure you recheck above procedure.

Note: If you don’t have internet connection on ppp0, still you can share the wifi. In this case none of the device will have internet connection, but you can still share files via wifi. When you run above script some warning message might show constantly, its normal as long as the connecting device can connect to the internet. Later when you want to stop sharing and use the wifi as regular receiver you can cancel above script and connect to wifi from the computer as normal.


1. Ubuntu 12.04 – setting up my Wifi Hotspot
2. Hostapd : The Linux Way to create Virtual Wifi Access Point


Tags: , , , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s