# Software access point (Русский)

Эта страница нуждается в сопроводителе

Статья не гарантирует актуальность информации. Помогите русскоязычному сообществу поддержкой подобных страниц. См. Команда переводчиков ArchWiki

Эта статья или раздел нуждается в переводе

Примечания: Статья практически не переведена (обсуждение: Talk:Software access point (Русский)#)

Программная точка доступа используется, если вы хотите чтобы Ваш компьютер выступал в качестве точки доступа для беспроводной локальной сети. Это решит проблему выбора отдельного беспроводного маршрутизатора(WI-FI).

## Требования

### Поддержка режима AP устройством Wi-Fi

Вам понадобится nl80211 совместимое беспроводное устройство, поддерживающее рабочий режим AP. Это можно проверить, выполнив команду `iw list` , которая должна вывести `AP` в секции `Supported interface modes`:

    $ iw list

    Wiphy phy1
    ...
    	Supported interface modes:
    		 * IBSS
    		 * managed
    		 * AP
    		 * AP/VLAN
    		 * WDS
    		 * monitor
    		 * mesh point
    ...

### Wireless client and software AP with a single Wi-Fi device

Creating a software AP is independent from your own network connection (Ethernet, wireless, ...). Many wireless devices even support simultaneous operation both as AP and as wireless "client" at the same time. Using that capability you can create a software AP acting as a "wireless repeater" for an existing network, using a single wireless device. The capability is listed in the following section in the output of `iw list`:

    $ iw list

    Wiphy phy1
    ...
            valid interface combinations:
                     * #{ managed } <= 2048, #{ AP, mesh point } <= 8, #{ P2P-client, P2P-GO } <= 1,
                       total <= 2048, #channels <= 1, STA/AP BI must match
    ...

The constraint `#channels <= 1` means that your software AP must operate on the same channel as your Wi-Fi client connection; see the `channel` setting in `hostapd.conf` below.

If you want to use the capability/feature, perhaps because an Ethernet connection is not available, you need to create two separate virtual interfaces for using it. Virtual interfaces for a physical device `wlan0` can be created as follows: First, the virtual interfaces are created for the network connection (`wlan0_sta`) itself and for the software AP/hostapd "wireless repeater":

    # iw dev wlan0 interface add wlan0_sta type station
    # iw dev wlan0 interface add wlan0_ap  type __ap

Second, the interfaces are assigned separate MAC addresses (use custom unique addresses):

    # ip link set dev wlan0_sta address 12:34:56:78:ab:cd
    # ip link set dev wlan0_ap  address 12:34:56:78:ab:ce

## Overview

Setting up an access point comprises two main parts:

- Setting up the Wi-Fi link layer, so that wireless clients can associate to your computer's "software access point" and send/receive IP packets from/to your computer; this is what the hostapd package will do for you.
- Setting up the network configuration on you computer, so that your computer will properly relay IP packets from/to its own Internet connection from/to wireless clients.

## Wi-Fi Link Layer

Точка доступа Wi-Fi реализуется с помощью пакета hostapd (доступного из официальных репозиториях). Пакет поддерживает WPA2.

Adjust the options in hostapd configuration file if necessary. Especially, change the `ssid` and the `wpa_passphrase`. See hostapd Linux documentation page for more information.

    /etc/hostapd/hostapd.conf

    ssid=YourWiFiName
    wpa_passphrase=Somepassphrase
    interface=wlan0
    bridge=br0
    auth_algs=3
    channel=7
    driver=nl80211
    hw_mode=g
    logger_stdout=-1
    logger_stdout_level=2
    max_num_sta=5
    rsn_pairwise=CCMP
    wpa=2
    wpa_key_mgmt=WPA-PSK
    wpa_pairwise=TKIP CCMP

    Для автозапуска hostapd в качестве службы запустите hostapd.service.

Warning: The wireless channels allowed for access point operation differ according to geography. Depending on the wireless firmware, you may have to set the region correctly to use legal channels. Do not choose another region, as you may be illegally disturbing network traffic, affecting wireless functionality of your own device and others within its reach! To set the region see Wireless network configuration#Respecting the regulatory domain.
Note: If you have a card based on RTL8192CU chipset, install hostapd-8192cuAUR in the AUR and replace `driver=nl80211` with `driver=rtl871xdrv` in the `hostapd.conf` file.

## Конфигурация сети

There are two basic ways for implementing this:

1. bridge: create a network bridge on your computer (wireless clients will appear to access the same network interface and the same subnet that's used by your computer)
2. NAT: with IP forwarding/masquerading and DHCP service (wireless clients will use a dedicated subnet, data from/to that subnet is NAT-ted -- similar to a normal Wi-Fi router that's connected to your DSL or cable modem)

The bridge approach is simpler, but it requires that any service that's needed by your wireless clients (like, DHCP) is available on your computers external interface. That means it will not work if you have a dial-up connection (e.g., via PPPoE or a 3G modem) or if you're using a cable modem that will supply exactly one IP address to you via DHCP.

The NAT approach is more versatile, as it clearly separates Wi-Fi clients from your computer and it's completely transparent to the outside world. It will work with any kind of network connection, and (if needed) you can introduce traffic policies using the usual iptables approach.

Of course, it is possible to combine both things. For that, studying both articles would be necessary. Example: Like having a bridge that contains both an ethernet device and the wireless device with an static ip, offering DHCP and setting NAT configured to relay the traffic to an additional network device - that can be ppp or eth.

### Настройка моста

You need to create a network bridge and add your network interface (e.g. `eth0`) to it. You should not add the wireless device (e.g. `wlan0`) to the bridge; hostapd will add it on its own.

See Network bridge.

Tip: You may wish to reuse an existing bridge, if you have one (e.g. used by a virtual machine).

### Настройка NAT

Смотрите Раздача интернета для получения дополнительной информации.

Учтите, что в той статье используется устройство `net0` для подключения к локальной сети. В нашем случае в качестве его будет выступать беспроводное устройство (напр. `wlan0`).

## Tools

### create_ap

Скрипт create_ap включает в себя hostapd, dnsmasq и iptables для создания точки доступа посредством Моста/NAT (доступен в AUR create_apAUR).

### RADIUS

Смотрите [1] инструкции для запуска сервера FreeRADIUS для WPA2 Enterprise.

## Решение проблем

### WLAN очень медленно работает

Это может быть вызвано слабой энтропией. Попробуйте установить haveged.

### Вмешательство NetworkManager

hostapd может не работать, если устройство управляется NetworkManager. Вы можете замаскировать устройство:

    /etc/NetworkManager/NetworkManager.conf

    [keyfile]
    unmanaged-devices=mac:<hwaddr>

## Смотрите также

- Router
- Hostapd : The Linux Way to create Virtual Wi-Fi Access Point
- tutorial and script for configuring a subnet with DHCP and DNS

Categories:

- Русский
- Wireless networking (Русский)