How To Setup A Wireless Access Point On Linux OS using hostapd

by hash3liZer . 18 May 2018

How To Setup A Wireless Access Point On Linux OS using hostapd

In this tutorial, i'll show you to setup a functional wireless access point (hotspot) on linux. We will host an access point and then configure some DHCP network paramters for settling in the traffic routing and will make some amendments according the needs. This would allow us to create and manage our own networks without special needs to care about.

In Windows, users usually used to accomplish this by running a couple command in command prompt and windows do the rest of this task itself by assigning predefined routing tables and IP ranges. Well, in linux we will have to do it ourself. What exactly we will carry out to accomplish this is host a network, let's for easiness say WiFi, and assign the IP ranges for traffic routing.


hostapd is a user-space daemon-process software to manage, host and implement wireless access points on the fly under the influence of nl80211 driver which still is under development phase and not yet fully supported by many adapters.


dnsmasq is a light-weight Dynamic Host Configuration Protocol (DHCP) server with support of dns forwarder, basically designed for small home or office networks. It certainly is fast and easier to modify.


Install Packages

Update the environment and install the required packages. The commands will go like:

sudo apt-get update
sudo apt-get install hostapd dnsmasq

This will install the necessary packages or will update them if they are already installed.

hostapd dnsmasq


Wireless Card

Find your wireless adapter interface:


Here, you see the wireless interface is wlan0. Now, put this interface in monitor mode:

ifconfig wlan0 down
iwconfig wlan0 mode monitor
ifconfig wlan0 up


Access Point

Create a new folder under your home directory to keep all the necessary files. Let's say the home directory is /root/ and ap be the name of folder to keep the network files. So,

sudo mkdir /root/ap
cd /root/ap

Create a hostapd configuration file and write the following instructions:

nano hostapd.conf
ssid=[AP Name] 
channel=[AP Channel]

Press CTRL+X and then y to save the file. Note these parameters in the above configuration:

  • interface: Wireless interface to host access point on.
  • ssid: Essid of Network (Name).
  • channel: AP channel.
  • rsn_pariwise: RSN layer encryption to use.
  • wpa_passphrase: Password for Access Point.

Now, just initiate the Access Point:

hostapd hostapd.conf
hostapd hostapd.conf



We will use dnsmasq for this part. We are required to setup network routing so that traffic could switch between network nodes and a path could be available to send data on. Open a new terminal and create a configuration file for dnsmasq.

nano dnsmasq.conf

Save the file. Note the above parameters:

  • interface: Access Point Interface
  • dhcp-range: IP range for nodes
  • dhcp-option:3: Gateway IP
  • dhcp-option:6: DNS

Now, make some amendments in network routing and kick-start dnsmasq:

ifconfig wlan0 up netmask
route add -net netmask gw
dnsmasq -C dnsmasq.conf -d
dnsmasq -C dnsmasq.conf


Traffic Forward

Until yet, we have our serviceable wireless access point available to use. You can try connecting and exploring it. But still, we have to provide internet access. Traffic forwarding in a manner is a procedure to forward traffic from one network end to another network. Hence, to do it, we are required another wireless or wired connection to our machine.

Lets say we have a wired internet connection on eth0 interface. Now, to forward traffic:

iptables --table nat --append POSTROUTING --out-interface eth0 -j MASQUERADE
iptables --append FORWARD --in-interface wlan0 -j ACCEPT

Note these two arguments in the above commands:

  • --out-interface: should be the interface from which you are forwarding traffic, i.e. eth0
  • --in-interface: Interface of Wireless Access Point for Internet Access, i.e. wlan0

Now, change the IP forward rules to permit the traffic forwarding.

echo 1 > /proc/sys/net/ipv4/ip_forward

After being done. You are good to take a head-shot of your newly created hotspot network.


We have seen to host a wireless access point on linux. At first, we installed the required packages and then give directives to operate our card in monitor mode which was mandatory. After then, we initiated the access point and defined routing tables for nodes to communicate with each other. And at the end, we forwarded traffic from one network to another.