CentOS 7 HOSTAPD AP Mode configuration

Source: Internet
Author: User



Recently want to make a no line, Linux under the non-line/wireless AP Implementation is HOSTAPD this software.



There are a lot of HOSTAPD on the internet, Baidu will be able to get a lot of relevant information, here just finishing my own configuration hostapd a step, the process also encountered large and small pits, easy to avoid after the query.


Hardware section


Operating mode of the AP we only need a wireless card and a cable network card. Wireless Card PCI interface or USB interface can be, wired network cards are usually integrated on the motherboard or plugged in the motherboard of the rate of hundreds of megabytes/gigabit, the market is also very common.



The general Linux system kernel already supports most hardware models by default and works well, if you encounter a network card model that is not recognized by the kernel, you need to manually install the driver module or manually compile it. It is not within the scope of this article to fix the driving method and the relevant steps.



To use AP mode, the wireless card first supports AP mode. How to detect whether the wireless card supports AP mode can be viewed by the following command:


IW List
[[email protected] ~]# iw list
Wiphy phy0
... Omit...
Supported interface modes:
* IBSS
* managed
*AP - indicates that the wireless network card supports AP mode
* AP/VLAN
* monitor
... Omit...


My Intel Corporation Centrino wireless-n 105 Wireless card supports 5 types, and AP mode is also in the supported range.


Software section


I am using the CentOS 7 system, has been updated to CentOS 7.1, the official does not actually provide HOSTAPD package, the first step to use HOSTAPD This software is to enable the source of Epel.



About the Epel source of the introduction please yourself Baidu or see "CentOS 7 Installation Epel source."


1. Install EPEL source
Yum Update #update the system firstly
Yum Install Epel-release #install the EPEL source
2. Installing HOSTAPD Software


We may not know what packages the system provides for HOSTAPD, and you can search for packages that contain HOSTAPD.



Of course, if the Epel source is not installed and enabled, no results can be found through the Yum Search < package name string > command. After installing and enabling the Epel source, use the following command to search.


Yum Search HOSTAPD
[[email protected] ~]# yum search hostapd
Loaded plug-ins: faststmirror, remove with leaves
Loading mirror speeds from cached hostfile
============================ N/S matched: hostapd ============================
hostapd-logwatch.x86_64 : Logwatch scripts for hostapd
hostapd.x86_64 : IEEE 802.11 AP, IEEE 802.1X/WPA/WPA2/EAP/RADIUS Authenticator


From the above you can see that hostapd.x86_64 is the package we want to install using Yum.


Yum Install HOSTAPD


Then the next configuration to use HOSTAPD is to start with the files in his package. So first look at the list of files provided by the HOSTAPD package and use RPM-QL < package name > to query.


RPM-QL HOSTAPD
[[email protected] ~]# rpm -ql hostapd
/etc/hostapd
/Etc / hostapd / hostapd.conf the most important configuration file
/etc/sysconfig/hostapd
/Usr / lib / SYSTEMd / system / hostapd.service - service script
/Usr / SBIN / hostapd - main commands
/usr/sbin/hostapd_cli
... Omit...
/Usr / share / Doc / hostapd-2.4/hostapd.conf ා the folder contains relevant configuration examples. Please refer to
... Omit...
/Usr / share / man / man1 / hostapd? Cli.1.gz? Man manual
/usr/share/man/man8/hostapd.8.gz
3. Start or stop HOSTAPD operation


If you need to boot the HOSTAPD service automatically


Systemctl Enable Hostapd.service


Manual start


Systemctl Start Hostapd.service


Restart


Systemctl Restart Hostapd.service


Stop it


Systemctl Stop Hostapd.service


Disable start-up automatically


Systemctl Disable Hostapd.service
4. HOSTAPD AP Mode configuration


The first thing to note is that the default installation of HOSTAPD is not configured and cannot be started.



As you can see from the RPM-QL HOSTAPD command above, the HOSTAPD package already provides the most complete and detailed description of hostapd.conf, which is the/usr/share/doc/hostapd-< version number in the list of package files above >/ hostapd.conf this file, but it's all in English. See the CentOS 7 hostapd.conf configuration note For Hostapd.conf's Chinese instructions.



Follow our request HOSTAPD to start up and work properly and meet the following points:


    1. Working in AP Mode

    2. Require password when connecting


Working in AP mode requires a wired network card and a wireless card for bridging, which requires that we first establish a bridging interface.


Use the NMCLI command to configure:


First use the IP link command to see which of the native computer has been identified as the NIC name:


IP link
[[email protected] ~]# ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: p2p1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT group default qlen 1000
    link/ether 00:14:78:66:2e:a7 brd ff:ff:ff:ff:ff:ff
3: wlp2s0: <BROADCAST,MULTICAST> mtu 1500 qdisc mq state DOWN mode DEFAULT group default qlen 1000
    link/ether 90:94:e4:78:49:b5 brd ff:ff:ff:ff:ff:ff


Using NMCLI to establish a bridge interface Br0 and set up automatic connection, "Br0" can be set freely, as long as the configuration consistent up and down can be. In order to facilitate general use, the General Bridge interface is named in this way.


NMCLI Connection Add type bridge AutoConnect Yes save Yes ifname br0


Adding the Wired interface p2p1 to the bridging interface Br0, the network interface in CentOS 7 is no longer named in the same way as in the previous eth0 eth1, but will be named after the bus sequence, I am here the PCI Gigabit network adapter for P2P1 Some motherboards will be similar to enp2s0 this.


NMCLI connection Add type Bridge-slave autoconnect Yes save Yes ifname P2P1 Master Br0


View Interfaces


[[email protected] ~]# nmcli connection show 
NAME               UUID                                  TYPE            DEVICE
bridge-br0         bc7e63a4-7fee-4419-8f09-e316a78f42e7  bridge          br0
bridge-slave-p2p1  59fc1f91-4e60-4388-ad41-1a4937c8ff25  802-3-ethernet  p2p1





Pit Tip: actually to this step, here we only built a bridge with only one wired interface, and did not include the wireless interface. In fact, the NMCLI command does not support the wireless interface to join the bridge interface Br0 wireless interface to join the bridge can only be done through hostapd.conf.






Although the command to join the wireless NIC interface to the bridge can be performed normally.


NMCLI connection Add type Bridge-slave autoconnect Yes save Yes ifname Wlp2s0 Master Br0


However, note the device field when the network connection is displayed, and the device field for the newly added wireless card is "--" empty.


NMCLI Connection Show
[[email protected] ~]# nmcli connection show 
NAME                      UUID                                  TYPE            DEVICE
bridge-br0                bc7e63a4-7fee-4419-8f09-e316a78f42e7  bridge          br0
bridge-slave-p2p1         59fc1f91-4e60-4388-ad41-1a4937c8ff25  802-3-ethernet  p2p1
bridge-slave-wlp2s0       18880002-44c1-4a84-968a-66670c00322f  802-3-ethernet  --


When you activate the connection, you are prompted not to find the device.


NMCLI Connection up Bridge-slave-wlp2s0
[[email protected] ~]# nmcli connection up bridge-slave-wlp2s0 Error:no device found for connection ' Bridge-slave-wlp2s0 ' .


All right...... Remove the unused wireless bridging connection.


NMCLI Connection Delete Bridge-slave-wlp2s0





Continue below:



Previously mentioned in the hostapd.conf of the Chinese note can see the "CentOS 7 hostapd.conf configuration instructions."



Here is just a minimal configuration:


#/ etc / hostapd / hostapd.conf minimize configuration
interface=wlp2s0
Bridge = BR0. This parameter is used to bridge the wireless network card to BR0
driver=nl80211
Ssid=test
Hw_mode=g
Channel=1
Auth_algs=3
Ignore? Broadcast? SSID = 0? Broadcast or not, 0 broadcast
Wpa=3
WPA ﹣ passphrase = 12345678 ﹣ wireless connection password





Pit Tip: as I mentioned in the previous tip, we've only built a bridge with a single wired interface. Please note the above bridge=br0 option, which is very important, if you want to run AP mode, you must specify the bridge interface to be bridged. BRIDGE=BR0 option Description Add the Wireless card interface Wlp2s0 to the bridge Br0, the wireless NIC interface is specified by the first line INTERFACE=WLP2S0 option. This br0 is a network bridge that contains the wired interface P2P1 and a wireless interface wlp2s0.





Other command modes are configured:


There are other ways to build a bridge, but if it is under CentOS 7, the simplest thing to do is to use the NMCLI command, as CentOS 7 defaults to providing the Neteorkmanager software, which is valid after the connection is configured with the NMCLI command. But NMCLI is not omnipotent, mentioned before, I currently encountered two problems: 1. NMCLI does not support adding the wireless card to the Network Bridge; 2. So far nmcli does not support setting the wireless card static IP address (this will be encountered in the HOSTAPD configuration routing mode).



See <<<<<< This article >>>>>>> for the CentOS 7 bridging network configuration.


Start the HOSTAPD service


To this we have configured the Network Bridge, the bridge will automatically get the IP address, gateway and DNS settings from the router, that is, the computer will automatically be able to surf the Internet. HOSTAPD is also configured, SSID is test, password 12345678. Because it is a bridge interface, when the wireless client connection is successful, it will automatically obtain the IP address, gateway and DNS settings from the router.



Now it's time to start the HOSTAPD service.


Systemctl Start Hostapd.service


And the result does start to fail, check the service status:


Systemctl Status Hostapd.service
[[email protected] ~]# systemctl status hostapd          
● hostapd.service - Hostapd IEEE 802.11 AP, IEEE 802.1X/WPA/WPA2/EAP/RADIUS Authenticator
   Loaded: loaded (/etc/systemd/system/hostapd.service; enabled)
   Active: failed (Result: exit-code) since 一 2015-09-21 20:19:49 CST; 3s ago
  Process: 6897 ExecStart=/usr/sbin/hostapd /etc/hostapd/hostapd.conf -P /run/hostapd.pid $OTHER_ARGS (code=exited, status=1/FAILURE)
 Main PID: 6897 (code=exited, status=1/FAILURE)
9月 21 20:19:49 server hostapd[6897]: wlp2s0: interface state HT_SCAN->DISABLED
9月 21 20:19:49 server hostapd[6897]: wlp2s0: AP-DISABLED
9月 21 20:19:49 server hostapd[6897]: wlp2s0: Unable to setup interface.
9月 21 20:19:49 server hostapd[6897]: wlp2s0: interface state DISABLED->DISABLED
9月 21 20:19:49 server hostapd[6897]: wlp2s0: AP-DISABLED
9月 21 20:19:49 server hostapd[6897]: hostapd_free_hapd_data: Interface wlp2s0 wasn‘t started
9月 21 20:19:49 server hostapd[6897]: nl80211: deinit ifname=wlp2s0 disabled_11b_rates=0
9月 21 20:19:49 server systemd[1]: hostapd.service: main process exited, code=exited, status=1/FAILURE
9月 21 20:19:49 server systemd[1]: Unit hostapd.service entered failed state.
9月 21 20:19:49 server systemd[1]: hostapd.service failed.


The above actually does not see any specific details of the problem.


5, HOSTAPD debugging


First look at man HOSTAPD's manual to find out how to debug.


Mans HOSTAPD
[[email protected] ~]# man hostapd
... Omit...
Hostapd [-hdbktv] [-p ] <configuration file(s)=""></configuration></pid>
-h Show the usage.
-d Show more debug messages. # debug option
-dd Show even more debug messages. # debug options detailed output
-B Run daemon in the background.
-p  Path to PID file.</pid>
-k Include key data in debug messages.
-t Include timestamps in some debug messages.
The -v Show hostapd version.
... Omit...


It seems to be very simple and roughly what is above. Then run in debug mode.


/usr/sbin/hostapd/etc/hostapd/hostapd.conf-d
[[email protected] ~]# /usr/sbin/hostapd /etc/hostapd/hostapd.conf -d
……omit……
Could not set interface wlp2s0 flags (UP): Operation not possible due to RF-kill
nl80211: Failed to set interface up after switching mode
……omit……





pit Hint:"Operation not possible due to Rf-kill", then Rf-kill is what? About Rf-kill can look at this "Rfkill wireless device soft switch".






All right, install the Rfkill package first.


Yum Install Rfkill


See if the wireless card is turned off.


Rfkill List
[Email protected] ~]# rfkill list0:phy0:Wireless LAN Soft blocked:yes Hard Blocked:no


Unlock


Rfkill unblock WLAN
[[email protected] ~]# Rfkill unblock WLAN


Run Debug mode again


/usr/sbin/hostapd/etc/hostapd/hostapd.conf-d


Ok everything is fine, then you can end debugging start the service in normal mode


Systemctl Start Hostapd.service


Get.


6. Configuration Summary


In the configuration of the HOSTAPD AP mode, it is possible to actually encounter and solve the problem that is the configuration of the bridge, and it is a bit of a miracle.



This article is from "Lao Ding's Linux" blog, please be sure to keep this source http://laoding.blog.51cto.com/980622/1697017



CentOS 7 HOSTAPD AP Mode configuration


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.