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

From ArchWiki
Jump to: navigation, search
m (SysV Support (Soon to be Depreciated/Legacy): fix spelling in heading)
(Move Troubleshooting into sub page.)
Line 14: Line 14:
 
{{Article summary heading|资源}}
 
{{Article summary heading|资源}}
 
{{Article summary wiki|Netcfg_Tips}} - Tips and Tricks for netcfg.
 
{{Article summary wiki|Netcfg_Tips}} - Tips and Tricks for netcfg.
{{Article summary wiki|Netcfg_Troubleshooting}} - Troubleshooting for netcfg.
+
{{Article summary wiki|Netcfg Troubleshooting (简体中文)}} - Troubleshooting for netcfg.
 
{{Article summary link|netcfg 网络脚本仓库|http://projects.archlinux.org/netcfg.git/}}
 
{{Article summary link|netcfg 网络脚本仓库|http://projects.archlinux.org/netcfg.git/}}
 
{{Article summary end}}
 
{{Article summary end}}
Line 205: Line 205:
  
 
{{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).}}
 
{{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).}}
 
==问题以及解决==
 
===没有用!!为什么?===
 
请看最新的问题以及解决章节。为了找到哪里出现问题,我们需要更多信息,而不是仅仅说这样那样不行!为了节约人力物力,首先你需要仔细阅读搜索wiki或者搜索论坛。
 
 
===Driver Quirks (netcfg 2.1以及更高版本)===
 
Some drivers behave odd and need workarounds to connect. These have to be enabled manually. They're best determined by reading the forums, seeing what others have used, and if that fails trial and error. They can be combined.
 
 
参考翻译:一些驱动很奇怪,需要一些额外操作才能连接。这些必须手动启用。问题的最好解决是搜索论坛,看看别人是如何使用的,以及尝试了什么方法以及错误。可能问题就可以和你看到的内容联系起来解决。
 
 
* prescan - Run "iwlist $INTERFACE scan" before attempting to connect (Some broadcom)
 
* preessid - Run "iwconfig $INTERFACE essid $ESSID" before attempting to connect. (Some ipw3945 and Intel PRO/Wireless 4965AGN)
 
* wpaessid - Same as previous, run before starting wpa_supplicant
 
* predown - Take interface down before association and then restore it after. (madwifi)
 
* postsleep - Sleep 1 second before checking if the association was successful
 
* postscan - Run "iwlist scan" after associating
 
 
例如
 
QUIRKS=(prescan preessid)
 
 
如果你的DNS或者DHCP有问题,尝试添加下面一行到你的netcfg配置文件里面去:
 
DHCLIENT=no
 
这样netcfg就会使用dhcpcd而不会使用dhclient
 
 
如果你得到"Wireless Network Not Found"或者"Association Failed"的错误,并且你已经尝试了上面的做法,试试看加上:
 
SCAN=no
 
 
===在连接网络前给 iwconfig 传递启动参数(只适用于netcfg 2.1以及更高版本)===
 
简单的:
 
 
IWCONFIG="<arguments>"
 
 
<arguments>处可以是任何有效的 iwconfig参数。程序会运行"iwconfig $INTERFACE $IWCONFIG"
 
 
例如,设置bssid/ap mac:
 
IWCONFIG="ap 12:34:56:78:90:12"
 
 
This supercedes the IWOPTS option which was incompletely implemented.(参考翻译:这个参数会取代不完全执行的IWOPTS选项。- -b)
 
 
===Network unavailable(网络不可用)===
 
这一般是因为:
 
* 超出范围,连接超时
 
* 驱动问题(请看上面的Driver Quirks)
 
* 尝试连接了一个隐藏的网络
 
 
如果你知道你要连接的网络是隐藏的,请设置
 
SCAN=no
 
 
===Wireless Association failed(无线网络连接失败)===
 
这一般是因为:
 
* 超出接受范围,连接超时
 
* 错误的配置
 
* 错误的密钥
 
* 驱动问题(请看上面的Driver Quirks)
 
 
如果你知道是范围问题,添加<code>TIMEOUT=</code>可能有用
 
 
===Unable to get IP address with DHCP(无法通过DHCP获得IP地址)===
 
这一般是因为:
 
* 超出范围,连接超时
 
 
尝试添加<code>DHCP_TIMEOUT</code>
 
 
===Not a valid connection, check spelling or look at examples(不是一个可用连接,检查配置文件)===
 
你必须设定CONNECTION= 为 "ethernet", "ppp",或者 "wireless"其中一项
 
 
===Using a string WEP key(使用WEP字符串密钥)===
 
下面设置只是STRING WEP密钥,不是HEX WEP密钥,也不是WPA密钥。
 
KEY="s:''密钥''"
 
 
===老硬件rt2500, rt2400使用iwpriv替代===
 
 
我没有打算支持这些的计划。但 rt2x00 目前被支持,很快就会不支持了。
 
 
如果你必须使用这些硬件,创建一个包含 iwpriv 命令的脚本,保存,赋予可执行权限,然后把这个文件路径放入 PRE_UP=""
 
 
 
===如果仍然不管用我该怎么办===
 
查看下面所有的FAQ。如果没有解决方法,那么就上论坛或者邮件里表提问。
 
 
提问的时候,记住必须提供尽可能多的信息,至少要包含下面命令的输出信息:
 
* netcfg 所有输出,哪怕 netcfg 说运行成功
 
* ifconfig -a
 
* 连接前 iwconfig 的输出
 
* /etc/network.d/ 下的配置文件,记住无线网络的密钥用别的替代,如 <censored>
 
* lsmod
 
比发表一个很长很长的帖子或者邮件更好的方法是把脚本粘贴到一些专门粘贴的网站。 [http://pastie.caboo.se/ Pastie]和[http://www.rafb.net/paste/ rafb|Nopaste]是两个很热门的。这里也有个 rafb 的命令行前端:
 
 
# pacman -S nopaste
 
 
==GUI图形界面==
 
 
目前已经有个基于 Qt 的 netcfg2 图形前端,叫做 ArchAssistant。这个软件是在系统托盘里管理、连接或者断开多个网络配置。它也有无线网络的自动搜寻功能。它对于笔记本电脑用户特别有用。
 
 
链接:
 
archassistant on [https://aur.archlinux.org/packages.php?ID=15655 AUR] | [http://www.kde-apps.org/content/show.php/ArchAssistant?content=76760 kde-apps.org] | archassistant package on archlinux.fr [http://repo.archlinux.fr/i686/ i686] and [http://repo.archlinux.fr/x86_64/ x86_64]
 
  
 
==FAQ==
 
==FAQ==

Revision as of 08:13, 5 November 2012

翻译状态: 本文是英文页面 Netcfg翻译,最后翻译时间:2012-10-14,点击这里可以查看翻译后英文页面的改动。

Tango-preferences-desktop-locale.png本页面需要更新翻译,内容可能已经与英文脱节。要贡献翻译,请访问简体中文翻译组Tango-preferences-desktop-locale.png

附注: please use the first argument of the template to provide more detailed indications.
摘要 help replacing me
指导如何安装和配置 netcfg – 网络配置和配置文件脚本。
概览
Template:Networking overview (简体中文)
资源
Netcfg_Tips - Tips and Tricks for netcfg.
Netcfg Troubleshooting (简体中文) - Troubleshooting for netcfg.
netcfg 网络脚本仓库

Netcfg 通过配置文件来配置和管理网络连接. 支持一系列可插拨的连接类型,例如无线连接,以太网,ppp.也能够打开或结束多对一的连接,也就是多种连接写在同一个配置文件内,可选地粘合在一起。它非常简单、健壮,可以管理多种网络配置方式。 netcfg 是systemd支持的一种网络配置方式。

Note: netcfg-2.8.9 drops deprecated rc.conf compatibility. Users of netcfg should configure all interfaces in /etc/conf.d/netcfg rather than /etc/rc.conf.

准备

最简单的情况,用户至少要知道网络接口的名字(例如eth0 ,wlan0).如果配置的是固定IP地址,网关和DNS必须要填上.

如果连接到一个无线网络,必须知道一些基本的信息.对于无线网络这些信息包括使用的安全类型(WEP/WPA/WPA2),网络名(ESSID),和密码或密钥.另外,保证已经为无线设备安装了合适的驱动和固件,在Wireless Setup有相关描述.

安装

可以从官方软件仓库安装软件包netcfg

版本2.5.x ,有可选的依赖包括: 自动的移动无线网络需要的wpa_actiond –, 自动的以太网配置需要的 wpa_actiond

# pacman -S wpa_actiond ifplugd

如果需要netcfg的bash的自动补全支持:

# pacman -S bash-completion

配置

网络的配置文件在/etc/network.d目录.

为尽量减少可能发生的错误,从/etc/network.d/examples/复制示例配置文件到/etc/network.d/mynetwork.文件的名字是网络配置文件的名字(文章里使用的例子是"mynetwork").文件的名字不是网络设置并且不需要与无线网络名称(SSID)相同.

根据连接类型与安全模式,使用下列/etc/network.d/examples里的文件作为基础.

无线示例

Warning: 小心在互联网上找到的示例,因为它常常会包含会导致问题的过时选项.
连接类型/安全 示例配置
无线; WEP 16进制密钥 wireless-wep
无线; WEP 字符密钥 wireless-wep-string-key
无线; WPA 个人版 (passphrase) wireless-wpa
无线; WPA 企业版 wireless-wpa-config (wpa_supplicant configuration is external)
wireless-wpa-configsection (wpa_supplicant configuration stored as string)
有线; DHCP ethernet-dhcp
有线; 固定 IP ethernet-static
有线; iproute 配置 ethernet-iproute

接下来,更改新的配置文件,/etc/network.d/mynetwork:

  • INTERFACE 为正确的无线或以太网接口. 这个可以用 ip linkiwconfig 检查.
  • 确保无线连接的 ESSIDKEY (passphrase) 设置正确. 在这些地方输入错误很常见.
    • 注意 WEP 字符 密钥 (不是 16进制 密钥) 必须在前面指定 s: (例 KEY="s:somepasskey").
注意: 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. 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 page's 1st example exercise to generate a hexadecimal string from you WPA passkey.
Save the new hexadecimal string into your wireless WPA profile in /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):

KEY='7b271c9a7c8a6ac07d12403a1f0792d7d92b5957ff8dfd56481ced43ec6a6515'

That should do it, without the need to reveal the passkey.


手动操作

连接到一个配置好的网络:

# netcfg mynetwork

断开一个配置好的网络:

# netcfg down <profile-name>

其他方式请参考:

$ netcfg help

如果在开机的时候自动连接到网络, 添加配置文件的文件名到 rc.conf中NETWORKS=()的那一行, 例如: NETWORKS=(home).

另外,要想开机连接网络就必须确定 net-profiles 同时存在于你的rc.conf中的 DAEMONS=()

如果连接不上网络, 看是否属于以下所列的情况. 如果还有其他的问题, 可以看以下的说明或者上 arch 论坛, IRC 以及邮件列表.

自动连接网络

Systemd Support (Recommended)

Since version 2.8.2 netcfg provides systemd unit files. Select from the following three features.

Net-Profiles

Edit /etc/conf.d/netcfg eth0 refere to the file /etc/network.d/eth0 (copy from /etc/network.d/examples/ethernet-static)

# NETWORKS=(eth0)

Add service net-profiles (instead of networking) in /etc/rc.conf

Other Solution:

Use the template service file netcfg@xxx.service that allows connection to a profile on boot without having to specify it in /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 wpa_actiond package is required. Note that wireless-wpa-config profiles do not work with net-auto-wireless. Convert them to wireless-wpa-configsection instead.

Specify the desired wireless interface with the WIRELESS_INTERFACE variable in /etc/conf.d/netcfg or define a list of wireless networks that should be automatically connected with the AUTO_PROFILES variable in /etc/conf.d/netcfg. Enable the 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 ifplugd is required.

Specify the desired wired interface with the WIRED_INTERFACE variable in /etc/conf.d/netcfg and enable the net-auto-wired.service so systemd manages it.

Example:

# systemctl enable net-auto-wired.service

The daemon starts an ifplugd process which runs /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 CONNECTION = "ethernet" or "ethernet-iproute" and INTERFACE = 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 AUTO_WIRED=1 to the desired profile.
Note: The net-auto-wired daemon cannot start multiple ifplugd processes for multiple interfaces (unlike ifplugd's own /etc/rc.d/ifplugd which can).

SysV Support (Soon to be Deprecated/Legacy)

Net-Profiles

net-profiles allows users to connect profiles during boot.

To enable this feature, users must add net-profiles to the DAEMONS array in /etc/rc.conf and specify profiles to try in the NETWORKS array in /etc/conf.d/netcfg:

/etc/rc.conf
DAEMONS=(... net-profiles ...)
/etc/conf.d/netcfg
NETWORKS=(mynetwork yournetwork)

A network profile can also be started in the background by prefixing it with a @ in the NETWORKS array. Note that one should only do this if the backgrounded profiles configure separate interfaces, otherwise race conditions may occur.

/etc/conf.d/netcfg
NETWORKS=(@mynetwork @yournetwork)

Alternatively, net-profiles can be configured to restore the profiles that were active at last shutdown by setting the NETWORKS array to last, as described below.

/etc/conf.d/netcfg
NETWORKS=(last)

Finally, net-profiles can be configured to display a menu – allowing users to choose a desired profile – by setting the contents of the NETWORKS array to menu:

/etc/conf.d/netcfg
NETWORKS=(menu)

Additionally, the dialog package is required.

Tip: Access the menu at any time by running netcfg-menu in a terminal.

Net-Auto-Wireless

To enable this feature, users must add net-auto-wireless to the DAEMONS array in /etc/rc.conf:

/etc/rc.conf
DAEMONS=(... net-auto-wireless ...)

And specify the desired wireless interface with the WIRELESS_INTERFACE variable in /etc/conf.d/netcfg:

/etc/conf.d/netcfg
WIRELESS_INTERFACE="wlan0"

It is also possible to define a list of wireless networks that should be automatically connected with the AUTO_PROFILES variable in /etc/conf.d/netcfg. If AUTO_PROFILES is not set, all wireless networks will be tried.

Additionally, the wpa_actiond package is required. Note that wireless-wpa-config profiles do not work with net-auto-wireless. Convert them to wireless-wpa-configsection instead.

Net-Auto-Wired

To enable this feature, users must install ifplugd, then add net-auto-wired to the DAEMONS array in /etc/rc.conf and specify the desired wired interface with the WIRED_INTERFACE variable in /etc/conf.d/netcfg:

/etc/rc.conf
DAEMONS=(... net-auto-wired ...)
/etc/conf.d/netcfg
WIRED_INTERFACE="eth0"

The daemon starts an ifplugd process which runs /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 CONNECTION = "ethernet" or "ethernet-iproute" and INTERFACE = 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 AUTO_WIRED=1 to the desired profile.
Note: The net-auto-wired daemon cannot start multiple ifplugd processes for multiple interfaces (unlike ifplugd's own /etc/rc.d/ifplugd which can).

FAQ

我在使用netcfg的时候还需要这些文件么?

Template:FAQ

Template:FAQ

Template:FAQ