Difference between revisions of "Software access point"

From ArchWiki
Jump to: navigation, search
(Wifi Link Layer: improved wording, formatted and clarified note about RTL8192CU chipset)
(33 intermediate revisions by 14 users not shown)
Line 1: Line 1:
{{i18n|Software Access Point}}
+
[[ru:Software Access Point]]
[[Category:Wireless Networking (English)]]
+
[[Category:Wireless Networking]]
 +
{{Article summary start}}
 +
{{Article summary text|Basic setup of wifi access point.}}
 +
{{Article summary heading|Related}}
 +
{{Article summary wiki|Network Configuration}}
 +
{{Article summary wiki|Wireless Setup}}
 +
{{Article summary wiki|Ad-hoc networking}}
 +
{{Article summary wiki|Internet Sharing}}
 +
{{Article summary end}}
 +
A software access point is used when you want your computer to act as an wifi access point for the local wireless network. It saves you the trouble of getting a separate wireless router.
  
A software access point is used when you want your computer to act as an access point for the local wireless network. It saves you the trouble of getting a separate wireless router.
+
== Requirements ==
  
= Things you need =
+
* A nl80211 compatible wireless device (e.g. ath9k)
  
You will need:
+
== Overview ==
  
* prism2/2.5/3 pure pci wireless card or nl80211 compatible cards (e.g. ath9k)
+
Setting up an access point comprises two main parts:
* wireless_tools, hostapd and bridge-utils from pacman
+
* Setting up the '''wifi 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.
  
== Steps to implement ==
+
== Wifi Link Layer ==
  
The config file of hostapd /etc/hostapd/hostapd.conf will help you to put your wireless device into master mode and willing to accept connection from other computers with encrypted password.
+
The actual Wifi link is established via the {{Pkg|hostapd}} package (available in the [[official repositories]]). The package has WPA2 support.
  
Here is an example from http://www.su-root.eu/computing/turn-your-linux-computer-in-a-wireless-access-point-using-hostapd:
+
Adjust the options in ''hostapd'' configuration file if necessary. Especially, change the {{ic|ssid}} and the {{ic|wpa_passphrase}}.
  
interface=wlan0
+
{{hc|/etc/hostapd/hostapd.conf|<nowiki>
bridge=br0
+
ssid=YourWifiName
driver=nl80211
+
wpa_passphrase=Somepassphrase
logger_stdout=-1
+
interface=wlan0
logger_stdout_level=2
+
bridge=br0
ssid=test
+
auth_algs=3
hw_mode=g
+
channel=7
channel=6
+
driver=nl80211
auth_algs=3
+
hw_mode=g
max_num_sta=5
+
logger_stdout=-1
wpa=2
+
logger_stdout_level=2
wpa_passphrase=tryyourbest
+
max_num_sta=5
wpa_key_mgmt=WPA-PSK
+
rsn_pairwise=CCMP
wpa_pairwise=TKIP CCMP
+
wpa=2
rsn_pairwise=CCMP
+
wpa_key_mgmt=WPA-PSK
 +
wpa_pairwise=TKIP CCMP
 +
</nowiki>}}
  
=== Set up bridge with kernel >= 2.6.33 ===
+
For automatically starting hostapd, [[Daemon|enable]] the {{ic|hostapd.service}}.
{{Out of date}}
+
Due to changes in the kernel since version 2.6.33 [http://bugs.gentoo.org/show_bug.cgi?id=298824 bridges cannot contain an uninitialized interface].
+
Because of this we need hostapd to add the wlan interface to the bridge instead.
+
  
Requirements:
+
{{Note|If you have a card based on RTL8192CU chipset, you will have to build [http://anarsoul.blogspot.com.es/2013/08/access-point-with-raspberry-pi-and.html this] patched version of ''hostapd'' and replace {{ic|1=driver=nl80211}} with {{ic|1=driver=rtl871xdrv}} in the {{ic|hostapd.conf}} file.}}
* kernel >= 2.6.33
+
* hostapd >= 0.7.1
+
* bridge-utils
+
  
One way to set this up since the [http://bbs.archlinux.org/viewtopic.php?id=120549 changes in rc.conf] because of the deprecation of [http://www.archlinux.org/news/deprecation-of-net-tools/ net-tools] is to use [[Netcfg]]:
+
== Network configuration ==
  
Setup a profile in /etc/network.d/ (for example called "bridge").
+
There are two basic ways for implementing this:
 +
# '''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)
 +
# '''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 WiFi router that's connected to your DSL or cable modem)
  
{{hc|/etc/network.d/bridge|2=
+
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 dialup 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.
INTERFACE="br0"
+
CONNECTION="bridge"
+
DESCRIPTION="Bridge wired and wireless connection"
+
  
# Only add wired interface here, hostapd will add wireless
+
The NAT aproach is more versatile, as it clearly separates wifi 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.
BRIDGE_INTERFACES="eth0"
+
IP="dhcp"}}
+
  
In rc.conf make sure you do the following:
+
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.
  
* Add the bridge profile to the NETWORKS list.
+
=== Bridge Setup ===
* Make sure you are starting the profiles by adding net-profiles to the DAEMONS list.
+
* Start hostapd after net-profiles by adding it to the DAEMONS list.
+
  
{{hc|/etc/rc.conf|2=
+
You need to create a network ''bridge'' and add your network interface (e.g. {{ic|eth0}}) to it. You '''should not''' add the wireless device (e.g. {{ic|wlan0}}) to the bridge; hostapd will add it on its own.
NETWORKS=( bridge )
+
  
...
+
If you use [[netctl]], see [[Bridge with netctl]] for details (just do not add {{ic|tap0}} used in that example).
  
DAEMONS=( ... net-profiles hostapd ... )
+
=== NAT Setup ===
}}
+
  
Reboot the machine and use another computer to see if you can find the "test" wireless connection.
+
See [[Internet Sharing]] for details.
  
If you do not want to reboot these commands should work:
+
On that article, the device connected to the lan is {{ic|net0}}. That device would be in this case your wireless device (e.g. {{ic|wlan0}}).
  
  netcfg up bridge
+
== Scripts ==
  rc.d start hostapd
+
  
=== Old way to set up bridge ===
+
[https://bbs.archlinux.org/viewtopic.php?pid=1269258 create_ap] script combines {{Pkg|hostapd}}, [[dnsmasq]] and [[iptables]] to create a NATed Access Point.
  
before hostapd does its job, eth0, wlan0 and br0 must be up and do not have any address. we can put the following lines in /etc/rc.conf
+
== Troubleshooting ==
  
eth0="eth0 up"
+
===WLAN is very slow===
wlan0="wlan0 up"
+
br0="br0 192.168.0.2 netmask 255.255.255.0 up"
+
INTERFACES=(lo eth0 wlan0 br0)
+
  
in the /etc/conf.d/bridges file, uncomment the lines (change eth1 to wlan0)
+
This could be caused by low entropy. Consider installing [[haveged]].
  
bridge_br0="eth0 wlan0"
+
===NetworkManager is interfering===
BRIDGE_INTERFACES=(br0)
+
  
we are ready to go, just reboot the machine and use another computer to see if you can find the "test" wireless connection.
+
hostapd may not work, if the device is managed by NetworkManager. You can mask the device:
  
{{note|*untested* if your computer stops at the sign of "waiting for IP address" etc, that may be it can not find a dhcp server. so you need to set up one.}}
+
{{hc|/etc/NetworkManager/NetworkManager.conf|<nowiki>
 +
[keyfile]
 +
unmanaged-devices=mac:<hwaddr>
 +
</nowiki>}}
  
 
== See also ==
 
== See also ==
  
* http://wireless.kernel.org/RTFM-AP
+
* [http://wireless.kernel.org/RTFM-AP hostapd Linux documentation page]
 
* [[Router]]
 
* [[Router]]
 +
* [http://nims11.wordpress.com/2012/04/27/hostapd-the-linux-way-to-create-virtual-wifi-access-point/ Hostapd : The Linux Way to create Virtual Wifi Access Point]
 +
* [http://xyne.archlinux.ca/notes/network/dhcp_with_dns.html tutorial and script for configuring a subnet with DHCP and DNS]

Revision as of 21:08, 1 November 2013

Template:Article summary start Template:Article summary text Template:Article summary heading Template:Article summary wiki Template:Article summary wiki Template:Article summary wiki Template:Article summary wiki Template:Article summary end A software access point is used when you want your computer to act as an wifi access point for the local wireless network. It saves you the trouble of getting a separate wireless router.

Requirements

  • A nl80211 compatible wireless device (e.g. ath9k)

Overview

Setting up an access point comprises two main parts:

  • Setting up the wifi 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.

Wifi Link Layer

The actual Wifi link is established via the hostapd package (available in the official repositories). The package has WPA2 support.

Adjust the options in hostapd configuration file if necessary. Especially, change the ssid and the wpa_passphrase.

/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

For automatically starting hostapd, enable the hostapd.service.

Note: If you have a card based on RTL8192CU chipset, you will have to build this patched version of hostapd and replace driver=nl80211 with driver=rtl871xdrv in the hostapd.conf file.

Network configuration

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 WiFi 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 dialup 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 aproach is more versatile, as it clearly separates wifi 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.

Bridge Setup

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.

If you use netctl, see Bridge with netctl for details (just do not add tap0 used in that example).

NAT Setup

See Internet Sharing for details.

On that article, the device connected to the lan is net0. That device would be in this case your wireless device (e.g. wlan0).

Scripts

create_ap script combines hostapd, dnsmasq and iptables to create a NATed Access Point.

Troubleshooting

WLAN is very slow

This could be caused by low entropy. Consider installing haveged.

NetworkManager is interfering

hostapd may not work, if the device is managed by NetworkManager. You can mask the device:

/etc/NetworkManager/NetworkManager.conf
[keyfile]
unmanaged-devices=mac:<hwaddr>

See also