trckpd

Wifi Access Point

Wifi Access Point - Ubuntu 14.04(64Bit), Hostapd 1.0, isc-dhcp-server

This document elaborates the steps and reference for creating an wifi access point in a Ubuntu 14.04 system.

Required NIC

nl80211 compliant wireless card/adapter which supports AP mode. In our case, it is Panda 300mbps Wireless-N device, driver - Realtek RTL8188SU 802.11n WLAN Adapter

Required software

  • Hostapd
  • isc-dhcp-server (an alternative is dnsmasq)

Why not ad-hoc ?

Ad-hoc is good where number of devices connected are small and the network is temporary. Due to it’s peer-to-peer nature, with increasing number of devices connected to an ad-hoc network, it will have more interference as each device will try to communicate with others. If the destination device change it’s location and loses direct connection with source, then data travels via multiple devices from source, resulting slower transfer speed. Many wifi-enabled devices refuses ad-hoc connection.

Set-up : All steps require root/superuser access

Installation : hostapd

wget http://archive.ubuntu.com/ubuntu/pool/universe/w/wpa/hostapd_1.0-3ubuntu2.1_amd64.deb
dpkg -i hostapd*.deb
apt-mark hold hostapd
update-rc.d hostapd disable # disable hostapd server at boot

[ The default package of Hostapd for Ubuntu 14.04 is buggy, it gave troubles creating the access point. So needed to downgrade the package. There is a patch available for the default package, have not tried that. ]

Installation : isc-dhcp-server

apt-get install isc-dhcp-server
update-rc.d isc-dhcp-server disable # disable dhcp server at boot

Configuration : DHCP Server

/etc/dhcp/dhcpd.conf - Subnet mask configuration

ddns-update-style none;
log-facility local7;
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;
}

Configuration : hostapd

/etc/hostpad/hostpad.conf - WIFI access point configuration

interface=wlan0
driver=nl80211
ssid=test_ap_wifi
hw_mode=g
channel=1
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=3
wpa_passphrase=123456789
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

[ The hw_mode can be set to “n”, in that case add the following line
wme_enabled=1
ieee80211n=1
ht_capab=[HT40+][SHORT-GI-40][DSSS_CCK-40]
]

/etc/defaults/hostapd - hostapd daemon configuration
DAEMON_CONF="/etc/hostapd/hostapd.conf"
DAEMON_OPTS="-dd" # debug messages

/etc/init.d/wifi_access_point - Wifi access point service

#!/bin/bash

function stop_wifi_ap {
    ### stop services dhcpd and hostapd
    service isc-dhcp-server stop
    service hostapd stop

    ### disable IP forwarding
    echo 0 > /proc/sys/net/ipv4/ip_forward

    ### remove the static IP from the wifi interface
    if grep -q 'auto wlan0' /etc/network/interfaces
    then
        sed -i /etc/network/interfaces -e '/auto wlan0/,\$ d'
        sed -i /etc/network/interfaces -e '\$ d'
    fi

    ### restart network manager to take over wifi management
    service network-manager restart
}

function start_wifi_ap {
    stop_wifi_ap
    sleep 3

    ### see: https://bugs.launchpad.net/ubuntu/+source/wpa/+bug/1289047/comments/8
    nmcli nm wifi off
    rfkill unblock wlan

    ### give a static IP to the wifi interface
    ip link set dev wlan0 up
    ip address add 10.10.0.1/24 dev wlan0

    ### protect the static IP from network-manager restart
    echo >> /etc/network/interfaces
    echo 'auto wlan0' >> /etc/network/interfaces
    echo 'iface wlan0' inet static >> /etc/network/interfaces
    echo 'address 10.10.0.1' >> /etc/network/interfaces
    echo 'netmask 255.255.255.0' >> /etc/network/interfaces

    ### enable IP forwarding
    echo 1 > /proc/sys/net/ipv4/ip_forward

    ### start services dhcpd and hostapd
    service hostapd start
    service isc-dhcp-server start
}

Other consideration

Did not use the iptables based firewall configuration An alternative configuration is to create a bridge interface [ merit or demerit of bridge or NAT is beyond me, I am studying]

Reference :