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

@rn@b K@rm@k@r
Oct 4, 2017 · 3 min read

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 AP, It doesn’t mean it can’t create wireless hotspot. But those cards aren’t in scope of this tutorial.

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 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 /etc/hostapd/hostapd.conf. Press Enter.
  • Paste the following 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

Please make sure there are no trailing white space and the end of the line! Hostapd is very sensitive to ending white spaces that are hard to troubleshoot!

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 your 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. Edit the file /etc/default/hostapd and modify the line of DAEMON_CONF like this:

DAEMON_CONF="/etc/hostapd/hostapd.conf"

Then start the hostapd service using the following command,

sudo service hostapd start

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. Stop it with the command sudo service hostapd stop

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

Edit the file /etc/default/isc-dhcp-server and set INTERFACES like this:

INTERFACES="wlan0"

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 give IP up to 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 service isc-dhcp-server start
sudo service hostapd start

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 or ip address

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. If you are connecting to internet through an android device with USB tethering, then the interface name should be usb0.

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.

@rn@b K@rm@k@r

Written by

J@v@script/NodeJS/Re@ct/Express/Typescript Developer

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade