Difference between revisions of "Ad-hoc networking"

From ArchWiki
Jump to: navigation, search
m (Custom systemd service (with wpa_supplicant and static IP): rm link, rm pid (not required), fixed config path)
(Requirements: Add link to compatible drivers.)
 
(17 intermediate revisions by 7 users not shown)
Line 1: Line 1:
[[Category:Wireless Networking]]
+
[[Category:Wireless networking]]
 +
[[ja:アドホックネットワーク]]
 
[[zh-CN:Ad-hoc networking]]
 
[[zh-CN:Ad-hoc networking]]
{{Article summary start}}
+
{{Related articles start}}
{{Article summary text|Basic setup of ad-hoc network.}}
+
{{Related|Network configuration}}
{{Article summary heading|Related}}
+
{{Related|Wireless network configuration}}
{{Article summary wiki|Network Configuration}}
+
{{Related|Software access point}}
{{Article summary wiki|Wireless Setup}}
+
{{Related|Internet sharing}}
{{Article summary wiki|Software Access Point}}
+
{{Related articles end}}
{{Article summary wiki|Internet Share}}
+
An IBSS (Independent Basic Service Set) network, often called an ad-hoc network, is a way to have a group of devices talk to each other wirelessly, without a central controller. It is an example of a peer-to-peer network, in which all devices talk directly to each other, with no inherent relaying.
{{Article summary end}}
+
An IBSS (Independent Basic Service Set) network, often called an ad-hoc network, is a way to have a group of devices talk to each other wirelessly, without a central controller. It is an example of an peer-to-peer network, in which all devices talk directly to each other, with no inherent relaying.
+
  
For example, you can set up ad-hoc networking to [[Internet Share|share an internet connection]].
+
For example, ad-hoc networking may be used to [[Internet sharing|share an internet connection]].
  
 
== Requirements ==
 
== Requirements ==
  
* A nl80211 compatible wireless device (e.g. ath9k) on all devices which will connect to the network
+
* A [https://wireless.wiki.kernel.org/en/users/drivers| nl80211 compatible] wireless device (e.g. ath9k) on all devices which will connect to the network
  
 
== Wifi link layer ==
 
== Wifi link layer ==
  
Since IBSS network is a peer-to-peer network, the steps necessary to set up wifi link layer should be the same on all devices.
+
Since IBSS network is a peer-to-peer network, the steps necessary to set up the wifi link layer should be the same on all devices.
  
 
{{Tip|It is possible to create complex network topologies, see [http://wireless.kernel.org/en/users/Documentation/iw/vif Linux Wireless documentation] for advanced examples.}}
 
{{Tip|It is possible to create complex network topologies, see [http://wireless.kernel.org/en/users/Documentation/iw/vif Linux Wireless documentation] for advanced examples.}}
Line 27: Line 26:
 
{{Warning|This method creates '''unencrypted''' ad-hoc network. See [[#WPA supplicant]] for method using WPA encryption.}}
 
{{Warning|This method creates '''unencrypted''' ad-hoc network. See [[#WPA supplicant]] for method using WPA encryption.}}
  
This section is very similar to [[Wireless Setup#Manual setup]], see there for better explanation of the following commands. Also make sure that {{Pkg|iw}} is [[pacman|installed]].
+
See [[Wireless network configuration#Manual setup]] for a better explanation of the following commands. Make sure that {{Pkg|iw}} is [[pacman|installed]].
  
 
Set the operation mode to ibss:
 
Set the operation mode to ibss:
Line 33: Line 32:
 
  # iw ''interface'' set type ibss
 
  # iw ''interface'' set type ibss
  
Bring the interface up (additional step like {{ic|rfkill unblock wifi}} might be needed):
+
Bring the interface up (an additional step like {{ic|rfkill unblock wifi}} might be needed):
  
 
  # ip link set ''interface'' up
 
  # ip link set ''interface'' up
  
Now you can create ad-hoc network. Replace ''your_ssid'' with the name of the network and ''frequency'' with the frequency in MHz, depending on which channel you want to use. See the Wikipedia page [[Wikipedia:List_of_WLAN_channels#Interference_Concerns|List of WLAN channels]] for a table showing frequencies of individual channels.
+
Now you can create an ad-hoc network. Replace ''your_ssid'' with the name of the network and ''frequency'' with the frequency in MHz, depending on which channel you want to use. See the Wikipedia page [[Wikipedia:List_of_WLAN_channels#Interference_Concerns|List of WLAN channels]] for a table showing frequencies of individual channels.
  
 
  # iw ''interface'' ibss join ''your_ssid'' ''frequency''
 
  # iw ''interface'' ibss join ''your_ssid'' ''frequency''
Line 45: Line 44:
 
{{Note|This method creates ad-hoc network using WPA encryption. WPA2 is currently not supported (August 2013).}}
 
{{Note|This method creates ad-hoc network using WPA encryption. WPA2 is currently not supported (August 2013).}}
  
Create configuration file for ''wpa_supplicant''. See [[WPA supplicant]] for details. Also make sure that {{Pkg|wpa_supplicant}} is [[pacman|installed]].
+
Ensure that {{Pkg|wpa_supplicant}} is [[pacman|installed]], and create a configuration file for it (see [[WPA supplicant]] for details).
  
 
{{hc|/etc/wpa_supplicant-adhoc.conf|<nowiki>
 
{{hc|/etc/wpa_supplicant-adhoc.conf|<nowiki>
Line 71: Line 70:
 
== Network configuration ==
 
== Network configuration ==
  
The final step is to assign an IP address to all devices in the network. There are multiple ways to do this, choose what suits you best:
+
The final step is to assign an IP address to all devices in the network. There are multiple ways to do this:
  
* Assign static IP addresses. See [[Network Configuration#Static IP address]] for details.
+
* Assign static IP addresses. See [[Network configuration#Static IP address]] for details.
 
* Running DHCP server on one device. See [[dhcpd]] or [[dnsmasq]] for details.
 
* Running DHCP server on one device. See [[dhcpd]] or [[dnsmasq]] for details.
 
* Running ''avahi-autoipd''. See [[Avahi#Obtaining IPv4LL IP address]] for details.
 
* Running ''avahi-autoipd''. See [[Avahi#Obtaining IPv4LL IP address]] for details.
  
Additionally, if you want to share an internet connection to the ad-hoc network, see [[Internet Share]].
+
If you want to share an internet connection to the ad-hoc network, see [[Internet sharing]].
  
 
== Tips and tricks ==
 
== Tips and tricks ==
Line 83: Line 82:
 
=== Using NetworkManager ===
 
=== Using NetworkManager ===
  
If you use [[NetworkManager]], you don't have to use the manual method described above, you can use ''nm-applet'' for the configuration instead. See [[NetworkManager#Ad-hoc]] for details.
+
If you use [[NetworkManager]], you can use ''nm-applet'' for ad-hoc network configuration instead of the manual method described above. See [[NetworkManager#Ad-hoc]] for details.
  
 
{{Note|NetworkManager does not support WPA encryption in ad-hoc mode.}}
 
{{Note|NetworkManager does not support WPA encryption in ad-hoc mode.}}
Line 94: Line 93:
 
addr=192.168.0.2
 
addr=192.168.0.2
 
mask=24
 
mask=24
ssid=MySSID
 
freq=2432
 
 
</nowiki>}}
 
</nowiki>}}
  
 
{{hc|/etc/systemd/system/network-wireless-adhoc@.service|<nowiki>
 
{{hc|/etc/systemd/system/network-wireless-adhoc@.service|<nowiki>
 
[Unit]
 
[Unit]
Description=Network connectivity for %i
+
Description=Ad-hoc wireless network connectivity (%i)
 
Wants=network.target
 
Wants=network.target
 
Before=network.target
 
Before=network.target
Line 110: Line 107:
 
RemainAfterExit=yes
 
RemainAfterExit=yes
 
EnvironmentFile=/etc/conf.d/network-wireless-adhoc@%i
 
EnvironmentFile=/etc/conf.d/network-wireless-adhoc@%i
ExecStart=/usr/bin/iw %i set type ibss
+
 
 +
# perhaps rfkill is not needed for you
 +
ExecStart=/usr/bin/rfkill unblock wifi
 
ExecStart=/usr/bin/ip link set %i up
 
ExecStart=/usr/bin/ip link set %i up
 +
ExecStart=/usr/bin/wpa_supplicant -B -i %i -D nl80211,wext -c /etc/wpa_supplicant-adhoc.conf
 
ExecStart=/usr/bin/ip addr add ${addr}/${mask} dev %i
 
ExecStart=/usr/bin/ip addr add ${addr}/${mask} dev %i
ExecStart=/usr/bin/iw dev %i ibss join ${ssid} ${freq}
+
 
ExecStart=/usr/bin/wpa_supplicant -B -i %i -D nl80211,wext -c /etc/wpa_supplicant/adhoc.conf
+
 
ExecStop=/usr/bin/ip addr flush dev %i
 
ExecStop=/usr/bin/ip addr flush dev %i
 
ExecStop=/usr/bin/ip link set %i down
 
ExecStop=/usr/bin/ip link set %i down

Latest revision as of 09:02, 19 November 2015

An IBSS (Independent Basic Service Set) network, often called an ad-hoc network, is a way to have a group of devices talk to each other wirelessly, without a central controller. It is an example of a peer-to-peer network, in which all devices talk directly to each other, with no inherent relaying.

For example, ad-hoc networking may be used to share an internet connection.

Requirements

  • A nl80211 compatible wireless device (e.g. ath9k) on all devices which will connect to the network

Wifi link layer

Since IBSS network is a peer-to-peer network, the steps necessary to set up the wifi link layer should be the same on all devices.

Tip: It is possible to create complex network topologies, see Linux Wireless documentation for advanced examples.

Manual method

Warning: This method creates unencrypted ad-hoc network. See #WPA supplicant for method using WPA encryption.

See Wireless network configuration#Manual setup for a better explanation of the following commands. Make sure that iw is installed.

Set the operation mode to ibss:

# iw interface set type ibss

Bring the interface up (an additional step like rfkill unblock wifi might be needed):

# ip link set interface up

Now you can create an ad-hoc network. Replace your_ssid with the name of the network and frequency with the frequency in MHz, depending on which channel you want to use. See the Wikipedia page List of WLAN channels for a table showing frequencies of individual channels.

# iw interface ibss join your_ssid frequency

WPA supplicant

Note: This method creates ad-hoc network using WPA encryption. WPA2 is currently not supported (August 2013).

Ensure that wpa_supplicant is installed, and create a configuration file for it (see WPA supplicant for details).

/etc/wpa_supplicant-adhoc.conf
ctrl_interface=DIR=/run/wpa_supplicant GROUP=wheel

# use 'ap_scan=2' on all devices connected to the network
ap_scan=2

network={
    ssid="MySSID"
    mode=1
    frequency=2432
    proto=WPA
    key_mgmt=WPA-NONE
    pairwise=NONE
    group=TKIP
    psk="secret passphrase"
}

Run wpa_supplicant on all devices connected to the network with the following command:

# wpa_supplicant -B -i interface -c /etc/wpa_supplicant-adhoc.conf -D nl80211,wext

Network configuration

The final step is to assign an IP address to all devices in the network. There are multiple ways to do this:

If you want to share an internet connection to the ad-hoc network, see Internet sharing.

Tips and tricks

Using NetworkManager

If you use NetworkManager, you can use nm-applet for ad-hoc network configuration instead of the manual method described above. See NetworkManager#Ad-hoc for details.

Note: NetworkManager does not support WPA encryption in ad-hoc mode.

Custom systemd service (with wpa_supplicant and static IP)

You can use the following templates to enable wireless ad-hoc networking:

/etc/conf.d/network-wireless-adhoc@<interface>
addr=192.168.0.2
mask=24
/etc/systemd/system/network-wireless-adhoc@.service
[Unit]
Description=Ad-hoc wireless network connectivity (%i)
Wants=network.target
Before=network.target
BindsTo=sys-subsystem-net-devices-%i.device
After=sys-subsystem-net-devices-%i.device

[Service]
Type=oneshot
RemainAfterExit=yes
EnvironmentFile=/etc/conf.d/network-wireless-adhoc@%i

# perhaps rfkill is not needed for you
ExecStart=/usr/bin/rfkill unblock wifi
ExecStart=/usr/bin/ip link set %i up
ExecStart=/usr/bin/wpa_supplicant -B -i %i -D nl80211,wext -c /etc/wpa_supplicant-adhoc.conf
ExecStart=/usr/bin/ip addr add ${addr}/${mask} dev %i

ExecStop=/usr/bin/ip addr flush dev %i
ExecStop=/usr/bin/ip link set %i down

[Install]
WantedBy=multi-user.target

See also