Difference between revisions of "Netcfg"
m (→Net-Auto-Wired) |
(→Configuration: improved the table and a few other minor fixes) |
||
Line 37: | Line 37: | ||
Depending on the connection type and security, use one of the following examples from {{ic|/etc/network.d/examples/}} as a base. | Depending on the connection type and security, use one of the following examples from {{ic|/etc/network.d/examples/}} as a base. | ||
− | {{Warning|Be wary of examples found on the | + | {{Warning|Be wary of examples found on the internet as they often contain deprecated options that may cause problems!}} |
− | {| | + | {| class="wikitable" align="center" |
− | ! Connection | + | ! Connection !! Type !! Example Profile |
|- | |- | ||
− | | Wired | + | | rowspan="3"| '''Wired''' |
+ | | Dynamic IP || {{ic|ethernet-dhcp}} | ||
|- | |- | ||
− | | | + | | Static IP || {{ic|ethernet-static}} |
|- | |- | ||
− | | | + | | Routed || {{ic|ethernet-iproute}} |
|- | |- | ||
− | | Wireless | + | | rowspan="3"| '''Wireless''' |
+ | | WPA-Personal | ||
+ | | {{ic|wireless-wpa}}<br><font size=1>(using a passphrase/pre-shared key)</font> | ||
|- | |- | ||
− | | | + | | rowspan="2"| WPA-Enterprise |
+ | | {{ic|wireless-wpa-config}}<br><font size=1>(the {{Pkg|wpa_supplicant}} configuration is external)</font> | ||
+ | |- | ||
+ | | {{ic|wireless-wpa-configsection}}<br><font size=1>(the {{Pkg|wpa_supplicant}} configuration is stored as a string)</font> | ||
|} | |} | ||
Line 57: | Line 63: | ||
* Set {{ic|INTERFACE}} to the correct wireless or Ethernet interface. This can be checked with {{ic|ip link}} and {{ic|iwconfig}}. | * Set {{ic|INTERFACE}} to the correct wireless or Ethernet interface. This can be checked with {{ic|ip link}} and {{ic|iwconfig}}. | ||
* Ensure the {{ic|ESSID}} and {{ic|KEY}} (passphrase) are set correctly for wireless connections. Typos in these fields are common errors. | * Ensure the {{ic|ESSID}} and {{ic|KEY}} (passphrase) are set correctly for wireless connections. Typos in these fields are common errors. | ||
− | ** Note that WEP ''string'' keys (not ''hex'' keys) must be specified with a leading {{ic|s:}} (e.g. {{ic|1=KEY="s:somepasskey"}}). | + | ** Note that WEP ''string'' keys (not ''hex'' keys) must be specified with a leading {{ic|s:}} (e.g. {{ic|1=KEY="s:''somepasskey''"}}). |
{{Note|netcfg configurations are valid Bash scripts. Any configuration involving special characters such as {{ic|$}} or {{ic|\}} needs to be quoted correctly otherwise it will be interpreted by Bash. To avoid interpretation, use single quotes or backslash escape characters where appropriate.}} | {{Note|netcfg configurations are valid Bash scripts. Any configuration involving special characters such as {{ic|$}} or {{ic|\}} needs to be quoted correctly otherwise it will be interpreted by Bash. To avoid interpretation, use single quotes or backslash escape characters where appropriate.}} | ||
Line 63: | Line 69: | ||
{{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|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 [[Wpa_supplicant#Classic_method:_.2Fetc.2Fwpa_supplicant.conf|encode the WPA passkey into a hexadecimal string]]. | + | {{Note|For WPA-Personal, it is also possible to [[Wpa_supplicant#Classic_method:_.2Fetc.2Fwpa_supplicant.conf|encode the WPA passkey into a hexadecimal string]]. Save the new hexadecimal string into the wireless WPA profile in {{ic|/etc/network.d/mynetwork}} as the value of the {{ic|KEY}} variable (make sure this will be the only {{ic|KEY}} variable enabled), to look similar to this: {{ic|1=KEY='7b271c9a7c8a6ac07d12403a1f0792d7d92b5957ff8dfd56481ced43ec6a6515'}}. That should disable the need to reveal the passkey.}} |
− | Save the new hexadecimal string into the wireless WPA profile in {{ic|/etc/network.d/mynetwork}} as the value of the {{ic|KEY}} variable (make sure this will be the only {{ic|KEY}} variable enabled), to look similar to this: {{ic|1=KEY='7b271c9a7c8a6ac07d12403a1f0792d7d92b5957ff8dfd56481ced43ec6a6515'}}. That should disable the need to reveal the passkey.}} | ||
==Manual Operation== | ==Manual Operation== |
Revision as of 22:07, 18 October 2012
zh-CN:Netcfg Template:Article summary start Template:Article summary text Template:Article summary heading Template:Article summary text Template:Article summary heading Template:Article summary wiki - Tips and Tricks for netcfg. Template:Article summary wiki - Troubleshooting for netcfg. Template:Article summary link - Git repo for official package scripts. Template:Article summary end Netcfg is used to configure and manage network connections via profiles. It has pluggable support for a range of connection types, such as wireless, Ethernet, PPP. It is also capable of starting/stopping many-to-one connections, that is, multiple connections within the same profile, optionally with bonding. Further it is useful for users seeking a simple and robust means of managing multiple network configurations (e.g. laptop users). With the push to drop support for initscripts/SysV, netcfg is one of several choices users have to managing their network connectivity under systemd.
/etc/rc.conf
compatibility. Users of netcfg should configure all interfaces in /etc/conf.d/netcfg
rather than /etc/rc.conf
.Contents
Preparation
In the simplest cases, users must at least know the name of their network interface(s) (e.g. eth0
, wlan0
). If configuring a static IP address, the IP addresses of the default gateway and name server(s) must also be known.
If connecting to a wireless network, have some basic information ready. For a wireless network this includes what type of security is used, the network name (ESSID), and any passphrase or encryption keys. Additionally, ensure the proper drivers and firmware are installed for the wireless device, as described in Wireless Setup.
Installation
The netcfg package is available in the official repositories.
As of netcfg version 2.5.x, optional dependencies include wpa_actiond — required for automatic/roaming wireless connections — and ifplugd — required for automatic Ethernet configuration. (More information.)
Users wanting Bash completion support for netcfg, install the bash-completion package from the official repositories.
Configuration
Network profiles are stored in /etc/network.d/
.
To minimize the potential for errors, copy an example configuration from /etc/network.d/examples/
to /etc/network.d/mynetwork
. The file name is the name of the network profile ("mynetwork" is used as an example throughout this article).
Depending on the connection type and security, use one of the following examples from /etc/network.d/examples/
as a base.
Connection | Type | Example Profile |
---|---|---|
Wired | Dynamic IP | ethernet-dhcp
|
Static IP | ethernet-static
| |
Routed | ethernet-iproute
| |
Wireless | WPA-Personal | wireless-wpa (using a passphrase/pre-shared key) |
WPA-Enterprise | wireless-wpa-config (the wpa_supplicant configuration is external) | |
wireless-wpa-configsection (the wpa_supplicant configuration is stored as a string) |
Modify the new configuration file, /etc/network.d/mynetwork
:
- Set
INTERFACE
to the correct wireless or Ethernet interface. This can be checked withip link
andiwconfig
. - Ensure the
ESSID
andKEY
(passphrase) are set correctly for wireless connections. Typos in these fields are common errors.- Note that WEP string keys (not hex keys) must be specified with a leading
s:
(e.g.KEY="s:somepasskey"
).
- Note that WEP string keys (not hex keys) must be specified with a leading
$
or \
needs to be quoted correctly otherwise it will be interpreted by Bash. To avoid interpretation, use single quotes or backslash escape characters where appropriate.chmod 0600 /etc/network.d/mynetwork
) to make it readable by root only./etc/network.d/mynetwork
as the value of the KEY
variable (make sure this will be the only KEY
variable enabled), to look similar to this: KEY='7b271c9a7c8a6ac07d12403a1f0792d7d92b5957ff8dfd56481ced43ec6a6515'
. That should disable the need to reveal the passkey.Manual Operation
To connect a profile:
# netcfg mynetwork
To disconnect a profile:
# netcfg down mynetwork
If successful, users can configure netcfg to connect automatically or during boot. If the connection fails, see #Troubleshooting for solutions and how to get help.
For other functions, see:
$ netcfg help
Automatic Operation
Net-Profiles
Edit the NETWORKS
array in /etc/conf.d/netcfg
to refer to your network config file /etc/network.d/mynetwork
.
/etc/conf.d/netcfg
NETWORKS=(mynetwork yournetwork)
Start the service on startup:
# systemctl enable netcfg.service
Alternate solution:
Specify the desired profile manually, without editing /etc/conf.d/netcfg
.
# systemctl enable netcfg@mynetwork.service
Alternatively, the profiles that were active at last shutdown can be restored by setting the NETWORKS
array to last
.
/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.
netcfg-menu
in a terminal.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.
# systemctl enable net-auto-wireless.service
Net-Auto-Wired
This allows users to automatically connect to wired networks. To use this feature, the ifplugd package is required.
Specify the desired wired interface with the WIRED_INTERFACE
variable in /etc/conf.d/netcfg
.
Enable the net-auto-wired.service
so systemd manages it.
# 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.
AUTO_WIRED=1
to the desired profile.net-auto-wired
daemon cannot start multiple ifplugd processes for multiple interfaces (unlike ifplugd's own /etc/rc.d/ifplugd
which can).