Netcfg (简体中文)

From ArchWiki
Revision as of 10:13, 11 January 2013 by Fengchao (Talk | contribs) (Update translation)

Jump to: navigation, search
翻译状态: 本文是英文页面 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.也能够打开或结束多对一的连接,也就是多种连接写在同一个配置文件内,可选地粘合在一起。它非常简单、健壮,可以管理多种网络配置方式。

准备

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

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

安装

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

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

# 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