Difference between revisions of "Netcfg"

From ArchWiki
Jump to navigation Jump to search
(netcfg was deprecated in favour of netctl, just redirect there)
 
(201 intermediate revisions by 78 users not shown)
Line 1: Line 1:
[[Category:Networking (English)]]
+
#REDIRECT [[Netctl]]
{{i18n|Netcfg}}
 
{{Article summary start}}
 
{{Article summary text|A guide to installing and configuring netcfg – network configuration and profile scripts.}}
 
{{Article summary heading|Related}}
 
{{Article summary wiki|Network}}
 
{{Article summary wiki|Wireless Setup}}
 
{{Article summary heading|Resources}}
 
{{Article summary link|netcfg network scripts repository|http://projects.archlinux.org/netcfg.git/}}
 
{{Article summary end}}
 
 
 
From the [http://projects.archlinux.org/netcfg.git/tree/man/netcfg.8 netcfg man page]:
 
 
 
:'''''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.''
 
 
 
netcfg is useful for users seeking a simple and robust means of managing multiple network configurations (e.g. laptop users). For systems connecting to a single network, the [[network]] daemon may be more appropriate.
 
 
 
==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, gateway and name server addresses 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 (SSID), and any password or encryption keys. Additionally, ensure the proper drivers and firmware are installed for the wireless device, as described in [[Wireless Setup]].
 
 
 
==Installation==
 
Ensure you have the latest version of netcfg installed. Older versions have more bugs and may not work well with the latest drivers. The {{Package Official|netcfg}} package is available in '''core''':
 
 
 
# pacman -S netcfg
 
 
 
As of version 2.5.x, optional dependencies include {{Package Official|wpa_actiond}} – required for automatic/roaming wireless connection – and {{Package Official|ifplugd}} – required for automatic ethernet configuration. ([http://www.archlinux.org/news/487/ More information].)
 
 
 
# pacman -S wpa_actiond ifplugd
 
 
 
==Configuration==
 
Network profiles are stored in the {{Filename|/etc/network.d}} directory. To minimize the potential for errors, copy an example configuration from {{Filename|/etc/network.d/examples}} to {{Filename|/etc/network.d/mynetwork}}. The file name is the name of the network profile ("mynetwork" is used as an example throughout this article). The name is not a network setting and does not need to match the wireless network name (SSID).
 
 
 
Depending on the connection type and security, use one of the following examples from {{Filename|/etc/network.d/examples}} as a base. Be wary of examples found on the Internet as they often contain deprecated options that may cause problems.
 
 
 
{| border="1"
 
! Connection type/security !! Example profile
 
|-
 
| Wireless; WEP hex key || {{Filename|wireless-wep}}
 
|-
 
| Wireless; WEP string key || {{Filename|wireless-wep-string-key}}
 
|-
 
| Wireless; WPA personal (passphrase) || {{Filename|wireless-wpa}}
 
|-
 
| Wireless; WPA enterprise || {{Filename|wireless-wpa-config}} (wpa_supplicant configuration is external) <br /> {{Filename|wireless-wpa-configsection}} (wpa_supplicant configuration stored as string)
 
|-
 
| Wired; DHCP || {{Filename|ethernet-dhcp}}
 
|-
 
| Wired; static IP || {{Filename|ethernet-static}}
 
|-
 
| Wired; iproute configuration || {{Filename|ethernet-iproute}}
 
|}
 
 
 
Next, modify the new configuration file, {{Filename|/etc/network.d/mynetwork}}:
 
 
 
* Set {{Codeline|INTERFACE}} to the correct wireless or ethernet interface. This can be checked with {{Codeline|ifconfig}} and {{Codeline|iwconfig}}.
 
* Ensure the {{Codeline|ESSID}} and {{Codeline|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 {{Codeline|s:}} (e.g. {{Codeline|<nowiki>KEY="s:somepasskey"</nowiki>}}).
 
 
 
{{Note | Netcfg configurations are valid Bash scripts. Any configuration involving special characters such as $ 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. }}
 
 
 
{{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. {{Codeline|chmod 0600 /etc/network.d/mynetwork}} to make it readable by root only).}}
 
 
 
==Usage==
 
To connect a profile:
 
# netcfg mynetwork
 
 
 
To disconnect a profile:
 
# netcfg down <profile-name>
 
 
 
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
 
 
 
==Connecting automatically==
 
Several methods are available to users wanting to automatically connect network profiles (e.g. during boot or whilst roaming). Note that a network profile must be properly configured within the {{Filename|/etc/network.d}} directory ''first'' (see [[#Configuration]]).
 
 
 
{{Tip|If enabling one of the following daemons and nothing is configured within the {{Codeline|INTERFACES}} array in {{Filename|rc.conf}}, you may remove the {{Codeline|network}} daemon from the {{Codeline|DAEMONS}} array. If you mount NFS shares during boot, ensure the {{Codeline|netfs}} daemon remains listed, though (otherwise the network will be dropped before unmounting shares during shutdown).}}
 
 
 
===net-profiles===
 
'''{{Codeline|net-profiles}} allows users to connect profiles during boot.'''
 
 
 
To enable this feature, users must add {{Codeline|net-profiles}} to the {{Codeline|DAEMONS}} array in [[rc.conf]] and specify profiles to try in the {{Codeline|NETWORKS}} array:
 
 
 
{{File
 
|name=/etc/rc.conf
 
|content=<nowiki>
 
NETWORKS=(mynetwork yournetwork)
 
 
 
...
 
 
 
DAEMONS=(... net-profiles ...)
 
</nowiki>}}
 
 
 
Alternatively, {{Codeline|net-profiles}} can be configured to display a menu &ndash; allowing users to choose a desired profile &ndash; by setting the contents of the {{Codeline|NETWORKS}} array to {{Codeline|menu}}:
 
 
 
{{File
 
|name=/etc/rc.conf
 
|content=<nowiki>
 
NETWORKS=(menu)
 
 
 
...
 
 
 
DAEMONS=(... net-profiles ...)
 
</nowiki>}}
 
 
 
Additionally, the {{Package Official|dialog}} package is required.
 
 
 
{{Tip|Access the menu at any time by running {{Codeline|netcfg-menu}} in a terminal.}}
 
 
 
===net-auto-wireless===
 
'''{{Codeline|net-auto-wireless}} allows users to automatically connect to wireless networks with proper roaming support.'''
 
 
 
To enable this feature, users must add {{Codeline|net-auto-wireless}} to the {{Codeline|DAEMONS}} array in [[rc.conf]] and specify the desired wireless interface with the {{Codeline|WIRELESS_INTERFACE}} variable:
 
 
 
{{File
 
|name=/etc/rc.conf
 
|content=<nowiki>
 
WIRELESS_INTERFACE="wlan0"
 
 
 
...
 
 
 
DAEMONS=(... net-auto-wireless ...)
 
</nowiki>}}
 
 
 
Additionally, the {{Package Official|wpa_actiond}} package is required. Note that wpa-config profiles does not work with net-auto-wireless. Convert them to wpa-configsection instead.
 
 
 
===net-auto-wired===
 
'''{{Codeline|net-auto-wired}} allows users to automatically connect to wired networks.'''
 
 
 
To enable this feature, users must install ifplugd
 
 
 
# pacman -S ifplugd
 
 
 
and add {{Codeline|net-auto-wired}} to the {{Codeline|DAEMONS}} array in [[rc.conf]] and specify the desired wired interface with the {{Codeline|WIRED_INTERFACE}} variable:
 
 
 
{{File
 
|name=/etc/rc.conf
 
|content=<nowiki>
 
WIRED_INTERFACE="eth0"
 
 
 
...
 
 
 
DAEMONS=(... net-auto-wired ...)
 
</nowiki>}}
 
 
 
The daemon starts an ifplugd process which runs {{Filename|/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.
 
 
 
Note2: The net-auto-wired daemon cannot start multiple ifplugd processes for multiple interfaces (unlike ifplugd's own /etc/rc.d/ifplugd which can).
 
 
 
==Tips and tricks==
 
 
 
===Passing arguments to iwconfig before connecting===
 
Simply add the following to a profile:
 
 
 
IWCONFIG="<arguments>"
 
 
 
Where {{Codeline|<arguments>}} can be any valid {{Codeline|iwconfig}} argument. The script then runs {{Codeline|iwconfig $INTERFACE $IWCONFIG}}.
 
 
 
For example, force the card to register to a specific access point given by MAC address:
 
IWCONFIG="ap 12:34:56:78:90:12"
 
 
 
This supersedes the {{Codeline|IWOPTS}} and {{Codeline|WEP_OPTS}} options which were incompletely implemented.
 
 
 
===rfkill (enable/disable radio power)===
 
netcfg can enable/disable radio for wireless cards equipped with software control of radio. For wireless cards with hardware switches, netcfg can detect disabled hardware switches and fail accordingly.
 
 
 
To enable rfkill support, you need to specify what sort of switch the wireless interface has; hardware or software. This can be set within a profile or at the interface level ({{Filename|/etc/network.d/interfaces/$INTERFACE}}; see [[#Per-interface configuration]]).
 
 
 
RFKILL=soft # can be either 'hard' or 'soft'
 
 
 
For some kill switches the rfkill entry in {{Filename|/sys}} is not linked to the interface and the {{Codeline|RFKILL_NAME}} variable needs to be set to the contents of the matching {{Filename|/sys/class/rfkill/rfkill#/name}}.
 
 
 
For example, on an Eee PC:
 
 
 
RFKILL=soft
 
RFKILL_NAME='eeepc-wlan'
 
 
 
===Execute commands before/after interface up/down===
 
If your interface requires special actions prior/after the establishment/closure of a connection, you may use the {{Codeline|PRE_UP}}, {{Codeline|POST_UP}}, {{Codeline|PRE_DOWN}}, and {{Codeline|POST_DOWN}} variables.
 
 
 
For example, if you want to configure your wireless card to operate in ad-hoc mode but you can only change modes when the interface is down, you could use something like this:
 
 
 
PRE_UP="ifconfig wlan0 down; iwconfig wlan0 mode ad-hoc"
 
 
 
Or if you want to mount your network shares after a successful connection, you could use:
 
 
 
POST_UP="sleep 5; mount /mnt/shares/nexus/utorrent 2>/dev/null"
 
 
 
{{Note|If the commands specified in these properties return anything other than 0 (success), netcfg aborts the current operation. So if you want to mount a certain network share that might not be available at the time of connection (thus returning an error), you could create a separate Bash script with the mount commands and a {{Codeline|exit 0}} at the end. Alternatively you can add {{Codeline|<nowiki>|| true</nowiki>}} to the end of the command that may fail.}}
 
 
 
===Per-interface configuration===
 
Configuration options that apply to all profiles using an interface can be set using {{Filename|/etc/network.d/interfaces/$INTERFACE}}. For example:
 
 
 
/etc/network.d/interfaces/wlan0
 
 
 
This is useful for {{Codeline|wpa_supplicant}} options, rfkill switch support, pre/post up/down scripts and {{Codeline|net-auto-wireless}}. These options are loaded ''before'' profiles so that any profile-based options will take priority.
 
 
 
{{Filename|/etc/network.d/interfaces/$INTERFACE}} may contain any valid profile option, though you are likely to use {{Codeline|PRE_UP}}/{{Codeline|DOWN}} and {{Codeline|POST_UP}}/{{Codeline|DOWN}} (described in the previous section) or one of the options listed below. Remember that these options are set for ''all'' profiles using the interface; you probably do not want to connect to your work VPN here, for instance, as it will try to connect on ''every'' wireless network!
 
 
 
WPA_GROUP  - Setting the group of the wpa_ctrl interface
 
WPA_COUNTRY - Enforces local regulatory limitations and allows use of more channels
 
WPA_DRIVER  - Defaults to wext, may want nl80211 for mac80211 devices
 
 
 
{{Note|{{Codeline|POST_UP}}/{{Codeline|POST_DOWN}} require the {{Package Official|wpa_actiond}} package.}}
 
 
 
===Output hooks===
 
netcfg has limited support to load hooks that handle output. By default it loads the {{Filename|arch}} hook which provides the familiar output that you see. A syslog logging hook is also included. These can be found at {{Filename|/usr/lib/network/hooks}}.
 
 
 
===ArchAssitant (GUI)===
 
 
 
A Qt-based netcfg front-end called ArchAssistant exists. It proposes to manage and connect/disconnect profiles from a systray icon. Automatic wireless detection is also available. This tool is particularly useful for laptop users.
 
 
 
Links:
 
 
 
* [http://aur.archlinux.org/packages.php?ID=15655 archassistant in the AUR]
 
* [http://www.kde-apps.org/content/show.php/ArchAssistant?content=76760 archassistant on kde-apps.org]
 
* archassistant package on archlinux.fr: [http://repo.archlinux.fr/i686/archassistant/ i686] and [http://repo.archlinux.fr/x86_64/archassistant/ x86_64]
 
 
 
There is also a relatively new GUI for netcfg2 on qt-apps.org that does only network configuration. You can find it [http://www.qt-apps.org/content/show.php/netcfgGUI?content=99523 here].
 
 
 
===wifi-select===
 
 
 
There is a console tool for selecting wireless networks in "real-time" (in NetworkManager manner) called <tt>wifi-select</tt>. The tool is convenient for use in Internet cafés or other places you are visiting for the first (and maybe the last) time. With this tool, you do not need to create a profile for a new network, just type {{Codeline|sudo wifi-select wlan0}} and choose the network you need.
 
 
 
The tool is currently packaged and available in [community] repository. To install:
 
 
 
# pacman -S wifi-select
 
 
 
<tt>wifi-select</tt> does the following:
 
* parses <tt>iwlist scan</tt> results and presents list of networks along with its security settings (WPA/WEP/none) using <tt>dialog</tt>
 
* if user selects network with existing profile -- just use this profile to connect with <tt>netcfg</tt>
 
* if user selects a new network (for example, WiFi hotspot), <tt>wifi-select</tt> automatically generates new profile with corresponding <tt>$SECURITY</tt> and asks for the key (if needed). It uses DHCP as <tt>$IP</tt> by default
 
* then, if connection succeeds, profile is saved for later usage
 
* if connection fails, user is asked if he/she wants to keep generated profile for further usage (for example to change <tt>$IP</tt> to static or adjust some additional options)
 
 
 
Links:
 
 
 
* [http://bbs.archlinux.org/viewtopic.php?id=63973 Forum thread] related to development of <tt>wifi-select</tt>
 
* [http://aur.archlinux.org/packages.php?ID=23471 wifi-select in the AUR]
 
* [http://hg.horna.org.ua/wifi-select/ wifi-select Mercurial repository]
 
 
 
==Troubleshooting==
 
 
 
===Debugging===
 
To run netcfg with debugging output, set the {{Codeline|NETCFG_DEBUG}} environment variable to {{Codeline|"yes"}}, for example:
 
 
 
# NETCFG_DEBUG="yes" netcfg <arguments>
 
 
 
Debugging information for wpa_supplicant can be logged using {{Codeline|WPA_OPTS}} within a profile, for example:
 
 
 
WPA_OPTS="-f/path/to/log"
 
 
 
Whatever is entered here will be added to the command when wpa_supplicant is called.
 
 
 
===Network unavailable===
 
This error is typically due to:
 
* Out of range
 
* Driver issue
 
* Trying to connect to a hidden network
 
 
 
If you know your network is hidden, set:
 
SCAN=no
 
 
 
===Wireless association failed===
 
This error is typically due to:
 
* Out of range/reception
 
* Incorrect configuration
 
* Invalid key
 
* Driver problem
 
 
 
If it is a range problem, increasing {{Codeline|TIMEOUT}} can help.
 
 
 
===Unable to get IP address with DHCP===
 
This error is typically due to:
 
* Out of range/reception
 
 
 
Try increasing {{Codeline|DHCP_TIMEOUT}}.
 
 
 
===Not a valid connection, check spelling or look at examples===
 
You must set {{Codeline|CONNECTION}} to one of the connection types listed in the {{Filename|/usr/lib/network/connections}} directory. Alternatively, use one of the provided configuration examples in {{Filename|/etc/network.d/examples}}.
 
 
 
===Driver quirks===
 
{{Note|You most likely do '''not''' need quirks; ensure your configuration is correct before considering them. Quirks are intended for a small range of drivers with unusual issues, many of them older versions. These are workarounds, not solutions.}}
 
 
 
Some drivers behave oddly and need workarounds to connect. Quirks must be enabled manually. They are best determined by reading the forums, seeing what others have used, and, if that fails, trial and error. Quirks can be combined.
 
 
 
; {{Codeline|prescan}}: Run {{Codeline|iwlist $INTERFACE scan}} before attempting to connect (broadcom)
 
; {{Codeline|preessid}}: Run {{Codeline|iwconfig $INTERFACE essid $ESSID}} before attempting to connect (ipw3945 and Intel PRO/Wireless 4965AGN)
 
; {{Codeline|wpaessid}}: Same as previous, run before starting {{Codeline|wpa_supplicant}}. Not supported anymore  - use <pre>IWCONFIG="essid $ESSID"</pre> instead. (ath9k)
 
; {{Codeline|predown}}: Take interface down before association and then restore it after (madwifi)
 
; {{Codeline|postsleep}}: Sleep one second before checking if the association was successful
 
; {{Codeline|postscan}}: Run {{Codeline|iwlist scan}} after associating
 
 
 
For example:
 
QUIRKS=(prescan preessid)
 
 
 
If you receive "Wireless network not found" or "Association failed" errors and have tried the above, try:
 
SCAN=no
 
 
 
If an AP with a hidden SSID is used, try
 
IWCONFIG="essid $ESSID"
 
 
 
===Ralink legacy drivers rt2500, rt2400 that use iwpriv===
 
There is no plans to add WPA support to these drivers. rt2x00 is supported, however, and will replace these.
 
 
 
If you must use them, create a shell script that runs the needed {{Codeline|iwpriv}} commands and put its path in {{Codeline|PRE_UP}}.
 
 
 
===It still doesn't work, what do I do?===
 
If this article did not help solve your problem, the next best place to ask for help is the forums or the mailing list.
 
 
 
To be able to determine the problem, we need information. When you ask, provide the following output:
 
* '''ALL OUTPUT FROM netcfg'''
 
* '''ALL OUTPUT FROM netcfg'''
 
* '''ALL OUTPUT FROM netcfg'''
 
** This is absolutely crucial to be able determine what went wrong. The message might be short or non-existent, but it can mean a great deal.
 
* '''{{Filename|/etc/network.d}} network profiles'''
 
** This is also crucial as many problems are simple configuration issues. Feel free to censor your wireless key.
 
* '''netcfg version'''
 
* {{Codeline|lsmod}}
 
* {{Codeline|iwconfig}}
 
 
 
==FAQ==
 
{{FAQ
 
|question=Why doesn't netcfg do ''(some feature)''?
 
|answer=netcfg doesn't need to; it connects to networks. netcfg is modular and re-usable; see {{Filename|/usr/lib/networks}} for reusable functions for custom scripts.}}
 
 
 
{{FAQ
 
|question=Why doesn't netcfg behave in ''this'' way?
 
|answer=netcfg doesn't enforce any rules; it connects to networks. It doesn't impose any heuristics, like "disconnect from wireless if ethernet is connected". If you want behaviour like that, it should be simple to write a separate tool over netcfg. See the question above.}}
 
 
 
{{FAQ
 
|question=Do I still need ''(some thing)'' if I'm using netcfg?
 
|answer=This question usually references {{Filename|/etc/hosts}} and the {{Codeline|HOSTNAME}} variable in {{Filename|/etc/rc.conf}}, which are both still required. You may remove {{Codeline|network}} from the {{Codeline|DAEMONS}} array if you've configured all your networks with netcfg, though.}}
 

Latest revision as of 15:26, 16 July 2013

Redirect to: