Difference between revisions of "Ad-hoc networking (简体中文)"

From ArchWiki
Jump to: navigation, search
(Sync to latest English page.)
(手动设置: Update translation.)
 
(17 intermediate revisions by 4 users not shown)
Line 1: Line 1:
[[Category:Networking (简体中文)]]
+
[[Category:Wireless networking (简体中文)]]
[[Category:Wireless Networking (简体中文)]]
 
 
[[en:Ad-hoc networking]]
 
[[en:Ad-hoc networking]]
{{Translateme (简体中文)}}
+
[[ja:アドホックネットワーク]]
{{Article summary start}}
+
{{Related articles start (简体中文)}}
{{Article summary text|基本的 ad-hoc 网络设置。}}
+
{{Related2|Network configuration (简体中文)|网络配置}}
{{Article summary heading|相关}}
+
{{Related2|Wireless Setup (简体中文)|无线设置}}
{{Article summary wiki|Network Configuration}}
+
{{Related|软AP}}
{{Article summary wiki|Wireless Setup}}
+
{{Related|Internet sharing}}
{{Article summary wiki|Software Access Point}}
+
{{Related articles end}}
{{Article summary wiki|Internet Share}}
+
{{TranslationStatus (简体中文)|Ad-hoc_networking|2017-08-22|463497}}
{{Article summary end}}
+
Independent Basic Service Set(独立基本服务集),缩写是 IBSS,也被称为自组网络,是一种不使用中心控制节点,就能让一组设备相互通讯的方法。是点对点网络的一种,网络中的设备直接通讯,不需要中转。自组网络可以用来进行 [[Internet sharing|网络共享]]。
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, ad-hoc networking may be used to [[Internet Share|share an internet connection]].
+
== 要求 ==
  
== Requirements ==
+
所有要连接到网络的设备都具有兼容 [https://wireless.wiki.kernel.org/en/users/drivers|nl80211] 的无线网卡。
  
* A nl80211 compatible wireless device (e.g. ath9k) on all devices which will connect to the network
+
== Wifi 链路层 ==
  
== Wifi link layer ==
+
因为 IBSS 网络是点对点网络,所有设备都应该使用相同的 wifi 连接设置。
  
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|可以设置更复杂的网络拓扑,[http://wireless.kernel.org/en/users/Documentation/iw/vif Linux 无线文档] 包含更高级的示例。}}
  
{{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.}}
+
=== 手动设置 ===
  
=== Manual method ===
+
{{警告|此方法创建的是 '''非加密''' 自组网络,要创建加密网络,请参考 [[#WPA supplicant]].}}
  
{{Warning|This method creates '''unencrypted''' ad-hoc network. See [[#WPA supplicant]] for method using WPA encryption.}}
+
详细信息请参考 [[Wireless network configuration#Manual setup]]。请先[[pacman|安装]] 软件包 {{Pkg|iw}}
  
See [[Wireless Setup#Manual setup]] for a better explanation of the following commands. Make sure that {{Pkg|iw}} is [[pacman|installed]].
+
设置操作模式为 ibss:
 
 
Set the operation mode to ibss:
 
  
 
  # iw ''interface'' set type ibss
 
  # iw ''interface'' set type ibss
  
Bring the interface up (an additional step like {{ic|rfkill unblock wifi}} might be needed):
+
启动接口(可能需要额外的 {{ic|rfkill unblock wifi}}):
  
 
  # ip link set ''interface'' up
 
  # 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 [[Wikipedia:List_of_WLAN_channels#Interference_Concerns|List of WLAN channels]] for a table showing frequencies of individual channels.
+
现在可以创建自组网络了,将 ''your_ssid'' 替换为实际的网络,''frequency'' 替换为以 MHz 为单位的频率。频道和频率的对应关系,请参考, [[Wikipedia:List_of_WLAN_channels#Interference_Concerns|这里]]
  
 
  # iw ''interface'' ibss join ''your_ssid'' ''frequency''
 
  # iw ''interface'' ibss join ''your_ssid'' ''frequency''
Line 45: Line 41:
 
=== WPA supplicant ===
 
=== WPA supplicant ===
  
{{Note|This method creates ad-hoc network using WPA encryption. WPA2 is currently not supported (August 2013).}}
+
确保已经 [[pacman|安装]] 了 {{Pkg|wpa_supplicant}},并进行了配置(参考 [[WPA supplicant]]).
 
 
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 53: Line 47:
  
 
# use 'ap_scan=2' on all devices connected to the network
 
# use 'ap_scan=2' on all devices connected to the network
 +
# this is unnecessary if you only want the network to be created when no other networks are available
 
ap_scan=2
 
ap_scan=2
  
Line 59: Line 54:
 
     mode=1
 
     mode=1
 
     frequency=2432
 
     frequency=2432
     proto=WPA
+
     proto=RSN
     key_mgmt=WPA-NONE
+
     key_mgmt=WPA-PSK
     pairwise=NONE
+
     pairwise=CCMP
     group=TKIP
+
     group=CCMP
 
     psk="secret passphrase"
 
     psk="secret passphrase"
 
}
 
}
 
</nowiki>}}
 
</nowiki>}}
  
Run ''wpa_supplicant'' on all devices connected to the network with the following command:
+
所有连接到网络的设备运行下面 ''wpa_supplicant'' 命令:
  
 
  # wpa_supplicant -B -i ''interface'' -c /etc/wpa_supplicant-adhoc.conf -D nl80211,wext
 
  # 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:
 
  
* Assign static IP addresses. See [[Network Configuration#Static IP address]] for details.
+
最后一步是给网络中的所有设备分配 IP 地址,有多种方法:
* Running DHCP server on one device. See [[dhcpd]] or [[dnsmasq]] for details.
 
* Running ''avahi-autoipd''. See [[Avahi#Obtaining IPv4LL IP address]] for details.
 
  
If you want to share an internet connection to the ad-hoc network, see [[Internet Share]].
+
* 分配静态 IP 地址,参考:[[Network configuration#Static IP address]].
 +
* 在一个设备上运行 DHCP,参考 [[dhcpd]] 或 [[dnsmasq]].
 +
* 运行 ''avahi-autoipd''. 参考 [[Avahi#Obtaining IPv4LL IP address]].
  
== Tips and tricks ==
+
要向自组网络共享外网连接,请参考 [[Internet sharing]].
  
=== 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.
+
=== 使用 NetworkManager ===
  
{{Note|NetworkManager does not support WPA encryption in ad-hoc mode.}}
+
如果使用 [[NetworkManager]],可以使用 ''nm-applet'' 进行自组网络配置,不用使用手动方法。详情参考 [[NetworkManager#Ad-hoc]]。
  
=== Custom systemd service (with wpa_supplicant and static IP) ===
+
{{Note|NetworkManager 在自组网络模式中不支持 WPA 加密。}}
  
You can use the following templates to enable wireless ad-hoc networking:
+
=== 自定义 systemd 服务(使用 wpa_supplicant 和静态 IP) ===
  
 +
可以使用下面模板启用无线自组网络:
 
{{hc|/etc/conf.d/network-wireless-adhoc@<interface>|<nowiki>
 
{{hc|/etc/conf.d/network-wireless-adhoc@<interface>|<nowiki>
 
addr=192.168.0.2
 
addr=192.168.0.2

Latest revision as of 10:24, 22 August 2017

翻译状态: 本文是英文页面 Ad-hoc_networking翻译,最后翻译时间:2017-08-22,点击这里可以查看翻译后英文页面的改动。

Independent Basic Service Set(独立基本服务集),缩写是 IBSS,也被称为自组网络,是一种不使用中心控制节点,就能让一组设备相互通讯的方法。是点对点网络的一种,网络中的设备直接通讯,不需要中转。自组网络可以用来进行 网络共享

要求

所有要连接到网络的设备都具有兼容 [1] 的无线网卡。

Wifi 链路层

因为 IBSS 网络是点对点网络,所有设备都应该使用相同的 wifi 连接设置。

Tip: 可以设置更复杂的网络拓扑,Linux 无线文档 包含更高级的示例。

手动设置

警告: 此方法创建的是 非加密 自组网络,要创建加密网络,请参考 #WPA supplicant.

详细信息请参考 Wireless network configuration#Manual setup。请先安装 软件包 iw

设置操作模式为 ibss:

# iw interface set type ibss

启动接口(可能需要额外的 rfkill unblock wifi):

# ip link set interface up

现在可以创建自组网络了,将 your_ssid 替换为实际的网络,frequency 替换为以 MHz 为单位的频率。频道和频率的对应关系,请参考, 这里

# iw interface ibss join your_ssid frequency

WPA supplicant

确保已经 安装wpa_supplicant,并进行了配置(参考 WPA supplicant).

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

# use 'ap_scan=2' on all devices connected to the network
# this is unnecessary if you only want the network to be created when no other networks are available
ap_scan=2

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

所有连接到网络的设备运行下面 wpa_supplicant 命令:

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

网络配置

最后一步是给网络中的所有设备分配 IP 地址,有多种方法:

要向自组网络共享外网连接,请参考 Internet sharing.

技巧

使用 NetworkManager

如果使用 NetworkManager,可以使用 nm-applet 进行自组网络配置,不用使用手动方法。详情参考 NetworkManager#Ad-hoc

Note: NetworkManager 在自组网络模式中不支持 WPA 加密。

自定义 systemd 服务(使用 wpa_supplicant 和静态 IP)

可以使用下面模板启用无线自组网络:

/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