Přejít na menu

Hostap - complete wi-fi AP configuration

Správa článků

Vyhledávání Vyhledávání
21.9.2014 23:05
,
Počet přečtení: 17678

How to set up wifi AP with WPA2, DHCP and DNS in your Linux computer.

  1. Configure wlan0 interface

    /etc/network/interfaces:
    auto wlan0
    iface wlan0 inet static
        address 192.168.22.1
        netmask 255.255.255.0

  1. Install the package hostapd for managing wireless card in host mode

    sudo apt-get install hostapd

  2. Configure hostap

    File /etc/hostapd/hostapd.conf:
    hw_mode=g
    channel=11
    driver=nl80211

    ssid=my-network-name
    interface=wlan0

    # possible MAC address restriction
    #macaddr_acl=0
    #accept_mac_file=/etc/hostapd.accept
    #deny_mac_file=/etc/hostapd.deny
    #ieee8021x=1    # Use 802.1X authentication

    # encryption
    wpa=2
    wpa_passphrase=my-secret-password
    wpa_key_mgmt=WPA-PSK
    wpa_pairwise=TKIP CCMP
    rsn_pairwise=CCMP
    ctrl_interface=/var/run/hostapd

    # Only root can configure hostapd
    ctrl_interface_group=0

  3. Start hostapd

    sudo hostapd /etc/hostapd/hostapd.conf
    Debug mode: sudo hostapd -dd /etc/hostapd/hostapd.conf

    Possible errors:

    Interface is managed with NetworkManager - check it: nmcli d should tell that intergace is NOT managed
    Take it out from NetworkManager: sudo nmcli nm wifi off
    Another error:
    rfkill: WLAN soft blocked
    Could not set interface wlan0 flags (UP): Operation not possible due to RF-kill
    wlan0: Could not connect to kernel driver
    Solution:
    check interface state: rfkill list
    unblock interface with rfkill: sudo rfkill unblock wlan
    Hostap is already running
    nl80211: Could not configure driver mode
    nl80211 driver initialization failed.
    hostapd_free_hapd_data: Interface wlan0 wasn't started
    ps ax | grep hostap

  4. Try to connect to your new network - you should not obtain an IP address yet

  5. Setup masquerading

  6. Configure DHCP and DNS:

    • With dnsmasq:
      Dnsmasq is not installed by default - only dnsmasq-base is, but it is not usable.

      sudo apt-get install dnsmasq
      /etc/dnsmasq.conf:
      interface=wlan0
      dhcp-range=192.168.22.2,192.168.22.100,2h
      #dhcp-host=11:22:33:44:55:66,192.168.1.2

      Dnsmasq must be set in NetworkManager in /etc/NetworkManager/NetworkManager.conf:
      dns=dnsmasq

    • Old approach: 

Autostart of hostapd

Add to the /etc/rc.local:
rfkill unblock wlan0 && hostapd /etc/hostapd/hostapd.conf

  • Take out wlan interface from NetworkManager config (see error in Start hostapd): /etc/NetworkManager/NetworkManager.conf:

[keyfile]
unmanaged-devices=mac:<WLAN_MAC_ADDRESS>
Maybe the same there: no-auto-default=<WLAN_MAC_ADDRESS>

Bash script wifiup.sh:

#! /bin/bash
if [ `ps ax | grep hostap | grep -v grep | wc -l` -eq 0 ]; then
    echo `rfkill list` > /tmp/wifi-rfkill-on-start
    rfkill unblock wlan && hostapd /etc/hostapd/hostapd.conf & > /tmp/hostap.log
fi

Vytvořil 21. září 2014 ve 23:31:45 mira. Upravováno 8x, naposledy 14. října 2015 ve 22:06:41, mira


Diskuze ke článku

Vložení nového komentáře
*
*
*