Difference between revisions of "Netcfg (简体中文)"

From ArchWiki
Jump to: navigation, search
(use https for links to archlinux.org)
(Redirect to Netctl.)
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[Category:简体中文]]
+
#REDIRECT [[netctl (简体中文)]]
[[en:Netcfg]]
+
[[es:Netcfg]]
+
[[fr:Netcfg]]
+
[[it:Netcfg]]
+
[[ro:Netcfg]]
+
[[ru:Netcfg]]
+
[[tr:netcfg]]
+
{{TranslationStatus (简体中文)|Netcfg|2012-10-14|229087}}
+
{{Translateme (简体中文)}}
+
{{Article summary start|摘要}}
+
{{Article summary text|指导如何安装和配置 netcfg – 网络配置和配置文件脚本。}}
+
{{Article summary heading|概览}}
+
{{Article summary text|{{Networking overview (简体中文)}}}}
+
{{Article summary heading|资源}}
+
{{Article summary wiki|Netcfg_Tips}} - Tips and Tricks for netcfg.
+
{{Article summary wiki|Netcfg Troubleshooting (简体中文)}} - Troubleshooting for netcfg.
+
{{Article summary link|netcfg 网络脚本仓库|https://projects.archlinux.org/netcfg.git/}}
+
{{Article summary end}}
+
Netcfg 通过配置文件来配置和管理网络连接. 支持一系列可插拨的连接类型,例如无线连接,以太网,ppp.也能够打开或结束多对一的连接,也就是多种连接写在同一个配置文件内,可选地粘合在一起''。它非常简单、健壮,可以管理多种网络配置方式。 netcfg 是[[systemd]]支持的一种网络配置方式。
+
{{Note|netcfg-2.8.9 drops deprecated rc.conf compatibility. Users of netcfg should configure all interfaces in {{ic|/etc/conf.d/netcfg}}  rather than {{ic|/etc/rc.conf}}.}}
+
==准备==
+
最简单的情况,用户至少要知道网络接口的名字(例如''eth0'' ,''wlan0'').如果配置的是固定IP地址,网关和DNS必须要填上.
+
 
+
如果连接到一个无线网络,必须知道一些基本的信息.对于无线网络这些信息包括使用的安全类型(WEP/WPA/WPA2),网络名(ESSID),和密码或密钥.另外,保证已经为无线设备安装了合适的驱动和固件,在[[Wireless Setup]]有相关描述.
+
 
+
==安装==
+
+
可以从[[Official Repositories|官方软件仓库]]安装软件包{{Pkg|netcfg}}。
+
 
+
版本2.5.x ,有可选的依赖包括: 自动的移动无线网络需要的{{Pkg|wpa_actiond}} –, 自动的以太网配置需要的 {{Pkg|ifplugd}} –
+
 
+
# pacman -S wpa_actiond ifplugd
+
 
+
如果需要netcfg的bash的自动补全支持:
+
 
+
# pacman -S bash-completion
+
 
+
==配置==
+
网络的配置文件在{{ic|/etc/network.d}}目录.
+
 
+
为尽量减少可能发生的错误,从{{ic|/etc/network.d/examples/}}复制示例配置文件到{{ic|/etc/network.d/mynetwork}}.文件的名字是网络配置文件的名字(文章里使用的例子是"mynetwork").文件的名字不是网络设置并且不需要与无线网络名称(SSID)相同.
+
 
+
根据连接类型与安全模式,使用下列{{ic|/etc/network.d/examples}}里的文件作为基础.
+
 
+
=== 无线示例 ===
+
{{Warning|小心在互联网上找到的示例,因为它常常会包含会导致问题的过时选项.}}
+
 
+
{| border="1"
+
! 连接类型/安全 !! 示例配置
+
|-
+
| 无线; WEP 16进制密钥 || {{ic|wireless-wep}}
+
|-
+
| 无线; WEP 字符密钥 || {{ic|wireless-wep-string-key}}
+
|-
+
| 无线; WPA 个人版 (passphrase) || {{ic|wireless-wpa}}
+
|-
+
| 无线; WPA 企业版 || {{ic|wireless-wpa-config}} (wpa_supplicant configuration is external) <br /> {{ic|wireless-wpa-configsection}} (wpa_supplicant configuration stored as string)
+
|-
+
| 有线; DHCP || {{ic|ethernet-dhcp}}
+
|-
+
| 有线; 固定 IP || {{ic|ethernet-static}}
+
|-
+
| 有线; iproute 配置|| {{ic|ethernet-iproute}}
+
|}
+
 
+
接下来,更改新的配置文件,{{ic|/etc/network.d/mynetwork}}:
+
 
+
* 设 {{Ic|INTERFACE}} 为正确的无线或以太网接口. 这个可以用 {{Ic|ip link}} 和 {{Ic|iwconfig}} 检查.
+
* 确保无线连接的 {{Ic|ESSID}} 和 {{Ic|KEY}} (passphrase) 设置正确. 在这些地方输入错误很常见.
+
** 注意 WEP ''字符'' 密钥 (不是 ''16进制'' 密钥) 必须在前面指定 {{Ic|s:}} (例 {{Ic|<nowiki>KEY="s:somepasskey"</nowiki>}}).
+
 
+
{{注意 | Netcfg 配置是可用的 Bash 脚本. 任何配置遇到特殊字符如 $ 或 \ 需要正确引用否则它会被 Bash 解释. 为避免解释, 用单引号或反斜杠. }}
+
 
+
{{Note | Network information (e.g. wireless passkey) will be stored in plain text format, so users may want to change the permissions on the newly created profile (e.g. {{Ic|chmod 0600 /etc/network.d/mynetwork}} to make it readable by root only).}}
+
 
+
{{Note | For WPA personal, it is also possible to use WPA passkey encoded into a hexadecimal string, instead of plain text passkey.
+
Follow the procedure on the [[Wpa_supplicant#Classic_method:_wpa_supplicant.conf|WPA supplicant page's 1st example exercise]] to generate a hexadecimal string from you WPA passkey.<br>
+
Save the new hexadecimal string into your wireless WPA profile in {{Ic|/etc/network.d/mynetwork}} as the value of KEY variable (make sure this will be the only KEY variable enabled), to look similar to this (replace the string with your one):
+
<pre>KEY='7b271c9a7c8a6ac07d12403a1f0792d7d92b5957ff8dfd56481ced43ec6a6515'</pre>
+
That should do it, without the need to reveal the passkey.<br>
+
}}
+
 
+
 
+
==手动操作==
+
连接到一个配置好的网络:
+
# netcfg mynetwork
+
 
+
断开一个配置好的网络:
+
# netcfg down <profile-name>
+
 
+
其他方式请参考:
+
$ netcfg help
+
 
+
如果在开机的时候自动连接到网络, 添加配置文件的文件名到 rc.conf中<code>NETWORKS=()</code>的那一行, 例如:
+
<code>NETWORKS=(home)</code>.
+
 
+
另外,要想开机连接网络就必须确定 <code>net-profiles</code> 同时存在于你的rc.conf中的 <code>DAEMONS=()</code>里
+
 
+
如果连接不上网络, 看是否属于以下所列的情况. 如果还有其他的问题, 可以看以下的说明或者上 arch 论坛, IRC 以及邮件列表.
+
 
+
==自动连接网络==
+
===Systemd Support (Recommended) ===
+
Since version 2.8.2 {{Pkg|netcfg}} provides systemd unit files.  Select from the following three features.
+
 
+
==== Net-Profiles ====
+
Edit {{ic|/etc/conf.d/netcfg}} eth0 refere to the file /etc/network.d/eth0 (copy from {{ic|/etc/network.d/examples/ethernet-static}})
+
# NETWORKS=(eth0)
+
 
+
Add service net-profiles (instead of networking) in {{ic|/etc/rc.conf}}
+
 
+
Other Solution:
+
 
+
Use the template service file {{ic|netcfg@xxx.service}} that allows connection to a profile on boot without having to specify it in {{ic|/etc/conf.d/netcfg}}. To specify the desired profile, enable the template service and use the network profile name as the instance name.
+
 
+
Example:
+
# systemctl enable netcfg@<profile-name>.service
+
 
+
==== Net-Auto-Wireless ====
+
This allows users to automatically connect to wireless networks with proper roaming support.  To use this feature, the {{Pkg|wpa_actiond}} package is required. Note that {{ic|wireless-wpa-config}} profiles do not work with {{ic|net-auto-wireless}}. Convert them to {{ic|wireless-wpa-configsection}} instead.
+
 
+
Specify the desired wireless interface with the {{ic|WIRELESS_INTERFACE}} variable in {{ic|/etc/conf.d/netcfg}} or define a list of wireless networks that should be automatically connected with the {{ic|AUTO_PROFILES}} variable in  {{ic|/etc/conf.d/netcfg}}.  Enable the {{ic|net-auto-wireless.service}} so systemd manages it.
+
 
+
{{Note|If  AUTO_PROFILES is not set, all wireless networks will be tried.}}
+
 
+
Example:
+
# systemctl enable net-auto-wireless.service
+
 
+
==== Net-Auto-Wired ====
+
This allows users to automatically connect to wired networks.  To use this feature, the {{Pkg|ifplugd}} is required.
+
 
+
Specify the desired wired interface with the {{ic|WIRED_INTERFACE}} variable in {{ic|/etc/conf.d/netcfg}} and enable the {{ic|net-auto-wired.service}} so systemd manages it.
+
 
+
Example:
+
# systemctl enable net-auto-wired.service
+
 
+
The daemon starts an {{ic|ifplugd}} process which runs {{ic|/etc/ifplugd/netcfg.action}} when the status of the wired interface changes (e.g. a cable is plugged in or unplugged). On plugging in a cable, attempts are made to start any profiles with {{ic|CONNECTION <nowiki>=</nowiki> "ethernet"}} or {{ic|"ethernet-iproute"}} and {{ic|INTERFACE <nowiki>=</nowiki> WIRED_INTERFACE}} until one of them succeeds.
+
 
+
{{Note|DHCP profiles are tried before static ones, which could lead to undesired results in some cases. However, one can tell netcfg to prefer a particular interface by adding {{ic|1=AUTO_WIRED=1}} to the desired profile.}}
+
 
+
{{Note|The {{ic|net-auto-wired}} daemon cannot start multiple ifplugd processes for multiple interfaces (unlike ifplugd's own {{ic|/etc/rc.d/ifplugd}} which can).}}
+
 
+
=== SysV Support (Soon to be Deprecated/Legacy) ===
+
====Net-Profiles====
+
'''{{ic|net-profiles}} allows users to connect profiles during boot.'''
+
 
+
To enable this feature, users must add {{ic|net-profiles}} to the {{ic|DAEMONS}} array in {{ic|/etc/[[rc.conf]]}} and specify profiles to try in the {{ic|NETWORKS}} array in {{ic|/etc/conf.d/netcfg}}:
+
 
+
{{hc|/etc/rc.conf|<nowiki>
+
DAEMONS=(... net-profiles ...)
+
</nowiki>}}
+
{{hc|/etc/conf.d/netcfg|<nowiki>
+
NETWORKS=(mynetwork yournetwork)
+
</nowiki>}}
+
A network profile can also be started in the background by prefixing it with a {{ic|@}} in the {{ic|NETWORKS}} array. Note that one should only do this if the backgrounded profiles configure separate interfaces, otherwise race conditions may occur.
+
 
+
{{hc|/etc/conf.d/netcfg|<nowiki>
+
NETWORKS=(@mynetwork @yournetwork)
+
</nowiki>}}
+
 
+
Alternatively, {{ic|net-profiles}} can be configured to restore the profiles that were active at last shutdown by setting the {{ic|NETWORKS}} array to {{ic|last}}, as described below.
+
 
+
{{hc|/etc/conf.d/netcfg|<nowiki>
+
NETWORKS=(last)
+
</nowiki>}}
+
 
+
Finally, {{ic|net-profiles}} can be configured to display a menu &ndash; allowing users to choose a desired profile &ndash; by setting the contents of the {{ic|NETWORKS}} array to {{ic|menu}}:
+
 
+
{{hc|/etc/conf.d/netcfg|<nowiki>
+
NETWORKS=(menu)
+
</nowiki>}}
+
 
+
Additionally, the {{Pkg|dialog}} package is required.
+
 
+
{{Tip|Access the menu at any time by running {{ic|netcfg-menu}} in a terminal.}}
+
 
+
====Net-Auto-Wireless====
+
To enable this feature, users must add {{ic|net-auto-wireless}} to the {{ic|DAEMONS}} array in {{ic|/etc/rc.conf}}:
+
{{hc|/etc/rc.conf|<nowiki>
+
DAEMONS=(... net-auto-wireless ...)
+
</nowiki>}}
+
 
+
And specify the desired wireless interface with the {{ic|WIRELESS_INTERFACE}} variable in {{ic|/etc/conf.d/netcfg}}:
+
 
+
{{hc|/etc/conf.d/netcfg|<nowiki>
+
WIRELESS_INTERFACE="wlan0"
+
</nowiki>}}
+
 
+
It is also possible to define a list of wireless networks that should be automatically connected with the {{ic|AUTO_PROFILES}} variable in  {{ic|/etc/conf.d/netcfg}}. If {{ic|AUTO_PROFILES}} is not set, all wireless networks will be tried.
+
 
+
Additionally, the {{Pkg|wpa_actiond}} package is required. Note that {{ic|wireless-wpa-config}} profiles do not work with {{ic|net-auto-wireless}}. Convert them to {{ic|wireless-wpa-configsection}} instead.
+
 
+
====Net-Auto-Wired====
+
To enable this feature, users must [[pacman|install]] {{Pkg|ifplugd}}, then add {{ic|net-auto-wired}} to the {{ic|DAEMONS}} array in {{ic|/etc/rc.conf}} and specify the desired wired interface with the {{ic|WIRED_INTERFACE}} variable in {{ic|/etc/conf.d/netcfg}}:
+
 
+
{{hc|/etc/rc.conf|<nowiki>
+
DAEMONS=(... net-auto-wired ...)
+
</nowiki>}}
+
{{hc|/etc/conf.d/netcfg|<nowiki>
+
WIRED_INTERFACE="eth0"
+
</nowiki>}}
+
 
+
The daemon starts an {{ic|ifplugd}} process which runs {{ic|/etc/ifplugd/netcfg.action}} when the status of the wired interface changes (e.g. a cable is plugged in or unplugged). On plugging in a cable, attempts are made to start any profiles with {{ic|CONNECTION <nowiki>=</nowiki> "ethernet"}} or {{ic|"ethernet-iproute"}} and {{ic|INTERFACE <nowiki>=</nowiki> WIRED_INTERFACE}} until one of them succeeds.
+
 
+
{{Note|DHCP profiles are tried before static ones, which could lead to undesired results in some cases. However, one can tell netcfg to prefer a particular interface by adding {{ic|1=AUTO_WIRED=1}} to the desired profile.}}
+
 
+
{{Note|The {{ic|net-auto-wired}} daemon cannot start multiple ifplugd processes for multiple interfaces (unlike ifplugd's own {{ic|/etc/rc.d/ifplugd}} which can).}}
+
 
+
==FAQ==
+
 
+
===我在使用netcfg的时候还需要这些文件么?===
+
 
+
{{FAQ
+
|question=为什么 netcfg 不能干''某某某某''事情?
+
|answer=netcfg 不必这样,他只是用来联网的。但是 netcfg 模块化和可以扩展的。看看{{ic|/usr/lib/networks/}},你可以用自己的脚本完成很多扩展功能。}}
+
 
+
{{FAQ
+
|question=为什么netcfg不这样呢?
+
|answer=netcfg不强制使用什么规则。它的任务只是网络连接。它也没有一些启发式的功能,如“当连接到有线网络时自动断开无线连接”。如果你想要类似的功能,借助netcfg可以很容易写出一个工具。}}
+
 
+
{{FAQ
+
|question=我在使用netcfg的时候还需要什么文件??
+
|answer=还需要正确配置{{ic|/etc/hosts}} 和 {{ic|/etc/hostname}}。}}
+

Latest revision as of 13:18, 29 July 2013