Turn your desktop computer into a wireless access point

My desktop computer has a wired connection to the internet and so the built-in wifi card is normally not used. I decided to enable and use it as a wireless access point.

Unfortunately NetworkManager will only create an ad-hoc wifi network, and Android devices will only connect to infrastructure access points. Don’t ask why… A rooted Android phone or tablet can be configured to connect to an ad-hoc network, and if a separate program can configure a Linux box to act as an access point, NetworkManager should be able to do the same. As far as I can see, there are no good technical reasons for either of these deficiencies.

The solution is hostapd:

First tell NetworkManager not to interfere and leave the wifi hardware in peace:

sudo nano /etc/NetworkManager/NetworkManager.conf

where ab:cd:ef:12:34:56 is the MAC address of your wifi card.

Install and configure hostapd, dnsmasq and configure wlan0 interface and ipv4 forwarding:

sudo apt-get install hostapd dnsmasq
sudo service hostapd stop
sudo service dnsmasq stop
# these are only needed if you do not want the services to start automatically on boot
sudo update-rc.d hostapd disable
sudo update-rc.d dnsmasq disable
sudo nano /etc/default/hostapd
sudo nano /etc/init.d/hostapd
# The following line seems to reset the config file path (set in /etc/default/hostapd)?!
sudo nano /etc/hostapd.conf
# Define interface
# Select driver
# Set access point name
# Set access point harware mode to 802.11g
# Set WIFI channel (can be easily changed)
# Enable WPA2 only (1 for WPA, 2 for WPA2, 3 for WPA + WPA2)
sudo nano /etc/dnsmasq.conf
# Bind to only one interface
# Choose interface for binding
# Specify range of IP addresses for DHCP leasses
sudo nano /etc/network/interfaces
# The loopback network interface
auto lo
iface lo inet loopback

auto wlan0
iface wlan0 inet static
hostapd /etc/hostapd.conf
sudo nano /etc/sysctl.conf 
sudo nano /etc/rc.local
# enable NAT for wireless access point on wlan0
iptables -t nat -A POSTROUTING -s ! -d  -j MASQUERADE

Bring up wlan0 interface and restart services

ifup wlan0
sudo service dnsmasq restart
sudo service hostapd restart

Additional information

  • https://www.mankier.com/5/NetworkManager.conf#Keyfile_Section
  • http://seravo.fi/2014/create-wireless-access-point-hostapd
  • http://forum.xda-developers.com/showthread.php?t=2009381
  • https://wiki.archlinux.org/index.php/Software_access_point
  • http://w1.fi/cgit/hostap/plain/hostapd/README

ip link set dev wlp0s20f0u4 up

Leave a Reply

Your email address will not be published. Required fields are marked *