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

From ArchWiki
Jump to: navigation, search
(配置)
(从 netcfg 迁移的方法: Sync with English page.)
Line 45: Line 45:
  
 
如果命令出错,可以使用 {{ic|journalctl -xn}} 和 {{ic|netctl status <profile>}} 检查出错原因。修正重新设置。
 
如果命令出错,可以使用 {{ic|journalctl -xn}} 和 {{ic|netctl status <profile>}} 检查出错原因。修正重新设置。
 +
 +
=== Automatic operation ===
 +
 +
If you use only one profile (per interface) or want to switch profiles manually, the [[#Basic method|basic method]] will do. Most common examples are servers, workstations, routers etc.
 +
 +
If you need to switch multiple profiles frequently, use [[#Automatic switching of profiles|Automatic switching of profiles]]. Most common examples are laptops.
 +
 +
==== Basic method ====
 +
 +
With this method, you can statically start only one profile per interface. First manually check that the profile can be started  successfully, then it can be {{ic|enabled}} using
 +
 +
# netctl enable ''profile''
 +
 +
This will create and enable a [[systemd]] service that will start when the computer boots.
 +
 +
{{Note|The connection is only established if the profile can be started succesfully at boot time (or when the service starts). That specifically means, in case of wired connection the cable must be plugged-in, in case of wireless connection the network must be in range.}}
 +
 +
{{Tip|To enable static IP profile on wired interface no matter if the cable is connected or not, use {{ic|1=SkipNoCarrier=yes}} in your profile.}}
 +
 +
==== Automatic switching of profiles ====
 +
 +
{{ic|netctl}} provides two special services for automatic switching of profiles: {{ic|netctl-auto@''interface''.service}} for wireless interfaces, and {{ic|netctl-ifplugd@''interface''.service}} for wired interfaces. Using {{ic|netctl-auto@''interface''.service}}, netctl profiles change as you move from range of one network into range of other network. Using {{ic|netctl-ifplugd@''interface''.service}}, netctl profiles change as you plug the cable in and out.
 +
 +
{{Note|{{ic|netcfg}} used {{ic|net-auto-wireless.service}} and {{ic|net-auto-wired.service}} for this purpose.}}
 +
 +
First [[pacman|install]] required packages:
 +
* Package {{Pkg|wpa_actiond}} is required to use {{ic|netctl-auto@''interface''.service}}.
 +
* Package {{Pkg|ifplugd}} is required to use {{ic|netctl-ifplugd@''interface''.service}}.
 +
 +
Now configure all profiles that {{ic|netctl-auto@''interface''.service}} or {{ic|netctl-ifplugd@''interface''.service}} can start. If you want some profile '''not''' to be started automatically by these services, you have to explicitly add {{ic|1=ExcludeAuto=yes}} to that profile. You can use {{ic|1=Priority=}} to set priority of some profile when multiple profiles are available. See {{ic|netctl.profile(5)}} for details.
 +
 +
{{Warning|Automatic selection of a WPA-enabled profile by netctl-auto is not possible with option {{ic|1=Security=wpa-config}}, please use {{ic|1=Security=wpa-configsection}} instead.}}
 +
 +
Once your profiles are set and verified to be working, simply enable these services with
 +
# systemctl enable netctl-auto@''interface''.service
 +
# systemctl enable netctl-ifplugd@''interface''.service 
 +
 +
{{Warning|If any of the profiles contain errors, such as an empty {{ic|1=Key=}} variable, the unit will fail to load at boot.}}
 +
 +
{{Warning|This method conflicts with the [[#Basic method|basic method]]. If you have previously enabled a profile through {{ic|netctl}}, run {{bc|# netctl disable ''profile''}} to prevent the profile from starting twice at boot.}}
  
 
===从 netcfg 迁移的方法===
 
===从 netcfg 迁移的方法===
Line 51: Line 91:
  
 
从 netcfg 迁移,请执行:
 
从 netcfg 迁移,请执行:
 +
* 禁用 netcfg 服务: {{ic|# systemctl disable netcfg.service}}.
 +
* 删除 netcfg,然后安装 {{Pkg|netctl}}
 
*将老的网络配置移动到新目录
 
*将老的网络配置移动到新目录
*根据 netctl.profile(5) 修改变量名称(主要是大小写变化,例如 CONNECTION= 变成 Connection=).
+
*根据 netctl.profile(5) 修改变量名称(主要是大小写变化,例如 CONNECTION 变成 Connection).
 +
* For static IP configuration make sure the {{ic|Address}} variables have a netmask after the IP (e.g. {{ic|1=Address=('192.168.1.23'''/24'''' '192.168.1.87'''/24'''')}} in the example profile).
 +
* If you setup a wireless profile according in the {{ic|wireless-wpa-configsection}} example, note that this overrides {{ic|wpa_supplicant}} options defined above the brackets. For a connection to a hidden wireless network, add {{ic|1=scan_ssid=1}} to the options in the {{ic|wireless-wpa-configsection}}; {{ic|1=Hidden=yes}} does not work there.  
 
*接口变量和其他变量不再需要引号(这仅仅是风格变化).
 
*接口变量和其他变量不再需要引号(这仅仅是风格变化).
*为每一个配置执行{{ic|netctl enable <profile>}} 'last' 工作方式有变化,参阅 netctl.special(7).
+
*为每一个配置执行{{ic|netctl enable ''profile''}}, '''last'''工作方式有变化,参阅 netctl.special(7).
 
*使用 {{ic|netctl list}} / {{ic|netctl start <profile>}} 替换 netcfg-menu. wifi-menu 依然保留。
 
*使用 {{ic|netctl list}} / {{ic|netctl start <profile>}} 替换 netcfg-menu. wifi-menu 依然保留。
 +
* Unlike {{ic|netcfg}}, by default {{ic|netctl}} fails to bring up a [[wikipedia:Network interface controller|NIC]] when it is not connected to another powered up NIC. To solve this problem, add {{ic|1=SkipNoCarrier=yes}} at the end of your {{ic|/etc/netctl/''profile''}}.
  
 
===密码加密(256-bit PSK)===
 
===密码加密(256-bit PSK)===

Revision as of 13:23, 27 July 2013

Template:Article summary start Template:Article summary text Template:Article summary heading Template:Article summary text Template:Article summary heading Template:Article summary wiki Template:Article summary end

翻译状态: 本文是英文页面 Netctl翻译,最后翻译时间:2013-04-11,点击这里可以查看翻译后英文页面的改动。

Netctl 是基于命令行的网络管理器,支持场景配置。它是 Arch 的项目,取代了原来的 netcfg

安装

netctl 软件包已经进入官方软件仓库.

netctlnetcfgAUR相互冲突,安装 netctl 会替换掉netcfgAUR。如果配置不正确,可能导致连接中断。

Note: 请使用systemctl --type=service确保其它可以配置网络的服务都没有运行,同时使用多个网络配置工具会导致冲突。

建议阅读

建议用户使用前阅读如下文档:

配置

netctl 可以用来检查和控制 systemd 网络配置管理服务的状态。软件提供了一些配置文件的示例以供参考。这些示例位于/etc/netctl/examples/,包括:

  • ethernet-dhcp
  • ethernet-static
  • wireless-wpa
  • wireless-wpa-static

如果使用无线网络,命令wifi-menu -o可以在/etc/netctl自动生成配置文件。

要使用示例配置,将他们从/etc/netctl/examples/复制到/etc/netctl/然后进行修改:

# cp /etc/netctl/examples/wireless-wpa /etc/netctl/profile

创建完配置后,通过如下方法建立连接:

# netctl start profile

如果命令出错,可以使用 journalctl -xnnetctl status <profile> 检查出错原因。修正重新设置。

Automatic operation

If you use only one profile (per interface) or want to switch profiles manually, the basic method will do. Most common examples are servers, workstations, routers etc.

If you need to switch multiple profiles frequently, use Automatic switching of profiles. Most common examples are laptops.

Basic method

With this method, you can statically start only one profile per interface. First manually check that the profile can be started successfully, then it can be enabled using

# netctl enable profile

This will create and enable a systemd service that will start when the computer boots.

Note: The connection is only established if the profile can be started succesfully at boot time (or when the service starts). That specifically means, in case of wired connection the cable must be plugged-in, in case of wireless connection the network must be in range.
Tip: To enable static IP profile on wired interface no matter if the cable is connected or not, use SkipNoCarrier=yes in your profile.

Automatic switching of profiles

netctl provides two special services for automatic switching of profiles: netctl-auto@interface.service for wireless interfaces, and netctl-ifplugd@interface.service for wired interfaces. Using netctl-auto@interface.service, netctl profiles change as you move from range of one network into range of other network. Using netctl-ifplugd@interface.service, netctl profiles change as you plug the cable in and out.

Note: netcfg used net-auto-wireless.service and net-auto-wired.service for this purpose.

First install required packages:

  • Package wpa_actiond is required to use netctl-auto@interface.service.
  • Package ifplugd is required to use netctl-ifplugd@interface.service.

Now configure all profiles that netctl-auto@interface.service or netctl-ifplugd@interface.service can start. If you want some profile not to be started automatically by these services, you have to explicitly add ExcludeAuto=yes to that profile. You can use Priority= to set priority of some profile when multiple profiles are available. See netctl.profile(5) for details.

Warning: Automatic selection of a WPA-enabled profile by netctl-auto is not possible with option Security=wpa-config, please use Security=wpa-configsection instead.

Once your profiles are set and verified to be working, simply enable these services with

# systemctl enable netctl-auto@interface.service 
# systemctl enable netctl-ifplugd@interface.service  
Warning: If any of the profiles contain errors, such as an empty Key= variable, the unit will fail to load at boot.
Warning: This method conflicts with the basic method. If you have previously enabled a profile through netctl, run
# netctl disable profile
to prevent the profile from starting twice at boot.

从 netcfg 迁移的方法

netctl 使用 /etc/netctl 保存配置,而不是 /etc/network.d (netcfg保存配置的位置).

从 netcfg 迁移,请执行:

  • 禁用 netcfg 服务: # systemctl disable netcfg.service.
  • 删除 netcfg,然后安装 netctl
  • 将老的网络配置移动到新目录
  • 根据 netctl.profile(5) 修改变量名称(主要是大小写变化,例如 CONNECTION 变成 Connection).
  • For static IP configuration make sure the Address variables have a netmask after the IP (e.g. Address=('192.168.1.23/24' '192.168.1.87/24') in the example profile).
  • If you setup a wireless profile according in the wireless-wpa-configsection example, note that this overrides wpa_supplicant options defined above the brackets. For a connection to a hidden wireless network, add scan_ssid=1 to the options in the wireless-wpa-configsection; Hidden=yes does not work there.
  • 接口变量和其他变量不再需要引号(这仅仅是风格变化).
  • 为每一个配置执行netctl enable profile, last工作方式有变化,参阅 netctl.special(7).
  • 使用 netctl list / netctl start <profile> 替换 netcfg-menu. wifi-menu 依然保留。
  • Unlike netcfg, by default netctl fails to bring up a NIC when it is not connected to another powered up NIC. To solve this problem, add SkipNoCarrier=yes at the end of your /etc/netctl/profile.

密码加密(256-bit PSK)

不想用明文保存密码的用户可以使用 256 位加密 PSK.

先用pacman 安装[core]软件仓库中的wpa_actiond

然后用wpa_passphrase生成256位加密 PSK:

Usage: wpa_passphrase [ssid] [passphrase]
$ wpa_passphrase archlinux freenode
注意: 这些信息会在配置中使用,请不要关闭终端。

在第二个终端将/etc/netctl/examples/wireless-wpa 复制到 /etc/netctl

# cp /etc/netctl/examples/wireless-wpa /etc/netctl/wireless-wpa

编辑/etc/netctl/wireless-wpa,将之前生成的Encrypted Pre-shared Key设置到Key

完成后的wireless-wpa应该类似于:

/etc/netctl/wireless-wpa
Description='A simple WPA encrypted wireless connection using 256-bit Encrypted PSK'
Interface=wlp2s2
Connection=wireless
Security=wpa
IP=dhcp
ESSID=archlinux
Key=\"64cf3ced850ecef39197bb7b7b301fc39437a6aa6c6a599d0534b16af578e04a
注意: 请使用special non-quoted rules 设置 Key=,参阅 netctl.profile(5)

支持

官方通知帖: https://bbs.archlinux.org/viewtopic.php?id=157670

提示和技巧

目前还没有功能能够替换 'netcfg current'. 如果需要,请使用:

netctl list|grep \*|sed 's/\*//'|sed 's/\ //'