Difference between revisions of "NetworkManager"

From ArchWiki
Jump to: navigation, search
m (Undo revision 264867 by Diogoleal (talk) /bin/bash is the standard shebang.)
m (Installation: grammar)
 
(450 intermediate revisions by more than 100 users not shown)
Line 1: Line 1:
[[Category:Networking]]
+
[[Category:Network managers]]
 
[[cs:NetworkManager]]
 
[[cs:NetworkManager]]
 
[[de:Networkmanager]]
 
[[de:Networkmanager]]
Line 8: Line 8:
 
[[pt:NetworkManager]]
 
[[pt:NetworkManager]]
 
[[ru:NetworkManager]]
 
[[ru:NetworkManager]]
[[tr:NetworkManager]]
+
[[zh-hans:NetworkManager]]
[[zh-CN:NetworkManager]]
+
{{Related articles start}}
{{Article summary start}}
+
{{Related|Network configuration}}
{{Article summary text|Covers installation and configuration of NetworkManager – a set of co-operative tools that make networking simple and straightforward.}}
+
{{Related|Wireless network configuration}}
{{Article summary heading|Overview}}
+
{{Related articles end}}
{{Article summary text|{{Networking overview}}}}
+
[http://projects.gnome.org/NetworkManager/ NetworkManager] is a program for providing detection and configuration for systems to automatically connect to network.  NetworkManager's functionality can be useful for both wireless and wired networks.  For wireless networks, NetworkManager prefers known wireless networks and has the ability to switch to the most reliable network.  NetworkManager-aware applications can switch from online and offline mode.  NetworkManager also prefers wired connections over wireless ones, has support for modem connections and certain types of VPN.  NetworkManager was originally developed by Red Hat and now is hosted by the [[GNOME]] project.
{{Article summary end}}
 
  
[http://projects.gnome.org/NetworkManager/ NetworkManager] is a program for providing detection and configuration for systems to automatically connect to network. NetworkManager's functionality can be useful for both wireless and wired networks. For wireless networks, NetworkManager prefers known wireless networks and has the ability to switch to the most reliable network. NetworkManager-aware applications can switch from online and offline mode. NetworkManager also prefers wired connections over wireless ones, has support for modem connections and certain types of VPN. NetworkManager was originally developed by Red Hat and now is hosted by the [[GNOME]] project.
+
{{Warning|By default, Wi-Fi passwords are stored in clear text, see [[#Encrypted Wi-Fi passwords]].}}
 +
 
 +
== Installation ==
 +
 
 +
NetworkManager can be [[install]]ed with the package {{Pkg|networkmanager}}, which contains a daemon, a command line interface ({{ic|nmcli}}) and a curses‐based interface ({{ic|nmtui}}). It has functionality for basic DHCP support. For full featured DHCP and if you require IPv6 support, {{Pkg|dhclient}} integrates it. After installation, you should [[#Enable_NetworkManager|enable the daemon]].
 +
 
 +
Additional interfaces:
 +
* {{Pkg|nm-connection-editor}} for a graphical user interface,
 +
* {{Pkg|network-manager-applet}} for a system tray applet ({{ic|nm-applet}}).
 +
 
 +
{{Note|You must ensure that no other service that wants to configure the network is running; in fact, multiple networking services will conflict. You can find a list of the currently running services with {{ic|1=systemctl --type=service}} and then [[stop]] them. See [[#Configuration]] to enable the NetworkManager service.}}
 +
 
 +
=== Mobile broadband support ===
 +
 
 +
[[Install]] {{Pkg|modemmanager}}, {{Pkg|mobile-broadband-provider-info}} and {{Pkg|usb_modeswitch}} packages for mobile broadband connection support. See [[USB 3G Modem#Network Manager]] for details.
  
== Base install ==
+
=== PPPoE / DSL support ===
  
NetworkManager can be installed with the package {{Pkg|networkmanager}}, available in the [[official repositories]].
+
[[Install]] {{Pkg|rp-pppoe}} package for PPPoE / DSL connection support. To actually add PPPoE connection, use {{ic|1=nm-connection-editor}} and add new DSL/PPPoE connection.
  
 
=== VPN support ===
 
=== VPN support ===
  
Network Manager VPN support is based on a plug-in system. If you need VPN support via network manager you have to install one of the following packages from the [[official repositories]]:
+
NetworkManager VPN support is based on a plug-in system. If you need VPN support via NetworkManager, you have to install one of the following packages:
 +
 
 +
* {{Pkg|networkmanager-openconnect}} for [[OpenConnect]]
 +
* {{Pkg|networkmanager-openvpn}} for [[OpenVPN]]
 +
* {{Pkg|networkmanager-pptp}} for [[PPTP Client]]
 +
* {{Pkg|networkmanager-vpnc}} for [[Vpnc]]
 +
* {{Pkg|networkmanager-strongswan}} for [[strongSwan]]
 +
* {{AUR|networkmanager-fortisslvpn-git}}
 +
* {{AUR|networkmanager-iodine-git}}
 +
* {{AUR|networkmanager-libreswan}}
 +
* {{AUR|networkmanager-l2tp}}
 +
* {{AUR|networkmanager-ssh-git}}
 +
* {{AUR|networkmanager-sstp}}
 +
 
 +
{{Warning|1=VPN support is [https://bugzilla.gnome.org/buglist.cgi?quicksearch=networkmanager%20vpn unstable], check the daemon processes options set via the GUI correctly and double-check with each package release.[https://bugzilla.gnome.org/show_bug.cgi?id=755350]}}
  
* {{Pkg|networkmanager-openvpn}}
+
== Usage ==
* {{Pkg|networkmanager-pptp}}
 
* {{Pkg|networkmanager-vpnc}}
 
  
== Graphical front-ends ==
+
NetworkManager comes with {{man|1|nmcli}} and {{man|1|nmtui}}.
  
To configure and have easy access to NetworkManager most people will want to install an applet. This GUI front-end usually resides in the system tray (or notification area) and allows network selection and configuration of NetworkManager. Various applets exist for different types of desktops.
+
=== nmcli examples ===
  
=== GNOME ===
+
List nearby wifi networks:
 +
 
 +
$ nmcli device wifi list
 +
 
 +
Connect to a wifi network:
 +
 
 +
$ nmcli device wifi connect ''SSID'' password ''password''
 +
 
 +
Connect to a hidden network:
  
GNOME's {{Pkg|network-manager-applet}} is lightweight enough and works across all environments.
+
$ nmcli device wifi connect ''SSID'' password ''password'' hidden yes
  
If you want to store authentication details (Wireless/DSL) and enable global connection settings, i.e "available to all users" install and configure [[GNOME Keyring]].
+
Connect to a wifi on the {{ic|wlan1}} wifi interface:
  
=== KDE ===
+
$ nmcli device wifi connect ''SSID'' password ''password'' ifname wlan1 ''profile_name''
  
The KNetworkManager front-end is a Plasma widget available in the official repositories as package {{Pkg|kdeplasma-applets-networkmanagement}}.
+
Disconnect an interface:
  
{{Note|If you are changing from another network managing tool like [[Wicd]], do not forget to set the default 'Network Management Backend' in
+
$ nmcli device disconnect ifname eth0
System Settings -> Hardware -> Information Sources}}
 
  
If you have both the Plasma widget and {{ic|nm-applet}} installed and do not want to start {{ic|nm-applet}} when using KDE, add the following line to {{ic|/etc/xdg/autostart/nm-applet.desktop}}:
+
Reconnect an interface marked as disconnected:
NotShowIn=KDE
 
  
See [http://userbase.kde.org/NetworkManagement Userbase page] for more info.
+
$ nmcli connection up uuid ''UUID''
  
=== XFCE ===
+
Get a list of UUIDs:
{{Pkg|network-manager-applet}} will work fine in XFCE, but in order to see notifications, ''including error messages'', {{ic|nm-applet}} needs an implementation of the Freedesktop desktop notifications specification (see the [http://www.galago-project.org/specs/notification/0.9/index.html Galapago Project]) to display them. To enable notifications install {{Pkg|xfce4-notifyd}}, a package that provides an implementation for the specification.
 
  
Without such a notification daemon, {{ic|nm-applet}} outputs the following errors to stdout/stderr:
+
$ nmcli connection show
  
(nm-applet:24209): libnotify-WARNING **: Failed to connect to proxy
+
See a list of network devices and their state:
** (nm-applet:24209): WARNING **: get_all_cb: couldn't retrieve
 
system settings properties: (25) Launch helper exited with unknown
 
return code 1.
 
** (nm-applet:24209): WARNING **: fetch_connections_done: error
 
fetching connections: (25) Launch helper exited with unknown return
 
code 1.
 
** (nm-applet:24209): WARNING **: Failed to register as an agent:
 
(25) Launch helper exited with unknown return code 1
 
  
{{ic|nm-applet}} will still work fine, though, but without notifications.
+
$ nmcli device
  
If nm-applet is not prompting for a password when connecting to new wifi networks, and is just disconnecting immediately, you probably need to install {{Pkg|gnome-keyring}}.
+
Turn off wifi:
  
=== Openbox ===
+
$ nmcli radio wifi off
  
To function properly in Openbox, the GNOME applet requires the {{Pkg|xfce4-notifyd}} notification daemon for the same reason as in XFCE and the {{Pkg|gnome-icon-theme}} package to be able to display the applet in the systray.
+
== Front-ends ==
  
If you want to store authentication details (Wireless/DSL) install and configure [[gnome-keyring]].
+
To configure and have easy access to NetworkManager, most users will want to install an applet. This GUI front-end usually resides in the system tray (or notification area) and allows network selection and configuration of NetworkManager. Various desktop environments have their own applet. Otherwise you can use [[#nm-applet]].
  
{{Note|If the ''networkmanager'' daemon is in {{ic|rc.conf}}, the following settings are obsolete or the applet will be started twice.}}
+
=== GNOME ===
  
To have Openbox's autostart start {{ic|nm-applet}} properly, you may need to delete the file {{ic|/etc/xdg/autostart/nm-applet.desktop}} (You may need to delete this file again after every update to {{Pkg|network-manager-applet}}).
+
[[GNOME]] has a built-in tool, accessible from the Network settings.
  
Then in {{ic|autostart}}, start {{ic|nm-applet}} with this line:
+
=== KDE Plasma ===
  
(sleep 3 && /usr/bin/nm-applet --sm-disable) &
+
[[Install]] the {{Pkg|plasma-nm}} package.
  
If you experience errors connecting, make sure you have your [[D-Bus]] user session started.
+
=== nm-applet ===
  
=== Other desktops and window managers ===
+
{{Pkg|network-manager-applet}} is a GTK+ 3 front-end which works under Xorg environments with a systray.
  
In all other scenarios it is recommended to use the GNOME applet. You will also need to be sure that the {{Pkg|gnome-icon-theme}} package is installed to be able to display the applet.
+
To store connection secrets install and configure [[GNOME/Keyring]].
  
To store connection secrets install and configure [[gnome-keyring]].
+
Be aware that after enabling the tick-box option {{ic|Make available to other users}} for a connection, NetworkManager stores the password in plain-text, though the respective file is accessible only to root (or other users via {{ic|nm-applet}}). See [[#Encrypted Wi-Fi passwords]].
  
 
In order to run {{ic|nm-applet}} without a systray, you can use {{Pkg|trayer}} or {{Pkg|stalonetray}}. For example, you can add a script like this one in your path:
 
In order to run {{ic|nm-applet}} without a systray, you can use {{Pkg|trayer}} or {{Pkg|stalonetray}}. For example, you can add a script like this one in your path:
 +
 
{{hc|nmgui|<nowiki>
 
{{hc|nmgui|<nowiki>
#!/bin/sh
+
#!/bin/sh
nm-applet    > /dev/null 2>/dev/null &
+
nm-applet    2>&1 > /dev/null &
stalonetray  > /dev/null 2>/dev/null
+
stalonetray  2>&1 > /dev/null
killall nm-applet
+
killall nm-applet
 
</nowiki>}}
 
</nowiki>}}
  
When you close the stalonetray window, it closes {{ic|nm-applet}} too, so no extra memory is used once you are done with network settings.
+
When you close the ''stalonetray'' window, it closes {{ic|nm-applet}} too, so no extra memory is used once you are done with network settings.
  
=== Command line ===
+
The applet can show notifications for events such as connecting to or disconnecting from a WiFi network. For these notifications to display, ensure that you have a notification server installed - see [[Desktop notifications]]. If you use the applet without a notification server, you might see some messages in stdout/stderr, and the app might hang. See [https://bugzilla.gnome.org/show_bug.cgi?id=788313].
  
The {{Pkg|networkmanager}} package contains [http://manpages.ubuntu.com/manpages/maverick/man1/nmcli.1.html nmcli] since version 0.8.1.
+
In order to run {{ic|nm-applet}} with such notifications disabled, start the applet with the following command:
 +
$ nm-applet --no-agent
 +
 
 +
{{Tip|{{ic|nm-applet}} might be started automatically with a [[XDG Autostart|autostart desktop file]], to add the --no-agent option modify the Exec line there, i.e.
 +
<nowiki>Exec=nm-applet --no-agent</nowiki>
 +
}}
 +
 
 +
==== Appindicator ====
 +
 
 +
Appindicator support is available in ''nm-applet'' however it is not compiled into the official package, see {{Bug|51740}}. To use nm-applet in an Appindicator environment, replace {{Pkg|network-manager-applet}} with {{AUR|network-manager-applet-indicator}} and then start the applet with the following command:
 +
$ nm-applet --indicator
 +
 
 +
=== nmcli-dmenu ===
 +
 
 +
Alternatively there is {{AUR|networkmanager-dmenu-git}} which is a small script to manage NetworkManager connections with ''dmenu'' instead of {{ic|nm-applet}}. It provides all essential features such as connect to existing NetworkManager wifi or wired connections, connect to new wifi connections, requests passphrase if required, connect to existing VPN connections, enable/disable networking, launch ''nm-connection-editor'' GUI.
  
 
== Configuration ==
 
== Configuration ==
  
NetworkManager will require some additional steps to be able run properly.
+
NetworkManager will require some additional steps to be able run properly. Make sure you have configured {{ic|/etc/hosts}} as described in [[Network configuration#Set the hostname]] section.
 +
 
 +
=== Enable NetworkManager ===
 +
 
 +
NetworkManager is [[systemd#Using units|controlled]] with the {{ic|NetworkManager.service}} [[systemd]] unit. Once the NetworkManager daemon is started, it will automatically connect to any available "system connections" that have already been configured. Any "user connections" or unconfigured connections will need ''nmcli'' or an applet to configure and connect.
  
Verify that your {{ic|/etc/hosts}} is correct before continuing.  If you previously tried to connect before doing this step, NetworkManager may have altered it. An example hostname line in {{ic|/etc/hosts}}:
+
NetworkManager has a global configuration file at {{ic|/etc/NetworkManager/NetworkManager.conf}}. Addition configuration files can be placed in {{ic|/etc/NetworkManager/conf.d/}}. Usually no configuration needs to be done to the global defaults.
  
{{hc|/etc/hosts|
+
=== Enable NetworkManager Wait Online ===
127.0.0.1 localhost
+
 
::1      localhost
+
If you have services which fail if they are started before the network is up, you may use {{ic|NetworkManager-wait-online.service}} in addition to {{ic|NetworkManager.service}}. This is, however, rarely necessary because most networked daemons start up okay, even if the network has not been configured yet.
 +
 
 +
In some cases, the service will still fail to start successfully on boot due to the timeout setting in {{ic|/usr/lib/systemd/system/NetworkManager-wait-online.service}} being too short. Change the default timeout from 30 to a higher value.
 +
 
 +
=== Set up PolicyKit permissions ===
 +
 
 +
See [[General troubleshooting#Session permissions]] for setting up a working session.
 +
 
 +
With a working session, you have several options for granting the necessary privileges to NetworkManager:
 +
 
 +
* ''Option 1.'' Run a [[Polkit]] authentication agent when you log in, such as {{ic|/usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1}} (part of {{Pkg|polkit-gnome}}).  You will be prompted for your password whenever you add or remove a network connection.
 +
* ''Option 2.'' [[Users and groups#Group management|Add]] yourself to the {{ic|wheel}} group.  You will not have to enter your password, but your user account may be granted other permissions as well, such as the ability to use [[sudo]] without entering the root password.
 +
* ''Option 3.'' [[Users and groups#Group management|Add]] yourself to the {{ic|network}} group and create the following file:
 +
 
 +
{{hc|/etc/polkit-1/rules.d/50-org.freedesktop.NetworkManager.rules|<nowiki>
 +
polkit.addRule(function(action, subject) {
 +
  if (action.id.indexOf("org.freedesktop.NetworkManager.") == 0 && subject.isInGroup("network")) {
 +
    return polkit.Result.YES;
 +
  }
 +
});
 +
</nowiki>}}
 +
 
 +
: All users in the {{ic|network}} group will be able to add and remove networks without a password. This will not work under [[systemd]] if you do not have an active session with ''systemd-logind''.
 +
 
 +
=== Proxy settings ===
 +
 
 +
NetworkManager does not directly handle proxy settings, but if you are using [[GNOME]] or [[KDE]], you could use [http://marin.jb.free.fr/proxydriver/ proxydriver] which handles proxy settings using NetworkManager's information. proxydriver is found in the package {{AUR|proxydriver}}.
 +
 
 +
In order for ''proxydriver'' to be able to change the proxy settings, you would need to execute this command, as part of the GNOME startup process (''System > Preferences > Startup Applications''):
 +
 
 +
xhost +si:localuser:''username''
 +
 
 +
See also [[Proxy settings]].
 +
 
 +
=== Disable NetworkManager when using dbus ===
 +
 
 +
{{Accuracy|Missing sources and when should this be used?}}
 +
 
 +
It might not be obvious, but the service automatically starts through ''dbus''. To completely disable it you can [[mask]] {{ic|NetworkManager.service}} and {{ic|NetworkManager-dispatcher.service}}.
 +
 
 +
=== Checking connectivity ===
 +
 
 +
{{Accuracy|"the desktop manager" might handle captive portals, but this is mostly done through {{aur|capnet-assist}}}}
 +
 
 +
NetworkManager can try to reach a page on Internet when connecting to a network. {{Pkg|networkmanager}} is configured by default in {{ic|/usr/lib/NetworkManager/conf.d/20-connectivity.conf}} to check connectivity to archlinux.org. To use a different webserver or disable connectivity checking create {{ic|/etc/NetworkManager/conf.d/20-connectivity.conf}}, see "connectivity section" in {{man|5|NetworkManager.conf}}.
 +
 
 +
For those behind a captive portal, the desktop manager can automatically open a window asking for credentials.
 +
 
 +
=== DNS caching and split DNS ===
 +
 
 +
{{Expansion|Add unbound ({{AUR|dnssec-trigger}}).}}
 +
 
 +
==== dnsmasq ====
 +
 
 +
NetworkManager has a plugin to enable DNS using [[dnsmasq]]. The advantages of this setup is that DNS lookups will be cached, shortening resolve times, and DNS lookups of VPN hosts will be routed to the relevant VPN's DNS servers (especially useful if you are connected to more than one VPN).
 +
 
 +
Make sure {{Pkg|dnsmasq}} has been installed. Then, create {{ic|/etc/NetworkManager/conf.d/dns.conf}} and add the following to it:
 +
 
 +
{{hc|/etc/NetworkManager/conf.d/dns.conf|2=
 +
[main]
 +
dns=dnsmasq
 
}}
 
}}
  
In case you have nss-myhostname turned off, the line would look like:
+
Now [[restart]] {{ic|NetworkManager.service}}. NetworkManager will automatically start dnsmasq and add {{ic|127.0.0.1}} to {{ic|/etc/resolv.conf}}. The actual DNS servers can be found in {{ic|/run/NetworkManager/resolv.conf}}. You can verify dnsmasq is being used by doing the same DNS lookup twice with {{ic|$ drill example.com}} and verifying the server and query times.
 +
 
 +
===== Custom configuration =====
 +
 
 +
Custom configurations can be created for ''dnsmasq'' by creating configuration files in {{ic|/etc/NetworkManager/dnsmasq.d/}}. For example, to change the size of the DNS cache (which is stored in RAM):
  
{{hc|/etc/hosts|
+
{{hc|/etc/NetworkManager/dnsmasq.d/cache.conf|2=
127.0.0.1 my-laptop localhost
+
cache-size=1000
::1      my-laptop localhost
 
 
}}
 
}}
  
=== Disable current network setup ===
+
{{Tip|Check the configuration file syntax with {{ic|1=dnsmasq --test --conf-file=/dev/null --conf-dir=/etc/NetworkManager/dnsmasq.d}}.}}
You will want to disable your current network setup to be able to properly test NetworkManager
 
  
First, [[Daemon|stop]] the network daemon:
+
See {{man|8|dnsmasq}} for all available options.
  
# systemctl stop net-auto-wireless.service
+
===== IPv6 =====
  
Then, disable currently running network daemons.
+
{{Accuracy|This does not solve the issue because NetworkManager does not add {{ic|::1}} to {{ic|/etc/resolv.conf}}. Unless {{ic|@::1}} is manually passed to drill, it will still fail with {{ic|Error: error sending query: No (valid) nameservers defined in the resolver}}.}}
  
# systemctl disable net-auto-wireless.service
+
Enabling {{ic|dnsmasq}} in NetworkManager may break IPv6-only DNS lookups (i.e. {{ic|drill -6 [hostname]}}) which would otherwise work. In order to resolve this, creating the following file will configure ''dnsmasq'' to also listen to the IPv6 loopback:
  
If you are running netctl, instead use:
+
{{hc|/etc/NetworkManager/dnsmasq.d/ipv6_listen.conf|2=
 +
listen-address=::1
 +
}}
  
# systemctl stop netctl-auto@<interface>.service
+
In addition, {{ic|dnsmasq}} also does not prioritize upstream IPv6 DNS. Unfortunately NetworkManager does not do this ([https://bugs.launchpad.net/ubuntu/+source/network-manager/+bug/936712 Ubuntu Bug]). A workaround would be to disable IPv4 DNS in the NetworkManager config, assuming one exists
# systemctl disable netctl-auto@<interface>.service
 
  
Finally, bring down your NIC's (Network Interface Controllers, i.e. network cards).  For example (using the {{Pkg|iproute2}} package):
+
===== DNSSEC =====
  
# ip link set eth0 down
+
The dnsmasq instance started by NetworkManager by default will not validate [[DNSSEC]] since it is started with the {{ic|--proxy-dnssec}} option. It will trust whatever DNSSEC information it gets from the upstream DNS server.
# ip link set wlan0 down
 
  
{{Note| you must bring your NIC's back up before you continue if you brought them down as shown above. }}
+
For dnsmasq to properly validate DNSSEC, create the following configuration file:
  
=== Enable NetworkManager ===
+
{{hc|/etc/NetworkManager/dnsmasq.d/dnssec.conf|2=
 +
conf-file=/usr/share/dnsmasq/trust-anchors.conf
 +
dnssec
 +
dnssec-check-unsigned
 +
}}
  
Once the NetworkManager daemon is started, it will automatically connect to any available "system connections" that have already been configured. Any "user connections" or unconfigured connections will need {{ic|nmcli}} or an applet to configure and connect.
+
==== systemd-resolved ====
  
You can enable NetworkManager at startup with the following command:
+
NetworkManager can use [[systemd-resolved]] as a DNS resolver and cache. Make sure that ''systemd-resolved'' is properly configured and that {{ic|systemd-resolved.service}} is [[started]] before using it.
  
{{bc|# systemctl enable NetworkManager}}
+
systemd-resolved will be used automatically if {{ic|/etc/resolv.conf}} is a symlink to {{ic|/run/systemd/resolve/stub-resolv.conf}}, {{ic|/run/systemd/resolve/resolv.conf}} or {{ic|/usr/lib/systemd/resolv.conf}}.
  
You can start the NetworkManager daemon immediately with the following command:
+
If {{ic|/etc/resolv.conf}} is not a symlink to any of those files, enable it explicitly by setting the {{ic|1=dns=}} option in {{man|5|NetworkManager.conf}}:
  
{{bc|# systemctl start NetworkManager}}
+
{{hc|/etc/NetworkManager/conf.d/dns.conf|2=
 +
[main]
 +
dns=systemd-resolved
 +
}}
  
=== Enable NetworkManager Wait Online ===
+
==== Other methods ====
If you have services which fail if they are started before the network is up, you have to use {{ic|NetworkManager-wait-online.service}} in addition to the NetworkManager service. This is however hardly ever necessary since most network daemons start up fine, even if the network has not been configured yet.
 
  
You can enable NetworkManager Wait Online at startup with the following command:
+
{{Tip|Set the local DNS server address in {{ic|/etc/resolvconf.conf}} and [[#Use openresolv|configure NetworkManager to use openresolv]].}}
  
{{bc|# systemctl enable NetworkManager-wait-online}}
+
With an already working caching DNS server, the DNS server address can be specified it in NetworkManagers' settings (usually by right-clicking the applet). Setup will depend on the type of front-end used; the process usually involves right-clicking on the applet, editing (or creating) a profile, and then choosing DHCP type as 'Automatic (specify addresses).' The DNS addresses will need to be entered and are usually in this form: {{ic|127.0.0.1, ''DNS-server-one'', ...}}.
  
In some cases the service will still fail to start sucessfully on boot:
+
=== Network services with NetworkManager dispatcher ===
  
  NetworkManager-wait-online.service: main process exited, code=exited, status=1/FAILURE
+
There are quite a few network services that you will not want running until NetworkManager brings up an interface. NetworkManager has the ability to start services when you connect to a network and stop them when you disconnect (e.g. when using [[NFS]], [[SMB]] and [[NTPd]]).
  Failed to start Network Manager Wait Online
 
  Unit NetworkManger-wait-online.service entered failed state
 
  Starting Network.
 
  Reached target Network.
 
  
This is due to the timeout setting in {{ic|/usr/lib/systemd/system/NetworkManager-wait-online.service}} being to short. Change the default timeout from 30 to a higher value.
+
To activate the feature you need to [[enable]] and [[start]] the {{ic|NetworkManager-dispatcher.service}}.
  
=== Set up PolicyKit permissions ===
+
Once the service is active, scripts can be added to the {{ic|/etc/NetworkManager/dispatcher.d}} directory.
  
See [[General Troubleshooting#Session permissions]] for setting up a working session.
+
Scripts must be owned by '''root''', otherwise the dispatcher will not execute them. For added security, set [[group]] ownership to root as well:
  
With a working session, you have several options for granting the necessary privileges to NetworkManager:
+
# chown root:root /etc/NetworkManager/dispatcher.d/''10-script.sh''
  
''Option 1.'' Run a [[PolicyKit]] authentication agent when you log in, such as {{ic|/usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1}} (part of {{Pkg|polkit-gnome}}).  You will be prompted for your password whenever you add or remove a network connection.
+
Make sure the file has correct permissions:
  
''Option 2.'' Add yourself to the {{ic|wheel}} group.  You will not have to enter your password, but your user account may be granted other permissions as well, such as the ability to use [[sudo]] without entering the root password.
+
# chmod 755 /etc/NetworkManager/dispatcher.d/''10-script.sh''
  
''Option 3.'' Add yourself to the {{ic|network}} group and create the following file:
+
The scripts will be run in alphabetical order at connection time, and in reverse alphabetical order at disconnect time. To ensure what order they come up in, it is common to use numerical characters prior to the name of the script (e.g. {{ic|10-portmap}} or {{ic|30-netfs}} (which ensures that the ''portmapper'' is up before NFS mounts are attempted).
{{hc|/etc/polkit-1/rules.d/50-org.freedesktop.NetworkManager.rules|<nowiki>
 
polkit.addRule(function(action, subject) {
 
  if (action.id.indexOf("org.freedesktop.NetworkManager.") == 0 && subject.isInGroup("network")) {
 
    return polkit.Result.YES;
 
  }
 
});</nowiki>}}
 
All users in the {{ic|network}} group will be able to add and remove networks without a password. This will not work under systemd if you do not have an active session with [[Systemd#Using_systemd-logind|systemd-logind]].
 
  
=== Network services with NetworkManager dispatcher===
+
Scripts will receive the following arguments:
 +
* '''Interface name:''' e.g. {{ic|eth0}}
 +
* '''Interface status:''' ''up'' or ''down''
 +
* '''VPN status:''' ''vpn-up'' or ''vpn-down''
  
There are quite a few network services that you will not want running until NetworkManager brings up an interface. Good examples are [[OpenNTPD]] and network filesystem mounts of various types (e.g. '''netfs'''). NetworkManager has the ability to start these services when you connect to a network and stop them when you disconnect. To activate the feature you need to enable/start the NetworkManager-dispatcher service:
+
{{Warning|If you connect to foreign or public networks, be aware of what services you are starting and what servers you expect to be available for them to connect to. You could make a security hole by starting the wrong services while connected to a public network.}}
  
{{bc|# systemctl start NetworkManager-dispatcher}}
+
==== Avoiding the dispatcher timeout ====
{{bc|# systemctl enable NetworkManager-dispatcher}}
 
  
Once the feature is active, scripts can be added to the {{ic|/etc/NetworkManager/dispatcher.d}} directory.  These scripts will need to have executable, user permissions.  For security, it is good practice to make them owned by '''root:root''' and writable only by the owner.
+
If the above is working, then this section is not relevant. However, there is a general problem related to running dispatcher scripts which take longer to be executed. Initially an internal timeout of three seconds only was used. If the called script did not complete in time, it was killed. Later the timeout was extended to about 20 seconds (see the [https://bugzilla.redhat.com/show_bug.cgi?id=982734 Bugtracker] for more information). If the timeout still creates the problem, a work around may be to modify the dispatcher service file {{ic|/usr/lib/systemd/system/NetworkManager-dispatcher.service}} to remain active after exit:  
  
The scripts will be run in alphabetical order at connection time, and in reverse alphabetical order at disconnect time. They receive two arguments: the name of the interface (e.g. ''eth0'') and the status (''up'' or ''down''). To ensure what order they come up in, it is common to use numerical characters prior to the name of the script (e.g. {{ic|10_portmap}} or {{ic|30_netfs}} (which ensures that the portmapper is up before NFS mounts are attempted).
+
{{hc|/etc/systemd/system/NetworkManager-dispatcher.service|2=
 +
.include /usr/lib/systemd/system/NetworkManager-dispatcher.service
 +
[Service]
 +
RemainAfterExit=yes}}
  
{{Warning|For security reason. You should disable write access for group and other. For example use 755 mask.
+
Now start and enable the modified {{ic|NetworkManager-dispatcher}} service.
In other case it can refuse to execute script, with error message "nm-dispatcher.action: Script could not be executed: writable by group or other, or set-UID." in {{ic|/var/log/messages.log}} }}
 
{{Warning|if you connect to foreign or public networks, be aware of what services you are starting and what servers you expect to be available for them to connect to. You could make a security hole by starting the wrong services while connected to a public network.}}
 
  
==== Start OpenNTPD ====
+
{{Warning|Adding the {{ic|RemainAfterExit}} line to it will prevent the dispatcher from closing. Unfortunately, the dispatcher '''has''' to close before it can run your scripts again. With it the dispatcher will not time out but it also will not close, which means that the scripts will only run once per boot. Therefore, do not add the line unless the timeout is definitely causing a problem.}}
  
The following example starts the OpenNTPD daemon when an interface is brought up. Save the file as {{ic|/etc/NetworkManager/dispatcher.d/20_openntpd}} and make it executable.
+
==== Dispatcher examples ====
 
 
{{bc|<nowiki>
 
#!/bin/sh
 
interface=$1 status=$2
 
case $status in
 
  up)
 
    systemctl start openntpd
 
    ;;
 
  down)
 
    if ! nm-tool | awk '/State:/{print $2}' | grep -qs connected; then
 
      systemctl stop openntpd
 
    fi
 
    ;;
 
esac
 
</nowiki>}}
 
  
==== Mount remote folder with sshfs ====
+
===== Mount remote folder with sshfs =====
  
As the script is run in a very restrictive environment, you have to export {{ic|SSH_AUTH_SOCK}} in order to connect to your SSH agent. There are different ways to accomplish this, see [https://bbs.archlinux.org/viewtopic.php?pid=1042030#p1042030 this link] for more information. The example below works with [[gnome-keyring]], and will ask you for the password if not unlocked already. In case NetworkManager connects automatically on login, it is likely gnome-keyring has not yet started and the export will fail (hence the sleep). The {{ic|UUID}} to match can be found with the command {{ic|nmcli con status}} or {{ic|nmcli con list}}.     
+
As the script is run in a very restrictive environment, you have to export {{ic|SSH_AUTH_SOCK}} in order to connect to your SSH agent. There are different ways to accomplish this, see [https://bbs.archlinux.org/viewtopic.php?pid=1042030#p1042030 this message] for more information. The example below works with [[GNOME Keyring]], and will ask you for the password if not unlocked already. In case NetworkManager connects automatically on login, it is likely ''gnome-keyring'' has not yet started and the export will fail (hence the sleep). The {{ic|UUID}} to match can be found with the command {{ic|nmcli con status}} or {{ic|nmcli con list}}.     
  
 
{{bc|<nowiki>
 
{{bc|<nowiki>
Line 241: Line 327:
  
 
interface=$1 status=$2
 
interface=$1 status=$2
if [ "$CONNECTION_UUID" = "<uuid>" ]; then
+
if [ "$CONNECTION_UUID" = "</nowiki>''uuid''<nowiki>" ]; then
 
   case $status in
 
   case $status in
 
     up)
 
     up)
       export SSH_AUTH_SOCK=$(find /tmp -maxdepth 1 -type s -user "$USER" -name 'ssh')
+
       SSH_AUTH_SOCK=$(find /tmp -maxdepth 1 -type s -user "$USER" -name 'ssh')
       su "$USER" -c "sshfs $LOCAL $REMOTE"
+
      export SSH_AUTH_SOCK
 +
       su "$USER" -c "sshfs $REMOTE $LOCAL"
 
       ;;
 
       ;;
 
     down)
 
     down)
Line 254: Line 341:
 
</nowiki>}}
 
</nowiki>}}
  
==== Use dispatcher to connect to a VPN after a network-connection is established ====
+
===== Mounting of SMB shares =====
 +
 
 +
Some [[SMB]] shares are only available on certain networks or locations (e.g. at home). You can use the dispatcher to only mount SMB shares that are present at your current location.
 +
 
 +
The following script will check if we connected to a specific network and mount shares accordingly:
 +
{{hc|/etc/NetworkManager/dispatcher.d/30-mount-smb.sh|<nowiki>
 +
#!/bin/sh
 +
 
 +
# Find the connection UUID with "nmcli con show" in terminal.
 +
# All NetworkManager connection types are supported: wireless, VPN, wired...
 +
if [ "$2" = "up" ]; then
 +
  if [ "$CONNECTION_UUID" = "uuid" ]; then
 +
    mount /your/mount/point &
 +
    # add more shares as needed
 +
  fi
 +
fi
 +
</nowiki>}}
 +
 
 +
The following script will unmount all shares before a disconnect from a specific network:
 +
 
 +
{{hc|/etc/NetworkManager/dispatcher.d/pre-down.d/30-mount-smb.sh|<nowiki>
 +
#!/bin/sh
 +
umount -a -l -t cifs
 +
</nowiki>}}
 +
 
 +
{{Note|
 +
* Make sure this script is located in the {{ic|pre-down.d}} sub-directory as shown above, otherwise it will unmount all shares on any connection state change.
 +
* Since NetworkManager 0.9.8, the ''pre-down'' and ''down'' events are not executed on shutdown or restart, see [https://bugzilla.gnome.org/show_bug.cgi?id&#61;701242 this bug report] for more info.}}
 +
 
 +
===== Mounting of NFS shares =====
 +
 
 +
See [[NFS#Using a NetworkManager dispatcher]].
 +
 
 +
===== Use dispatcher to automatically toggle wireless depending on LAN cable being plugged in =====
 +
 
 +
The idea is to only turn Wi-Fi on when the LAN cable is unplugged (for example when detaching from a laptop dock), and for Wi-Fi to be automatically disabled, once a LAN cable is plugged in again.
 +
 
 +
Create the following dispatcher script ([http://superuser.com/questions/233448/disable-wlan-if-wired-cable-network-is-available Source]), replacing {{ic|1=LAN_interface}} with yours.
 +
{{hc|/etc/NetworkManager/dispatcher.d/wlan_auto_toggle.sh|<nowiki>
 +
#!/bin/sh
 +
 
 +
if [ "$1" = "LAN_interface" ]; then
 +
    case "$2" in
 +
        up)
 +
            nmcli radio wifi off
 +
            ;;
 +
        down)
 +
            nmcli radio wifi on
 +
            ;;
 +
    esac
 +
fi
 +
</nowiki>}}
 +
{{Note|You can get a list of interfaces using [[#nmcli examples|nmcli]]. The ethernet (LAN) interfaces start with {{ic|en}}, e.g. {{ic|1=enp0s5}}}}
 +
 
 +
===== Use dispatcher to connect to a VPN after a network connection is established =====
 +
 
 +
In this example we want to connect automatically to a previously defined VPN connection after connecting to a specific Wi-Fi network. First thing to do is to create the dispatcher script that defines what to do after we are connected to the network.
  
In this example we want to connect automatically to a previously defined VPN connection after connecting to a specific Wi-Fi network. First thing to do is to create the dispatcher script that defines what to do after we are connected to the network.  
+
{{Note|This script will require {{Pkg|wireless_tools}} in order to use {{ic|iwgetid}}.}}
  
:1. Create the dispatcher script:
 
 
{{hc|/etc/NetworkManager/dispatcher.d/vpn-up|<nowiki>
 
{{hc|/etc/NetworkManager/dispatcher.d/vpn-up|<nowiki>
 
#!/bin/sh
 
#!/bin/sh
 
VPN_NAME="name of VPN connection defined in NetworkManager"
 
VPN_NAME="name of VPN connection defined in NetworkManager"
ESSID="wifi network ESSID (not connection name)"
+
ESSID="Wi-Fi network ESSID (not connection name)"
  
 
interface=$1 status=$2
 
interface=$1 status=$2
Line 273: Line 415:
 
   down)
 
   down)
 
     if iwgetid | grep -qs ":\"$ESSID\""; then
 
     if iwgetid | grep -qs ":\"$ESSID\""; then
       if nmcli con status id "$VPN_NAME" | grep -qs activated; then
+
       if nmcli con show --active | grep "$VPN_NAME"; then
 
         nmcli con down id "$VPN_NAME"
 
         nmcli con down id "$VPN_NAME"
 
       fi
 
       fi
Line 280: Line 422:
 
esac
 
esac
 
</nowiki>}}
 
</nowiki>}}
Remember to make it executable with {{ic|chmod +x}} and to make the VPN connection available to all users.
 
  
Trying to connect using this setup will fail and NetworkManager will complain about 'no valid VPN secrets', because of [http://projects.gnome.org/NetworkManager/developers/migrating-to-09/secrets-flags.html the way VPN secrets are stored] which brings us to step 2:
+
If you would like to attempt to automatically connect to VPN for all Wi-Fi networks, you can use the following definition of the ESSID: {{ic|1=ESSID=$(iwgetid -r)}}. Remember to set the script's permissions [[#Network services with NetworkManager dispatcher|accordingly]].
 +
 
 +
Trying to connect with the above script may still fail with {{ic|NetworkManager-dispatcher.service}} complaining about 'no valid VPN secrets', because of [http://developer.gnome.org/NetworkManager/0.9/secrets-flags.html the way VPN secrets are stored]. Fortunately, there are different options to give the above script access to your VPN password.
  
:2. Edit your VPN connection configuration file to make NetworkManager store the secrets by itself rather than inside a keyring [https://bugzilla.redhat.com/show_bug.cgi?id=710552 that will be inaccessible for root]: open up {{ic|/etc/NetworkManager/system-connections/<name of your VPN connection>}} and change the {{ic|password-flags}} and {{ic|secret-flags}} form {{ic|1}} to {{ic|0}}.
+
1: One of them requires editing the VPN connection configuration file to make NetworkManager store the secrets by itself rather than inside a keyring [https://bugzilla.redhat.com/show_bug.cgi?id=710552 that will be inaccessible for root]: open up {{ic|/etc/NetworkManager/system-connections/''name of your VPN connection''}} and change the {{ic|password-flags}} and {{ic|secret-flags}} from {{ic|1}} to {{ic|0}}.
  
{{Note|It may now be necessary to re-open the NetworkManager connection editor and re-enter the VPN passwords/secrets.}}
+
If that alone does not work, you may have to create a {{ic|passwd-file}} in a safe location with the same permissions and ownership as the dispatcher script, containing the following:
 +
{{hc|/path/to/passwd-file|<nowiki>
 +
vpn.secrets.password:YOUR_PASSWORD
 +
</nowiki>}}
 +
 
 +
The script must be changed accordingly, so that it gets the password from the file:
 +
 
 +
{{hc|/etc/NetworkManager/dispatcher.d/vpn-up|<nowiki>
 +
#!/bin/sh
 +
VPN_NAME="name of VPN connection defined in NetworkManager"
 +
ESSID="Wi-Fi network ESSID (not connection name)"
 +
 
 +
interface=$1 status=$2
 +
case $status in
 +
  up|vpn-down)
 +
    if iwgetid | grep -qs ":\"$ESSID\""; then
 +
      nmcli con up id "$VPN_NAME" passwd-file /path/to/passwd-file
 +
    fi
 +
    ;;
 +
  down)
 +
    if iwgetid | grep -qs ":\"$ESSID\""; then
 +
      if nmcli con show --active | grep "$VPN_NAME"; then
 +
        nmcli con down id "$VPN_NAME"
 +
      fi
 +
    fi
 +
    ;;
 +
esac
 +
</nowiki>}}
  
=== Proxy settings ===
+
2: Alternatively, change the {{ic|password-flags}} and put the password directly in the configuration file adding the section {{ic|vpn-secrets}}:
  
NetworkManager does not directly handle proxy settings, but if you are using GNOME, you could use [http://marin.jb.free.fr/proxydriver/ proxydriver] wich handles proxy settings using NetworkManager's informations. You can find the package for {{AUR|proxydriver}} in the [[AUR]].
+
  [vpn]
 +
  ....
 +
  password-flags=0
 +
 
 +
  [vpn-secrets]
 +
  password=''your_password''
  
In order for proxydriver to be able to change the proxy settings, you would need to execute this command, as part of the GNOME startup process (System -> Preferences -> Startup Applications):
+
{{Note|It may now be necessary to re-open the NetworkManager connection editor and save the VPN passwords/secrets again.}}
  
xhost +si:localuser:your_username
+
===== OpenNTPD =====
  
See: [[Proxy settings]]
+
See [[OpenNTPD#Using NetworkManager dispatcher]].
  
 
== Testing ==
 
== Testing ==
  
NetworkManager applets are designed to load upon login so no further configuration should be necessary for most users.  If you have already disabled your previous network settings and disconnected from your network, you can now test if NetworkManager will work. The first step is to [[Daemon|start]] the ''networkmanager'' daemon.
+
NetworkManager applets are designed to load upon login so no further configuration should be necessary for most users.  If you have already disabled your previous network settings and disconnected from your network, you can now test if NetworkManager will work. The first step is to [[start]] {{ic|NetworkManager.service}}.
  
 
Some applets will provide you with a {{ic|.desktop}} file so that the NetworkManager applet can be loaded through the application menu.  If it does not, you are going to either have to discover the command to use or logout and login again to start the applet.  Once the applet is started, it will likely begin polling network connections with for auto-configuration with a DHCP server.
 
Some applets will provide you with a {{ic|.desktop}} file so that the NetworkManager applet can be loaded through the application menu.  If it does not, you are going to either have to discover the command to use or logout and login again to start the applet.  Once the applet is started, it will likely begin polling network connections with for auto-configuration with a DHCP server.
  
To start the GNOME applet in non-xdg-compliant window managers like [[Awesome]]:
+
To start the GNOME applet in non-xdg-compliant window managers like [[awesome]]:
  
 
  nm-applet --sm-disable &
 
  nm-applet --sm-disable &
  
For static IPs you will have to configure NetworkManager to understand them.  The process usually involves right-clicking the applet and selecting something like 'Edit Connections'.
+
For static IP addresses, you will have to configure NetworkManager to understand them.  The process usually involves right-clicking the applet and selecting something like 'Edit Connections'.
 +
 
 +
== Tips and tricks ==
 +
 
 +
=== Encrypted Wi-Fi passwords ===
 +
 
 +
By default, NetworkManager stores passwords in clear text in the connection files at {{ic|/etc/NetworkManager/system-connections/}}. To print the stored passwords, use the following command:
 +
 
 +
# grep -H '^psk=' /etc/NetworkManager/system-connections/*
 +
 
 +
The passwords are accessible to the root user in the filesystem and to users with access to settings via the GUI (e.g. {{ic|nm-applet}}).
 +
 
 +
It is preferable to save the passwords in encrypted form in a keyring instead of clear text. The downside of using a keyring is that the connections have to be set up for each user.
 +
 
 +
====Using Gnome-Keyring====
 +
 
 +
The keyring daemon has to be started and the keyring needs to be unlocked for the following to work.
 +
 
 +
Furthermore, NetworkManager needs to be configured not to store the password for all users. Using GNOME {{ic|nm-applet}}, run {{ic|nm-connection-editor}} from a terminal, select a network connection,  click {{ic|Edit}}, select the {{ic|Wifi-Security}} tab and click on the right icon of password and check {{ic|Store the password only for this user}}.
 +
 
 +
====Using KDE Wallet====
 +
 
 +
Using KDE's {{Pkg|plasma-nm}}, click the applet, click on the top right {{ic|Settings}} icon, click on a network connection, in the {{ic|General settings}} tab, untick {{ic|all users may connect to this network}}. If the option is ticked, the passwords will still be stored in clear text, even if a keyring daemon is running.
 +
 
 +
If the option was selected previously and you un-tick it, you may have to use the {{ic|reset}} option first to make the password disappear from the file. Alternatively, delete the connection first and set it up again.
 +
 
 +
=== Sharing internet connection over Wi-Fi ===
 +
 
 +
You can share your internet connection (e.g. 3G or wired) with a few clicks. You will need a supported Wi-Fi card (Cards based on Atheros AR9xx or at least AR5xx are probably best choice). Please note that a [[firewall]] may interfere with internet sharing.
 +
 
 +
* [[Install]] the {{Pkg|dnsmasq}} package to be able to actually share the connection.
 +
 
 +
Create the shared connection:
 +
 
 +
* Click on applet and choose ''Create new wireless network''.
 +
* Follow wizard (if using WEP, be sure to use 5 or 13 character long password, different lengths will fail).
 +
** Choose either [[Fedora:Features/RealHotspot|Hotspot]] or Ad-hoc as Wi-Fi mode.
 +
 
 +
The connection will be saved and remain stored for the next time you need it.
 +
 
 +
{{Note|Android does not support connecting to Ad-hoc networks. To share a connection with Android use infrastructure mode (i.e. set Wi-Fi mode to "Hotspot").}}
 +
 
 +
=== Sharing internet connection over Ethernet ===
 +
 
 +
Scenario: your device has internet connection over wi-fi and you want to share the internet connection to other devices over ethernet.
 +
 
 +
Requirements:
 +
* [[Install]] the {{Pkg|dnsmasq}} package to be able to actually share the connection.
 +
* Your internet connected device and the other devices are connected over a suitable ethernet cable (this usually means a cross over cable or a switch in between).
 +
* Internet sharing is not blocked by a [[firewall]].
 +
 
 +
Steps:
 +
* Run {{ic|nm-connection-editor}} from terminal.
 +
* Add a new ethernet connection.
 +
* Give it some sensible name. For example "Shared Internet"
 +
* Go to "IPv4 Settings".
 +
* For "Method:" select "Shared to other computers".
 +
* Save
 +
 
 +
Now you should have a new option "Shared Internet" under the Wired connections in NetworkManager.
 +
 
 +
=== Checking if networking is up inside a cron job or script ===
 +
 
 +
Some ''cron'' jobs require networking to be up to succeed. You may wish to avoid running these jobs when the network is down. To accomplish this, add an '''if''' test for networking that queries NetworkManager's ''nm-tool'' and checks the state of networking. The test shown here succeeds if any interface is up, and fails if they are all down. This is convenient for laptops that might be hardwired, might be on wireless, or might be off the network.
 +
 
 +
{{bc|<nowiki>
 +
if [ $(nm-tool|grep State|cut -f2 -d' ') == "connected" ]; then
 +
    #Whatever you want to do if the network is online
 +
else
 +
    #Whatever you want to do if the network is offline - note, this and the else above are optional
 +
fi
 +
</nowiki>}}
 +
 
 +
This useful for a {{ic|cron.hourly}} script that runs ''fpupdate'' for the F-Prot virus scanner signature update, as an example. Another way it might be useful, with a little modification, is to differentiate between networks using various parts of the output from ''nm-tool''; for example, since the active wireless network is denoted with an asterisk, you could grep for the network name and then grep for a literal asterisk.
 +
 
 +
=== Connect to network with secret on boot ===
 +
 
 +
By default, NetworkManager will not connect to networks requiring a secret automatically on boot. This is because it locks such connections to the user who makes it by default, only connecting after they have logged in. To change this, do the following:
 +
 
 +
# Right click on the {{ic|nm-applet}} icon in your panel and select Edit Connections and open the Wireless tab
 +
# Select the connection you want to work with and click the Edit button
 +
# Check the boxes “Connect Automatically” and “Available to all users”
 +
Log out and log back in to complete.
 +
 
 +
=== Automatically unlock keyring after login ===
 +
 
 +
NetworkManager requires access to the login keyring to connect to networks requiring a secret. Under most circumstances, this keyring is unlocked automatically at login, but if it is not, and NetworkManager is not connecting on login, you can try the following.
 +
 
 +
==== GNOME ====
 +
 
 +
{{Note|The following method is dated and known not to work on at least one machine!}}
 +
* In {{ic|/etc/pam.d/gdm}} (or your corresponding daemon in {{ic|/etc/pam.d}}), add these lines at the end of the "auth" and "session" blocks if they do not exist already:
 +
  auth            optional        pam_gnome_keyring.so
 +
  session        optional        pam_gnome_keyring.so  auto_start
 +
 
 +
* In {{ic|/etc/pam.d/passwd}}, use this line for the 'password' block:
 +
  password    optional    pam_gnome_keyring.so
 +
 
 +
:Next time you log in, you should be asked if you want the password to be unlocked automatically on login.
 +
 
 +
==== SLiM login manager ====
 +
 
 +
See [[SLiM#Gnome Keyring]].
 +
 
 +
==== Troubleshooting ====
 +
 
 +
While you may type both values at connection time, {{Pkg|plasma-nm}} 0.9.3.2-1 and above are capable of retrieving OpenConnect username and password directly from KWallet.
 +
 
 +
Open "KDE Wallet Manager" and look up your OpenConnect VPN connection under "Network Management|Maps". Click "Show values" and
 +
enter your credentials in key "VpnSecrets" in this form (replace ''username'' and ''password'' accordingly):
 +
 
 +
form:main:username%SEP%''username''%SEP%form:main:password%SEP%''password''
 +
 
 +
Next time you connect, username and password should appear in the "VPN secrets" dialog box.
 +
 
 +
=== Ignore specific devices ===
 +
 
 +
Sometimes it may be desired that NetworkManager ignores specific devices and does not try to configure addresses and routes for them. You can quickly and easily ignore devices by MAC or interface-name by using the following in {{ic|/etc/NetworkManager/conf.d/unmanaged.conf}}:
 +
 
 +
[keyfile]
 +
unmanaged-devices=mac:00:22:68:1c:59:b1;mac:00:1E:65:30:D1:C4;interface-name:eth0
 +
 
 +
After you have put this in, [[Daemon|restart]] NetworkManager, and you should be able to configure interfaces without NetworkManager altering what you have set.
 +
 
 +
=== Configuring MAC address randomization ===
 +
 
 +
{{Note|1=Disabling MAC address randomization may be needed to get (stable) link connection [https://bbs.archlinux.org/viewtopic.php?id=220101] and/or networks that restrict devices based on their MAC Address or have a limit network capacity.}}
 +
 
 +
MAC randomization can be used for increased privacy by not disclosing your real MAC address to the network.
 +
 
 +
NetworkManager supports two types MAC Address Randomization: randomization during scanning, and for network connections. Both modes can be configured by modifying {{ic|/etc/NetworkManager/NetworkManager.conf}} or by creating a separate configuration file in {{ic|/etc/NetworkManager/conf.d/}} which is recommended since the aforementioned config file may be overwritten by NetworkManager.
 +
 
 +
Randomization during Wi-Fi scanning is enabled by default, but it may be disabled by adding the following lines to {{ic|/etc/NetworkManager/NetworkManager.conf}} or a dedicated configuration file under {{ic|/etc/NetworkManager/conf.d}}:
 +
 
 +
[device]
 +
wifi.scan-rand-mac-address=no
 +
 
 +
MAC randomization for network connections can be set to different modes for both wireless and ethernet interfaces. See [https://blogs.gnome.org/thaller/2016/08/26/mac-address-spoofing-in-networkmanager-1-4-0/ the Gnome blog post] for more details on the different modes.
 +
 
 +
In terms of MAC randomization the most important modes are stable and random. Stable generates a random MAC address when you connect to a new network and associates the two permanently. This means that you will use the same MAC address every time you connect to that network. In contrast, random will generate a new MAC address every time you connect to a network, new or previously known. You can configure the MAC randomization by adding the desired configuration under {{ic|/etc/NetworkManager/conf.d}}.
 +
 
 +
[device-mac-randomization]
 +
# "yes" is already the default for scanning
 +
wifi.scan-rand-mac-address=yes
 +
 +
[connection-mac-randomization]
 +
# Randomize MAC for every ethernet connection
 +
ethernet.cloned-mac-address=random
 +
# Generate a random MAC for each WiFi and associate the two permanently.
 +
wifi.cloned-mac-address=stable
 +
 
 +
See the following [https://blogs.gnome.org/thaller/2016/08/26/mac-address-spoofing-in-networkmanager-1-4-0/ GNOME blogpost] for more details.
 +
 
 +
=== Enable IPv6 Privacy Extensions ===
 +
 
 +
See [[IPv6#NetworkManager]].
 +
 
 +
=== Working with wired connections ===
 +
 
 +
By default, NetworkManager generates a connection profile for each wired ethernet connection it finds. At the point when generating the connection, it does not know whether there will be more ethernet adapters available. Hence, it calls the first wired connection "Wired connection 1". You can avoid generating this connection, by configuring {{ic|no-auto-default}} (see {{man|5|NetworkManager.conf}}), or by simply deleting it. Then NetworkManager will remember not to generate a connection for this interface again.
 +
 
 +
You can also edit the connection (and persist it to disk) or delete it. NetworkManager will not re-generate a new connection. Then you can change the name to whatever you want. You can use something like nm-connection-editor for this task.
 +
 
 +
=== resolv.conf ===
 +
 
 +
''NetworkManager'' overwrites [[resolv.conf]] by default.
 +
 
 +
This can be stopped by adding {{ic|1=dns=none}} to the {{ic|[main]}} section in {{ic|/etc/NetworkManager/NetworkManager.conf}}.
 +
 
 +
After that {{ic|/etc/resolv.conf}} might be a broken symlink that you will need to remove. Then, just create a new {{ic|/etc/resolv.conf}} file.
 +
 
 +
''NetworkManager'' also offers hooks via so called dispatcher scripts that can be used to alter the {{ic|/etc/resolv.conf}} after network changes. See [[#Network services with NetworkManager dispatcher]] and {{man|8|NetworkManager}} for more information.
 +
 
 +
==== Use openresolv ====
 +
 
 +
To configure NetworkManager to use [[openresolv]], set the {{ic|rc-manager}} option to {{ic|resolvconf}} with a configuration file in {{ic|/etc/NetworkManager/conf.d/}}:
 +
 
 +
{{hc|/etc/NetworkManager/conf.d/rc-manager.conf|2=
 +
[main]
 +
rc-manager=resolvconf
 +
}}
 +
 
 +
Others options are available in {{man|5|NetworkManager.conf}}.
 +
 
 +
=== Using iwd as the Wi-Fi backend ===
 +
 
 +
To enable the experimental [[iwd]] backend create the following configuration file:
 +
 
 +
{{hc|/etc/NetworkManager/conf.d/wifi_backend.conf|2=
 +
[device]
 +
wifi.backend=iwd
 +
}}
  
 
== Troubleshooting ==
 
== Troubleshooting ==
  
Some fixes to common problems.
+
=== No prompt for password of secured Wi-Fi networks ===
  
=== Using nm-applet, wifi networks don't prompt for password and just disconnect ===
+
When trying to connect to a secured Wi-Fi network, no prompt for a password is shown and no connection is established. This happens when no keyring package is installed. An easy solution is to install {{Pkg|gnome-keyring}}. If you want the passwords to be stored in encrypted form, follow [[GNOME Keyring]] to set up the ''gnome-keyring-daemon''.
  
This happens when no keyring package is installed. An easy solution is to install {{Pkg|gnome-keyring}}.
+
=== No traffic via PPTP tunnel ===
  
=== No traffic via PPTP tunnel ===
+
PPTP connection logins successfully; you see a ppp0 interface with the correct VPN IP address, but you cannot even ping the remote IP address. It is due to lack of MPPE (Microsoft Point-to-Point Encryption) support in stock Arch pppd. It is recommended to first try with the stock Arch {{Pkg|ppp}} as it may work as intended.
  
PPTP connection logins successfully, you see ppp0 interface with correct VPN IP, but you cannot even ping remote IP. It is due to lack of MPPE (Microsoft Point-to-Point Encryption) support in stock Arch pppd. It is recommended to first try with the stock Arch {{Pkg|ppp}} as it may work as intended.
+
To solve the problem it should be sufficient to install the {{AUR|ppp-mppe}}{{Broken package link|{{aur-mirror|ppp-mppe}}}} package.
  
To solve the problem it should be sufficient to install {{AUR|ppp-mppe}} from the [[AUR]].
+
See also [[WPA2 Enterprise#MS-CHAPv2]].
  
 
=== Network management disabled ===
 
=== Network management disabled ===
  
Sometimes when NetworkManager shuts down but the pid (state) file does not get removed and you will get a 'Network management disabled' message. If this happens, you'll have to remove it manually:
+
When NetworkManager shuts down but the pid (state) file is not removed, you will see a {{ic|Network management disabled}} message. If this happens, remove the file manually:
  
 
  # rm /var/lib/NetworkManager/NetworkManager.state
 
  # rm /var/lib/NetworkManager/NetworkManager.state
  
If this happens upon reboot, you can add an action to your {{ic|/etc/rc.local}} to have it removed upon bootup:
+
=== Problems with internal DHCP client ===
  
{{bc|<nowiki>nmpid=/var/lib/NetworkManager/NetworkManager.state
+
If you have problems with getting an IP address using the internal DHCP client, consider {{Pkg|dhclient}} as DHCP client.
[ -f $nmpid ] && rm $nmpid</nowiki>}}
 
  
=== NetworkManager prevents DHCPCD from using resolv.conf.head and resolv.conf.tail ===
+
After installation, update the NetworkManager config file:
  
Sometimes it is problematic to add static items to {{ic|resolv.conf}} when it is constantly rewritten by NetworkManager and {{ic|dhcpcd}}. A simple solution is using the following script:
+
{{hc|1=/etc/NetworkManager/conf.d/dhcp-client.conf|2=
{{bc|<nowiki>
+
[main]
#!/bin/bash
+
dhcp=dhclient
#
+
}}
# /etc/NetworkManager/dispatcher.d/99-resolv.conf-head_and_tail
 
# Include /etc/resolv.conf.head and /etc/resolv.conf.tail to /etc/resolv.conf
 
#
 
# scripts in the /etc/NetworkManager/dispatcher.d/ directory
 
# are called alphabetically and are passed two parameters:
 
# $1 is the interface name, and $2 is “up” or “down” as the
 
# case may be.
 
 
 
resolvconf='/etc/resolv.conf';
 
cat "$resolvconf"{.head,,.tail} 2>/dev/null > "$resolvconf".tmp
 
mv -f "$resolvconf".tmp "$resolvconf"
 
</nowiki>}}
 
 
 
This script is also available in the [https://aur.archlinux.org/packages/networkmanager-dispatch-resolv AUR] for convenience
 
  
=== Preserving changes to resolv.conf ===
+
This workaround might solve problems in big wireless networks like eduroam.
  
See [[Resolv.conf]].
+
=== DHCP problems with dhclient ===
  
=== DHCP problems ===
+
If you have problems with getting an IP address via DHCP, try to add the following to your {{ic|/etc/dhclient.conf}}:
  
If you have problems with getting an IP via DHCP, try to add the following to your {{ic|/etc/dhclient.conf}}:
 
 
   interface "eth0" {
 
   interface "eth0" {
 
     send dhcp-client-identifier 01:aa:bb:cc:dd:ee:ff;
 
     send dhcp-client-identifier 01:aa:bb:cc:dd:ee:ff;
 
   }
 
   }
Where {{ic|aa:bb:cc:dd:ee:ff}} is the MAC address of this NIC. The MAC address can be found using the {{ic|ip link show eth0}} command from the {{Pkg|iproute2}} package.
 
  
For some (incompliant) routers, you will not be able to connect properly unless you comment the line
+
Where {{ic|aa:bb:cc:dd:ee:ff}} is the MAC address of this NIC. The MAC address can be found using the {{ic|ip link show ''interface''}} command from the {{Pkg|iproute2}} package.
require dhcp_server_identifier
 
in {{ic|/etc/dhcpcd.conf}} (note that this file is distinct from {{ic|dhcpd.conf}}). This should not cause issues unless you have multiple DHCP servers on your network (not typical); see [http://technet.microsoft.com/en-us/library/cc977442.aspx this page] for more information.
 
  
=== Hostname problems ===
 
Add the following line to /etc/NetworkManager/NetworkManager.conf:
 
dhcp=dhcpcd
 
then restart.
 
systemctl restart NetworkManager
 
source https://bbs.archlinux.org/viewtopic.php?id=152376
 
 
=== Missing default route ===
 
=== Missing default route ===
  
Line 384: Line 725:
 
=== 3G modem not detected ===
 
=== 3G modem not detected ===
  
If NetworkManager (from v0.7.999) does not detect your 3G modem, but you still can connect using [[wvdial]], try installing
+
See [[USB 3G Modem#Network Manager]].
{{Pkg|modemmanager}} and restart NetworkManager daemon with {{ic|systemctl restart NetworkManager}}. It may also be necessary to replug or restart your modem. This utility provides support for hardware not in NetworkManager's default database.
 
  
 
=== Switching off WLAN on laptops ===
 
=== Switching off WLAN on laptops ===
  
Sometimes NetworkManager will not work when you disable your Wi-Fi adapter with a switch on your laptop and try to enable it again afterwards. This is often a problem with {{ic|rfkill}}. Install {{Pkg|rfkill}} from the [[official repositories]] and use  
+
Sometimes NetworkManager will not work when you disable your Wi-Fi adapter with a switch on your laptop and try to enable it again afterwards. This is often a problem with ''rfkill''. To check if the driver notifies ''rfkill'' about the wireless adapter's status, use:
  
 
  $ watch -n1 rfkill list all
 
  $ watch -n1 rfkill list all
  
to check if the driver notifies {{ic|rfkill}} about the wireless adapter's status.
 
 
If one identifier stays blocked after you switch on the adapter you could try to manually unblock it with (where X is the number of the identifier provided by the above output):
 
If one identifier stays blocked after you switch on the adapter you could try to manually unblock it with (where X is the number of the identifier provided by the above output):
  
 
  # rfkill event unblock X
 
  # rfkill event unblock X
  
=== Static IP settings revert to DHCP ===
+
=== Static IP address settings revert to DHCP ===
  
Due to an unresolved bug, when changing default connections to static IP, {{ic|nm-applet}} may not properly store the configuration change, and will revert to automatic DHCP.
+
Due to an unresolved bug, when changing default connections to a static IP address, {{ic|nm-applet}} may not properly store the configuration change, and will revert to automatic DHCP.
  
To work around this issue you have to edit the default connection (e.g. "Auto eth0") in {{ic|nm-applet}}, change the connection name (e.g. "my eth0"), uncheck the "Available to all users" checkbox, change your static IP settings as desired, and click '''Apply'''.  This will save a new connection with the given name.
+
To work around this issue you have to edit the default connection (e.g. "Auto eth0") in {{ic|nm-applet}}, change the connection name (e.g. "my eth0"), uncheck the "Available to all users" checkbox, change your static IP address settings as desired, and click '''Apply'''.  This will save a new connection with the given name.
  
Next, you will want to make the default connection not connect automatically.  To do so, run {{ic|nm-connection-editor}} (''not'' as root). In the connection editor, edit the default connection (eg "Auto eth0") and uncheck "Connect automatically".  Click '''Apply''' and close the connection editor.
+
Next, you will want to make the default connection not connect automatically.  To do so, run {{ic|nm-connection-editor}} ('''not''' as root). In the connection editor, edit the default connection (e.g. "Auto eth0") and uncheck "Connect automatically".  Click '''Apply''' and close the connection editor.
  
 
=== Cannot edit connections as normal user ===
 
=== Cannot edit connections as normal user ===
  
See [[#Set_up_PolicyKit_permissions]].
+
See [[#Set up PolicyKit permissions]].
  
 
=== Forget hidden wireless network ===
 
=== Forget hidden wireless network ===
  
Since hidden network are not displayed in the selection list of the Wireless view, they cannot be forgotten (removed) with the GUI. You can delete one with the following command:
+
Since hidden networks are not displayed in the selection list of the Wireless view, they cannot be forgotten (removed) with the GUI. You can delete one with the following command:
  
  # rm /etc/NetworkManager/system-connections/[SSID]
+
  # rm /etc/NetworkManager/system-connections/''SSID''
  
 
This works for any other connection.
 
This works for any other connection.
  
=== VPN not working in Gnome ===
+
=== VPN not working in GNOME ===
  
When setting up openconnect or vpnc connections in NetworkManager while using Gnome, you'll sometimes never see the dialog box pop up and the following error appears in /var/log/errors.log:
+
When setting up OpenConnect or vpnc connections in NetworkManager while using GNOME, you will sometimes never see the dialog box pop up and the following error appears in {{ic|/var/log/errors.log}}:
  
 
  localhost NetworkManager[399]: <error> [1361719690.10506] [nm-vpn-connection.c:1405] get_secrets_cb(): Failed to request VPN secrets #3: (6) No agents were available for this request.
 
  localhost NetworkManager[399]: <error> [1361719690.10506] [nm-vpn-connection.c:1405] get_secrets_cb(): Failed to request VPN secrets #3: (6) No agents were available for this request.
  
This is caused by the Gnome NM Applet expecting dialog scripts to be at /usr/lib/gnome-shell, when NetworkManager's packages put them in /usr/lib/networkmanager.
+
This is caused by the GNOME NM Applet expecting dialog scripts to be at {{ic|/usr/lib/gnome-shell}}, when NetworkManager's packages put them in {{ic|/usr/lib/networkmanager}}.
 
As a "temporary" fix (this bug has been around for a while now), make the following symlink(s):
 
As a "temporary" fix (this bug has been around for a while now), make the following symlink(s):
  
# For OpenConnect
+
* For OpenConnect: {{ic|ln -s /usr/lib/networkmanager/nm-openconnect-auth-dialog /usr/lib/gnome-shell/}}
ln -s /usr/lib/networkmanager/nm-openconnect-auth-dialog /usr/lib/gnome-shell/  
+
* For VPNC (i.e. Cisco VPN): {{ic|ln -s /usr/lib/networkmanager/nm-vpnc-auth-dialog /usr/lib/gnome-shell/}}
 
 
# For VPNC (i.e. Cisco VPN)
 
ln -s /usr/lib/networkmanager/nm-vpnc-auth-dialog /usr/lib/gnome-shell/
 
  
 
This may need to be done for any other NM VPN plugins as well, but these are the two most common.
 
This may need to be done for any other NM VPN plugins as well, but these are the two most common.
  
== Tips and tricks ==
+
=== Unable to connect to visible European wireless networks ===
  
=== Sharing internet connection over Wi-Fi ===
+
WLAN chips are shipped with a default [[Wireless network configuration#Respecting the regulatory domain|regulatory domain]]. If your access point does not operate within these limitations, you will not be able to connect to the network. Fixing this is easy:
  
You can share your internet connection (e.g.: 3G or wired) with a few clicks using nm. You will need a supported Wi-Fi card (Cards based on Atheros AR9xx or at least AR5xx are probably best choice)
+
# [[Install]] {{Pkg|crda}}
 
+
# Uncomment the correct Country Code in {{ic|/etc/conf.d/wireless-regdom}}
==== Ad-hoc ====
+
# Reboot the system, because the setting is only read on boot
 
 
* pacman -S {{pkg|dnsmasq}}
 
* custom dnsmasq.conf may interfere with nm (not sure about this, but i think so)
 
* Click on nm-applet -> Create new wireless network
 
* Follow wizard (if using WEP be sure to use 5 or 13 character long password, different lengths will fail)
 
* Settings will remain stored for the next time you need it
 
 
 
==== Real AP ====
 
 
 
Support of infrastructure mode (which is needed by Android phones as they do not intentionally support ad-hoc) is not currently supported by NetworkManager, but is in active development...
 
 
 
See: http://fedoraproject.org/wiki/Features/RealHotspot
 
 
 
=== Checking if networking is up inside a cron job or script ===
 
 
 
Some cron jobs require networking to be up to succeed. You may wish to avoid running these jobs when the network is down. To accomplish this, add an '''if''' test for networking that queries NetworkManager's {{ic|nm-tool}} and checks the state of networking. The test shown here succeeds if any interface is up, and fails if they are all down. This is convenient for laptops that might be hardwired, might be on wireless, or might be off the network.
 
if [ `nm-tool|grep State|cut -f2 -d' '` == "connected" ]; then
 
        #Whatever you want to do if the network is online
 
else
 
        #Whatever you want to do if the network is offline - note, this and the else above are optional
 
fi
 
 
 
This useful for a {{ic|cron.hourly}} script that runs {{ic|fpupdate}} for the F-Prot virus scanner signature update, as an example. Another way it might be useful, with a little modification, is to differentiate between networks using various parts of the output from {{ic|nm-tool}}; for example, since the active wireless network is denoted with an asterisk, you could grep for the network name and then grep for a literal asterisk.
 
 
 
=== Automatically unlock keyring after login ===
 
 
 
==== GNOME ====
 
  
# Right click on the {{ic|nm-applet}} icon in your panel and select Edit Connections and open the Wireless tab
+
=== Automatic connect to VPN on boot is not working  ===
# Select the connection you want to work with and click the Edit button
 
# Check the boxes “Connect Automatically” and “Available to all users”
 
Log out and log back in to complete.
 
  
{{Note|The following method is dated and known not to work on at least one machine!}}
+
The problem occurs when the system (i.e. NetworkManager running as the root user) tries to establish a VPN connection, but the password is not accessible because it is stored in the Gnome keyring of a particular user.  
* In {{ic|/etc/pam.d/gdm}} (or your corresponding daemon in {{ic|/etc/pam.d}}), add these lines at the end of the "auth" and "session" blocks if they do not exist already:
 
  auth            optional        pam_gnome_keyring.so
 
  session        optional        pam_gnome_keyring.so  auto_start
 
  
* In {{ic|/etc/pam.d/passwd}}, use this line for the 'password' block:
+
A solution is to keep the password to your VPN in plaintext, as described in step (2.) of [[#Use dispatcher to connect to a VPN after a network connection is established]].  
  password    optional    pam_gnome_keyring.so
 
  
:Next time you log in, you should be asked if you want the password to be unlocked automatically on login.
+
You do not need to use the dispatcher described in step (1.) to auto-connect anymore, if you use the new "auto-connect VPN" option from the {{ic|nm-applet}} GUI.
  
==== KDE ====
+
=== Systemd Bottleneck ===
{{Note|See http://live.gnome.org/GnomeKeyring/Pam for reference, and if you are using KDE with KDM, you can use {{AUR|pam-keyring-tool}} from the [[AUR]].}}
 
  
Put a script like the following in {{ic|~/.kde4/Autostart}}:
+
Over time the log files ({{ic|/var/log/journal}}) can become very large. This can have a big impact on boot performance when using NetworkManager, see: [[Systemd#Boot time increasing over time]].
  #!/bin/sh
 
  echo PASSWORD | /usr/bin/pam-keyring-tool --unlock --keyring=default -s
 
Similar should work with Openbox, LXDE, etc.
 
  
==== SLiM login manager ====
+
=== Regular network disconnects, latency and lost packets (WiFi) ===
See [[Slim#SLiM and Gnome Keyring]].
 
  
=== Ignore specific devices ===
+
NetworkManager does a scan every 2 minutes.
  
Sometimes it may be desired that NetworkManager ignores specific devices and does not try to configure addresses and routes for them.You can quickly and easily ignore devices by MAC by using the following in {{ic|/etc/NetworkManager/NetworkManager.conf}} :
+
Some WiFi drivers have issues when scanning for base stations whilst connected/associated. Symptoms include VPN disconnects/reconnects and lost packets, web pages failing to load and then refresh fine.
[keyfile]
 
unmanaged-devices=mac:00:22:68:1c:59:b1;mac:00:1E:65:30:D1:C4
 
After you have put this in, [[Daemon|restart]] NetworkManager, and you should be able to configure interfaces without NetworkManager altering what you have set.
 
  
=== Connect faster ===
+
Running {{ic|journalctl -f}} will indicate that this is taking place, messages like the following will be contained in the logs at regular intervals.
  
==== Disabling IPv6 ====
+
NetworkManager[410]: <info>  (wlp3s0): roamed from BSSID 00:14:48:11:20:CF (my-wifi-name) to (none) ((none))
  
Slow connection or reconnection to the network may be due to superfluous IPv6 queries in NetworkManager. If there is no IPv6 support on the local network, connecting to a network may take longer than normal while NetworkManager tries to establish an IPv6 connection that eventually times out. The solution is to disable IPv6 within NetworkManager which will make network connection faster. This has to be done once for every network you connect to.
+
There is a patched version of NetworkManager which should prevent this type of scanning: {{AUR|networkmanager-noscan}}.
  
* Right-click on the network status icon.
+
Alternatively, if roaming is not important, the periodic scanning behavior can be disabled by locking the BSSID of the access point in the WiFi connection profile.
* Click on "Edit Connections".
 
* Go to the "Wired" or "Wireless" tab, as appropriate.
 
* Select the name of the network.
 
* Click on "Edit".
 
* Go to the "IPv6 Settings" tab.
 
* In the "Method" dropdown, choose "Ignore/Disabled".
 
* Click on "Save".
 
  
==== Speed up DHCP by disabling ARP probing in DHCPCD ====
+
=== Unable to turn on wi-fi with Lenovo laptop (IdeaPad, Legion, etc.) ===
  
{{ic|dhcpcd}} contains an implementation of a recommendation of the DHCP standard ([http://www.ietf.org/rfc/rfc2131.txt RFC2131] section 2.2) to check via ARP if the assigned IP address is really not taken. This seems mostly useless in home networks, so you can save about 5 seconds on every connect by adding the following line to {{ic|/etc/dhcpcd.conf}}:
+
There is an issue with the {{ic|ideapad_laptop}} module on some Lenovo models due to the wi-fi driver incorrectly reporting a soft block. The card can still be manipulated with {{ic|netctl}}, but managers like NetworkManager break. You can verify that this is the problem by checking the output of {{ic|rfkill list}} after toggling your hardware switch and seeing that the soft block persists.
  
noarp
+
{{Accuracy|Try to use {{ic|rfkill.default_state}} and {{ic|rfkill.master_switch_mode}} (see [https://github.com/torvalds/linux/blob/master/Documentation/admin-guide/kernel-parameters.txt kernel-parameters.txt]) to fix the rfkill problem.}}
  
This is equivalent to passing {{ic|--noarp}} to {{ic|dhcpcd}}, and disables the described ARP probing, speeding up connections to networks with DHCP.
+
[[modprobe|Unloading]] the {{ic|ideapad_laptop}} module should fix this. ('''warning''': this may disable the laptop keyboard and touchpad also!).
  
==== Use OpenDNS servers ====
+
=== Turn off hostname sending ===
  
Create {{ic|/etc/resolv.conf.opendns}} with the nameservers:
+
NetworkManager by default sends the hostname to the DHCP server. Hostname sending can only be disabled per connection not globally ([https://bugzilla.gnome.org/show_bug.cgi?id=768076 GNOME Bug 768076]).
  
nameserver 208.67.222.222
+
To disable sending your hostname to the DHCP server for a specific connection, add the following to your network connection file:
nameserver 208.67.220.220
 
  
or use Google DNS servers, because people have been getting ads via the OpenDNS servers lately
+
{{hc|/etc/NetworkManager/system-connections/''your_connection_file''|2=
 +
...
 +
[ipv4]
 +
dhcp-send-hostname=false
 +
...
 +
[ipv6]
 +
dhcp-send-hostname=false
 +
...
 +
}}
  
nameserver 8.8.8.8
+
=== nm-applet disappears in i3wm ===
nameserver 8.8.4.4
 
  
And have the dispatcher replace the discovered DHCP servers with the OpenDNS ones:
+
If you use the {{ic|xfce4-notifyd.service}} for notifications you must [[edit]] the unit and add the following:
  
{{hc|/etc/NetworkManager/dispatcher.d/dns-servers-opendns|<nowiki>
+
{{hc|/etc/systemd/user/xfce4-notifyd.service.d/display_env.conf|2=
#!/bin/bash
+
[Service]
# Use OpenDNS servers over DHCP discovered servers
+
Environment="DISPLAY=:0.0"
 +
}}
  
cp -f /etc/resolv.conf.opendns /etc/resolv.conf</nowiki>}}
+
After reloading the daemons [[restart]] {{ic|xfce4-notifyd.service}}. Exit i3 and start it back up again and the applet should show on the tray.
  
Make the script executable:
+
== See also ==
  
# chmod +x /etc/NetworkManager/dispatcher.d/dns-servers-opendns
+
* [http://blogs.gnome.org/dcbw/2015/02/16/networkmanager-for-administrators-part-1/ NetworkManager for Administrators Part 1]
 +
* [[Wikipedia:NetworkManager]]

Latest revision as of 16:06, 13 August 2018

NetworkManager is a program for providing detection and configuration for systems to automatically connect to network. NetworkManager's functionality can be useful for both wireless and wired networks. For wireless networks, NetworkManager prefers known wireless networks and has the ability to switch to the most reliable network. NetworkManager-aware applications can switch from online and offline mode. NetworkManager also prefers wired connections over wireless ones, has support for modem connections and certain types of VPN. NetworkManager was originally developed by Red Hat and now is hosted by the GNOME project.

Warning: By default, Wi-Fi passwords are stored in clear text, see #Encrypted Wi-Fi passwords.

Contents

Installation

NetworkManager can be installed with the package networkmanager, which contains a daemon, a command line interface (nmcli) and a curses‐based interface (nmtui). It has functionality for basic DHCP support. For full featured DHCP and if you require IPv6 support, dhclient integrates it. After installation, you should enable the daemon.

Additional interfaces:

Note: You must ensure that no other service that wants to configure the network is running; in fact, multiple networking services will conflict. You can find a list of the currently running services with systemctl --type=service and then stop them. See #Configuration to enable the NetworkManager service.

Mobile broadband support

Install modemmanager, mobile-broadband-provider-info and usb_modeswitch packages for mobile broadband connection support. See USB 3G Modem#Network Manager for details.

PPPoE / DSL support

Install rp-pppoe package for PPPoE / DSL connection support. To actually add PPPoE connection, use nm-connection-editor and add new DSL/PPPoE connection.

VPN support

NetworkManager VPN support is based on a plug-in system. If you need VPN support via NetworkManager, you have to install one of the following packages:

Warning: VPN support is unstable, check the daemon processes options set via the GUI correctly and double-check with each package release.[1]

Usage

NetworkManager comes with nmcli(1) and nmtui(1).

nmcli examples

List nearby wifi networks:

$ nmcli device wifi list

Connect to a wifi network:

$ nmcli device wifi connect SSID password password

Connect to a hidden network:

$ nmcli device wifi connect SSID password password hidden yes

Connect to a wifi on the wlan1 wifi interface:

$ nmcli device wifi connect SSID password password ifname wlan1 profile_name

Disconnect an interface:

$ nmcli device disconnect ifname eth0

Reconnect an interface marked as disconnected:

$ nmcli connection up uuid UUID

Get a list of UUIDs:

$ nmcli connection show

See a list of network devices and their state:

$ nmcli device

Turn off wifi:

$ nmcli radio wifi off

Front-ends

To configure and have easy access to NetworkManager, most users will want to install an applet. This GUI front-end usually resides in the system tray (or notification area) and allows network selection and configuration of NetworkManager. Various desktop environments have their own applet. Otherwise you can use #nm-applet.

GNOME

GNOME has a built-in tool, accessible from the Network settings.

KDE Plasma

Install the plasma-nm package.

nm-applet

network-manager-applet is a GTK+ 3 front-end which works under Xorg environments with a systray.

To store connection secrets install and configure GNOME/Keyring.

Be aware that after enabling the tick-box option Make available to other users for a connection, NetworkManager stores the password in plain-text, though the respective file is accessible only to root (or other users via nm-applet). See #Encrypted Wi-Fi passwords.

In order to run nm-applet without a systray, you can use trayer or stalonetray. For example, you can add a script like this one in your path:

nmgui
#!/bin/sh
nm-applet    2>&1 > /dev/null &
stalonetray  2>&1 > /dev/null
killall nm-applet

When you close the stalonetray window, it closes nm-applet too, so no extra memory is used once you are done with network settings.

The applet can show notifications for events such as connecting to or disconnecting from a WiFi network. For these notifications to display, ensure that you have a notification server installed - see Desktop notifications. If you use the applet without a notification server, you might see some messages in stdout/stderr, and the app might hang. See [2].

In order to run nm-applet with such notifications disabled, start the applet with the following command:

$ nm-applet --no-agent
Tip: nm-applet might be started automatically with a autostart desktop file, to add the --no-agent option modify the Exec line there, i.e.
Exec=nm-applet --no-agent

Appindicator

Appindicator support is available in nm-applet however it is not compiled into the official package, see FS#51740. To use nm-applet in an Appindicator environment, replace network-manager-applet with network-manager-applet-indicatorAUR and then start the applet with the following command:

$ nm-applet --indicator

nmcli-dmenu

Alternatively there is networkmanager-dmenu-gitAUR which is a small script to manage NetworkManager connections with dmenu instead of nm-applet. It provides all essential features such as connect to existing NetworkManager wifi or wired connections, connect to new wifi connections, requests passphrase if required, connect to existing VPN connections, enable/disable networking, launch nm-connection-editor GUI.

Configuration

NetworkManager will require some additional steps to be able run properly. Make sure you have configured /etc/hosts as described in Network configuration#Set the hostname section.

Enable NetworkManager

NetworkManager is controlled with the NetworkManager.service systemd unit. Once the NetworkManager daemon is started, it will automatically connect to any available "system connections" that have already been configured. Any "user connections" or unconfigured connections will need nmcli or an applet to configure and connect.

NetworkManager has a global configuration file at /etc/NetworkManager/NetworkManager.conf. Addition configuration files can be placed in /etc/NetworkManager/conf.d/. Usually no configuration needs to be done to the global defaults.

Enable NetworkManager Wait Online

If you have services which fail if they are started before the network is up, you may use NetworkManager-wait-online.service in addition to NetworkManager.service. This is, however, rarely necessary because most networked daemons start up okay, even if the network has not been configured yet.

In some cases, the service will still fail to start successfully on boot due to the timeout setting in /usr/lib/systemd/system/NetworkManager-wait-online.service being too short. Change the default timeout from 30 to a higher value.

Set up PolicyKit permissions

See General troubleshooting#Session permissions for setting up a working session.

With a working session, you have several options for granting the necessary privileges to NetworkManager:

  • Option 1. Run a Polkit authentication agent when you log in, such as /usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1 (part of polkit-gnome). You will be prompted for your password whenever you add or remove a network connection.
  • Option 2. Add yourself to the wheel group. You will not have to enter your password, but your user account may be granted other permissions as well, such as the ability to use sudo without entering the root password.
  • Option 3. Add yourself to the network group and create the following file:
/etc/polkit-1/rules.d/50-org.freedesktop.NetworkManager.rules
polkit.addRule(function(action, subject) {
  if (action.id.indexOf("org.freedesktop.NetworkManager.") == 0 && subject.isInGroup("network")) {
    return polkit.Result.YES;
  }
});
All users in the network group will be able to add and remove networks without a password. This will not work under systemd if you do not have an active session with systemd-logind.

Proxy settings

NetworkManager does not directly handle proxy settings, but if you are using GNOME or KDE, you could use proxydriver which handles proxy settings using NetworkManager's information. proxydriver is found in the package proxydriverAUR.

In order for proxydriver to be able to change the proxy settings, you would need to execute this command, as part of the GNOME startup process (System > Preferences > Startup Applications):

xhost +si:localuser:username

See also Proxy settings.

Disable NetworkManager when using dbus

Tango-inaccurate.pngThe factual accuracy of this article or section is disputed.Tango-inaccurate.png

Reason: Missing sources and when should this be used? (Discuss in Talk:NetworkManager#)

It might not be obvious, but the service automatically starts through dbus. To completely disable it you can mask NetworkManager.service and NetworkManager-dispatcher.service.

Checking connectivity

Tango-inaccurate.pngThe factual accuracy of this article or section is disputed.Tango-inaccurate.png

Reason: "the desktop manager" might handle captive portals, but this is mostly done through capnet-assistAUR (Discuss in Talk:NetworkManager#)

NetworkManager can try to reach a page on Internet when connecting to a network. networkmanager is configured by default in /usr/lib/NetworkManager/conf.d/20-connectivity.conf to check connectivity to archlinux.org. To use a different webserver or disable connectivity checking create /etc/NetworkManager/conf.d/20-connectivity.conf, see "connectivity section" in NetworkManager.conf(5).

For those behind a captive portal, the desktop manager can automatically open a window asking for credentials.

DNS caching and split DNS

Tango-view-fullscreen.pngThis article or section needs expansion.Tango-view-fullscreen.png

Reason: Add unbound (dnssec-triggerAUR). (Discuss in Talk:NetworkManager#)

dnsmasq

NetworkManager has a plugin to enable DNS using dnsmasq. The advantages of this setup is that DNS lookups will be cached, shortening resolve times, and DNS lookups of VPN hosts will be routed to the relevant VPN's DNS servers (especially useful if you are connected to more than one VPN).

Make sure dnsmasq has been installed. Then, create /etc/NetworkManager/conf.d/dns.conf and add the following to it:

/etc/NetworkManager/conf.d/dns.conf
[main]
dns=dnsmasq

Now restart NetworkManager.service. NetworkManager will automatically start dnsmasq and add 127.0.0.1 to /etc/resolv.conf. The actual DNS servers can be found in /run/NetworkManager/resolv.conf. You can verify dnsmasq is being used by doing the same DNS lookup twice with $ drill example.com and verifying the server and query times.

Custom configuration

Custom configurations can be created for dnsmasq by creating configuration files in /etc/NetworkManager/dnsmasq.d/. For example, to change the size of the DNS cache (which is stored in RAM):

/etc/NetworkManager/dnsmasq.d/cache.conf
cache-size=1000
Tip: Check the configuration file syntax with dnsmasq --test --conf-file=/dev/null --conf-dir=/etc/NetworkManager/dnsmasq.d.

See dnsmasq(8) for all available options.

IPv6

Tango-inaccurate.pngThe factual accuracy of this article or section is disputed.Tango-inaccurate.png

Reason: This does not solve the issue because NetworkManager does not add ::1 to /etc/resolv.conf. Unless @::1 is manually passed to drill, it will still fail with Error: error sending query: No (valid) nameservers defined in the resolver. (Discuss in Talk:NetworkManager#)

Enabling dnsmasq in NetworkManager may break IPv6-only DNS lookups (i.e. drill -6 [hostname]) which would otherwise work. In order to resolve this, creating the following file will configure dnsmasq to also listen to the IPv6 loopback:

/etc/NetworkManager/dnsmasq.d/ipv6_listen.conf
listen-address=::1

In addition, dnsmasq also does not prioritize upstream IPv6 DNS. Unfortunately NetworkManager does not do this (Ubuntu Bug). A workaround would be to disable IPv4 DNS in the NetworkManager config, assuming one exists

DNSSEC

The dnsmasq instance started by NetworkManager by default will not validate DNSSEC since it is started with the --proxy-dnssec option. It will trust whatever DNSSEC information it gets from the upstream DNS server.

For dnsmasq to properly validate DNSSEC, create the following configuration file:

/etc/NetworkManager/dnsmasq.d/dnssec.conf
conf-file=/usr/share/dnsmasq/trust-anchors.conf
dnssec
dnssec-check-unsigned

systemd-resolved

NetworkManager can use systemd-resolved as a DNS resolver and cache. Make sure that systemd-resolved is properly configured and that systemd-resolved.service is started before using it.

systemd-resolved will be used automatically if /etc/resolv.conf is a symlink to /run/systemd/resolve/stub-resolv.conf, /run/systemd/resolve/resolv.conf or /usr/lib/systemd/resolv.conf.

If /etc/resolv.conf is not a symlink to any of those files, enable it explicitly by setting the dns= option in NetworkManager.conf(5):

/etc/NetworkManager/conf.d/dns.conf
[main]
dns=systemd-resolved

Other methods

Tip: Set the local DNS server address in /etc/resolvconf.conf and configure NetworkManager to use openresolv.

With an already working caching DNS server, the DNS server address can be specified it in NetworkManagers' settings (usually by right-clicking the applet). Setup will depend on the type of front-end used; the process usually involves right-clicking on the applet, editing (or creating) a profile, and then choosing DHCP type as 'Automatic (specify addresses).' The DNS addresses will need to be entered and are usually in this form: 127.0.0.1, DNS-server-one, ....

Network services with NetworkManager dispatcher

There are quite a few network services that you will not want running until NetworkManager brings up an interface. NetworkManager has the ability to start services when you connect to a network and stop them when you disconnect (e.g. when using NFS, SMB and NTPd).

To activate the feature you need to enable and start the NetworkManager-dispatcher.service.

Once the service is active, scripts can be added to the /etc/NetworkManager/dispatcher.d directory.

Scripts must be owned by root, otherwise the dispatcher will not execute them. For added security, set group ownership to root as well:

# chown root:root /etc/NetworkManager/dispatcher.d/10-script.sh

Make sure the file has correct permissions:

# chmod 755 /etc/NetworkManager/dispatcher.d/10-script.sh

The scripts will be run in alphabetical order at connection time, and in reverse alphabetical order at disconnect time. To ensure what order they come up in, it is common to use numerical characters prior to the name of the script (e.g. 10-portmap or 30-netfs (which ensures that the portmapper is up before NFS mounts are attempted).

Scripts will receive the following arguments:

  • Interface name: e.g. eth0
  • Interface status: up or down
  • VPN status: vpn-up or vpn-down
Warning: If you connect to foreign or public networks, be aware of what services you are starting and what servers you expect to be available for them to connect to. You could make a security hole by starting the wrong services while connected to a public network.

Avoiding the dispatcher timeout

If the above is working, then this section is not relevant. However, there is a general problem related to running dispatcher scripts which take longer to be executed. Initially an internal timeout of three seconds only was used. If the called script did not complete in time, it was killed. Later the timeout was extended to about 20 seconds (see the Bugtracker for more information). If the timeout still creates the problem, a work around may be to modify the dispatcher service file /usr/lib/systemd/system/NetworkManager-dispatcher.service to remain active after exit:

/etc/systemd/system/NetworkManager-dispatcher.service
.include /usr/lib/systemd/system/NetworkManager-dispatcher.service
[Service]
RemainAfterExit=yes

Now start and enable the modified NetworkManager-dispatcher service.

Warning: Adding the RemainAfterExit line to it will prevent the dispatcher from closing. Unfortunately, the dispatcher has to close before it can run your scripts again. With it the dispatcher will not time out but it also will not close, which means that the scripts will only run once per boot. Therefore, do not add the line unless the timeout is definitely causing a problem.

Dispatcher examples

Mount remote folder with sshfs

As the script is run in a very restrictive environment, you have to export SSH_AUTH_SOCK in order to connect to your SSH agent. There are different ways to accomplish this, see this message for more information. The example below works with GNOME Keyring, and will ask you for the password if not unlocked already. In case NetworkManager connects automatically on login, it is likely gnome-keyring has not yet started and the export will fail (hence the sleep). The UUID to match can be found with the command nmcli con status or nmcli con list.

#!/bin/sh
USER='username'
REMOTE='user@host:/remote/path'
LOCAL='/local/path'

interface=$1 status=$2
if [ "$CONNECTION_UUID" = "uuid" ]; then
  case $status in
    up)
      SSH_AUTH_SOCK=$(find /tmp -maxdepth 1 -type s -user "$USER" -name 'ssh')
      export SSH_AUTH_SOCK
      su "$USER" -c "sshfs $REMOTE $LOCAL"
      ;;
    down)
      fusermount -u "$LOCAL"
      ;;
  esac
fi
Mounting of SMB shares

Some SMB shares are only available on certain networks or locations (e.g. at home). You can use the dispatcher to only mount SMB shares that are present at your current location.

The following script will check if we connected to a specific network and mount shares accordingly:

/etc/NetworkManager/dispatcher.d/30-mount-smb.sh
#!/bin/sh

# Find the connection UUID with "nmcli con show" in terminal.
# All NetworkManager connection types are supported: wireless, VPN, wired...
if [ "$2" = "up" ]; then
  if [ "$CONNECTION_UUID" = "uuid" ]; then
    mount /your/mount/point & 
    # add more shares as needed
  fi
fi

The following script will unmount all shares before a disconnect from a specific network:

/etc/NetworkManager/dispatcher.d/pre-down.d/30-mount-smb.sh
#!/bin/sh
umount -a -l -t cifs
Note:
  • Make sure this script is located in the pre-down.d sub-directory as shown above, otherwise it will unmount all shares on any connection state change.
  • Since NetworkManager 0.9.8, the pre-down and down events are not executed on shutdown or restart, see this bug report for more info.
Mounting of NFS shares

See NFS#Using a NetworkManager dispatcher.

Use dispatcher to automatically toggle wireless depending on LAN cable being plugged in

The idea is to only turn Wi-Fi on when the LAN cable is unplugged (for example when detaching from a laptop dock), and for Wi-Fi to be automatically disabled, once a LAN cable is plugged in again.

Create the following dispatcher script (Source), replacing LAN_interface with yours.

/etc/NetworkManager/dispatcher.d/wlan_auto_toggle.sh
#!/bin/sh

if [ "$1" = "LAN_interface" ]; then
    case "$2" in
        up)
            nmcli radio wifi off
            ;;
        down)
            nmcli radio wifi on
            ;;
    esac
fi
Note: You can get a list of interfaces using nmcli. The ethernet (LAN) interfaces start with en, e.g. enp0s5
Use dispatcher to connect to a VPN after a network connection is established

In this example we want to connect automatically to a previously defined VPN connection after connecting to a specific Wi-Fi network. First thing to do is to create the dispatcher script that defines what to do after we are connected to the network.

Note: This script will require wireless_tools in order to use iwgetid.
/etc/NetworkManager/dispatcher.d/vpn-up
#!/bin/sh
VPN_NAME="name of VPN connection defined in NetworkManager"
ESSID="Wi-Fi network ESSID (not connection name)"

interface=$1 status=$2
case $status in
  up|vpn-down)
    if iwgetid | grep -qs ":\"$ESSID\""; then
      nmcli con up id "$VPN_NAME"
    fi
    ;;
  down)
    if iwgetid | grep -qs ":\"$ESSID\""; then
      if nmcli con show --active | grep "$VPN_NAME"; then
        nmcli con down id "$VPN_NAME"
      fi
    fi
    ;;
esac

If you would like to attempt to automatically connect to VPN for all Wi-Fi networks, you can use the following definition of the ESSID: ESSID=$(iwgetid -r). Remember to set the script's permissions accordingly.

Trying to connect with the above script may still fail with NetworkManager-dispatcher.service complaining about 'no valid VPN secrets', because of the way VPN secrets are stored. Fortunately, there are different options to give the above script access to your VPN password.

1: One of them requires editing the VPN connection configuration file to make NetworkManager store the secrets by itself rather than inside a keyring that will be inaccessible for root: open up /etc/NetworkManager/system-connections/name of your VPN connection and change the password-flags and secret-flags from 1 to 0.

If that alone does not work, you may have to create a passwd-file in a safe location with the same permissions and ownership as the dispatcher script, containing the following:

/path/to/passwd-file
vpn.secrets.password:YOUR_PASSWORD

The script must be changed accordingly, so that it gets the password from the file:

/etc/NetworkManager/dispatcher.d/vpn-up
#!/bin/sh
VPN_NAME="name of VPN connection defined in NetworkManager"
ESSID="Wi-Fi network ESSID (not connection name)"

interface=$1 status=$2
case $status in
  up|vpn-down)
    if iwgetid | grep -qs ":\"$ESSID\""; then
      nmcli con up id "$VPN_NAME" passwd-file /path/to/passwd-file
    fi
    ;;
  down)
    if iwgetid | grep -qs ":\"$ESSID\""; then
      if nmcli con show --active | grep "$VPN_NAME"; then
        nmcli con down id "$VPN_NAME"
      fi
    fi
    ;;
esac

2: Alternatively, change the password-flags and put the password directly in the configuration file adding the section vpn-secrets:

 [vpn]
 ....
 password-flags=0
 
 [vpn-secrets]
 password=your_password
Note: It may now be necessary to re-open the NetworkManager connection editor and save the VPN passwords/secrets again.
OpenNTPD

See OpenNTPD#Using NetworkManager dispatcher.

Testing

NetworkManager applets are designed to load upon login so no further configuration should be necessary for most users. If you have already disabled your previous network settings and disconnected from your network, you can now test if NetworkManager will work. The first step is to start NetworkManager.service.

Some applets will provide you with a .desktop file so that the NetworkManager applet can be loaded through the application menu. If it does not, you are going to either have to discover the command to use or logout and login again to start the applet. Once the applet is started, it will likely begin polling network connections with for auto-configuration with a DHCP server.

To start the GNOME applet in non-xdg-compliant window managers like awesome:

nm-applet --sm-disable &

For static IP addresses, you will have to configure NetworkManager to understand them. The process usually involves right-clicking the applet and selecting something like 'Edit Connections'.

Tips and tricks

Encrypted Wi-Fi passwords

By default, NetworkManager stores passwords in clear text in the connection files at /etc/NetworkManager/system-connections/. To print the stored passwords, use the following command:

# grep -H '^psk=' /etc/NetworkManager/system-connections/*

The passwords are accessible to the root user in the filesystem and to users with access to settings via the GUI (e.g. nm-applet).

It is preferable to save the passwords in encrypted form in a keyring instead of clear text. The downside of using a keyring is that the connections have to be set up for each user.

Using Gnome-Keyring

The keyring daemon has to be started and the keyring needs to be unlocked for the following to work.

Furthermore, NetworkManager needs to be configured not to store the password for all users. Using GNOME nm-applet, run nm-connection-editor from a terminal, select a network connection, click Edit, select the Wifi-Security tab and click on the right icon of password and check Store the password only for this user.

Using KDE Wallet

Using KDE's plasma-nm, click the applet, click on the top right Settings icon, click on a network connection, in the General settings tab, untick all users may connect to this network. If the option is ticked, the passwords will still be stored in clear text, even if a keyring daemon is running.

If the option was selected previously and you un-tick it, you may have to use the reset option first to make the password disappear from the file. Alternatively, delete the connection first and set it up again.

Sharing internet connection over Wi-Fi

You can share your internet connection (e.g. 3G or wired) with a few clicks. You will need a supported Wi-Fi card (Cards based on Atheros AR9xx or at least AR5xx are probably best choice). Please note that a firewall may interfere with internet sharing.

  • Install the dnsmasq package to be able to actually share the connection.

Create the shared connection:

  • Click on applet and choose Create new wireless network.
  • Follow wizard (if using WEP, be sure to use 5 or 13 character long password, different lengths will fail).
    • Choose either Hotspot or Ad-hoc as Wi-Fi mode.

The connection will be saved and remain stored for the next time you need it.

Note: Android does not support connecting to Ad-hoc networks. To share a connection with Android use infrastructure mode (i.e. set Wi-Fi mode to "Hotspot").

Sharing internet connection over Ethernet

Scenario: your device has internet connection over wi-fi and you want to share the internet connection to other devices over ethernet.

Requirements:

  • Install the dnsmasq package to be able to actually share the connection.
  • Your internet connected device and the other devices are connected over a suitable ethernet cable (this usually means a cross over cable or a switch in between).
  • Internet sharing is not blocked by a firewall.

Steps:

  • Run nm-connection-editor from terminal.
  • Add a new ethernet connection.
  • Give it some sensible name. For example "Shared Internet"
  • Go to "IPv4 Settings".
  • For "Method:" select "Shared to other computers".
  • Save

Now you should have a new option "Shared Internet" under the Wired connections in NetworkManager.

Checking if networking is up inside a cron job or script

Some cron jobs require networking to be up to succeed. You may wish to avoid running these jobs when the network is down. To accomplish this, add an if test for networking that queries NetworkManager's nm-tool and checks the state of networking. The test shown here succeeds if any interface is up, and fails if they are all down. This is convenient for laptops that might be hardwired, might be on wireless, or might be off the network.

if [ $(nm-tool|grep State|cut -f2 -d' ') == "connected" ]; then
    #Whatever you want to do if the network is online
else
    #Whatever you want to do if the network is offline - note, this and the else above are optional
fi

This useful for a cron.hourly script that runs fpupdate for the F-Prot virus scanner signature update, as an example. Another way it might be useful, with a little modification, is to differentiate between networks using various parts of the output from nm-tool; for example, since the active wireless network is denoted with an asterisk, you could grep for the network name and then grep for a literal asterisk.

Connect to network with secret on boot

By default, NetworkManager will not connect to networks requiring a secret automatically on boot. This is because it locks such connections to the user who makes it by default, only connecting after they have logged in. To change this, do the following:

  1. Right click on the nm-applet icon in your panel and select Edit Connections and open the Wireless tab
  2. Select the connection you want to work with and click the Edit button
  3. Check the boxes “Connect Automatically” and “Available to all users”

Log out and log back in to complete.

Automatically unlock keyring after login

NetworkManager requires access to the login keyring to connect to networks requiring a secret. Under most circumstances, this keyring is unlocked automatically at login, but if it is not, and NetworkManager is not connecting on login, you can try the following.

GNOME

Note: The following method is dated and known not to work on at least one machine!
  • In /etc/pam.d/gdm (or your corresponding daemon in /etc/pam.d), add these lines at the end of the "auth" and "session" blocks if they do not exist already:
 auth            optional        pam_gnome_keyring.so
 session         optional        pam_gnome_keyring.so  auto_start
  • In /etc/pam.d/passwd, use this line for the 'password' block:
 password    optional    pam_gnome_keyring.so
Next time you log in, you should be asked if you want the password to be unlocked automatically on login.

SLiM login manager

See SLiM#Gnome Keyring.

Troubleshooting

While you may type both values at connection time, plasma-nm 0.9.3.2-1 and above are capable of retrieving OpenConnect username and password directly from KWallet.

Open "KDE Wallet Manager" and look up your OpenConnect VPN connection under "Network Management|Maps". Click "Show values" and enter your credentials in key "VpnSecrets" in this form (replace username and password accordingly):

form:main:username%SEP%username%SEP%form:main:password%SEP%password

Next time you connect, username and password should appear in the "VPN secrets" dialog box.

Ignore specific devices

Sometimes it may be desired that NetworkManager ignores specific devices and does not try to configure addresses and routes for them. You can quickly and easily ignore devices by MAC or interface-name by using the following in /etc/NetworkManager/conf.d/unmanaged.conf:

[keyfile]
unmanaged-devices=mac:00:22:68:1c:59:b1;mac:00:1E:65:30:D1:C4;interface-name:eth0

After you have put this in, restart NetworkManager, and you should be able to configure interfaces without NetworkManager altering what you have set.

Configuring MAC address randomization

Note: Disabling MAC address randomization may be needed to get (stable) link connection [3] and/or networks that restrict devices based on their MAC Address or have a limit network capacity.

MAC randomization can be used for increased privacy by not disclosing your real MAC address to the network.

NetworkManager supports two types MAC Address Randomization: randomization during scanning, and for network connections. Both modes can be configured by modifying /etc/NetworkManager/NetworkManager.conf or by creating a separate configuration file in /etc/NetworkManager/conf.d/ which is recommended since the aforementioned config file may be overwritten by NetworkManager.

Randomization during Wi-Fi scanning is enabled by default, but it may be disabled by adding the following lines to /etc/NetworkManager/NetworkManager.conf or a dedicated configuration file under /etc/NetworkManager/conf.d:

[device]
wifi.scan-rand-mac-address=no

MAC randomization for network connections can be set to different modes for both wireless and ethernet interfaces. See the Gnome blog post for more details on the different modes.

In terms of MAC randomization the most important modes are stable and random. Stable generates a random MAC address when you connect to a new network and associates the two permanently. This means that you will use the same MAC address every time you connect to that network. In contrast, random will generate a new MAC address every time you connect to a network, new or previously known. You can configure the MAC randomization by adding the desired configuration under /etc/NetworkManager/conf.d.

[device-mac-randomization]
# "yes" is already the default for scanning
wifi.scan-rand-mac-address=yes

[connection-mac-randomization]
# Randomize MAC for every ethernet connection
ethernet.cloned-mac-address=random
# Generate a random MAC for each WiFi and associate the two permanently.
wifi.cloned-mac-address=stable

See the following GNOME blogpost for more details.

Enable IPv6 Privacy Extensions

See IPv6#NetworkManager.

Working with wired connections

By default, NetworkManager generates a connection profile for each wired ethernet connection it finds. At the point when generating the connection, it does not know whether there will be more ethernet adapters available. Hence, it calls the first wired connection "Wired connection 1". You can avoid generating this connection, by configuring no-auto-default (see NetworkManager.conf(5)), or by simply deleting it. Then NetworkManager will remember not to generate a connection for this interface again.

You can also edit the connection (and persist it to disk) or delete it. NetworkManager will not re-generate a new connection. Then you can change the name to whatever you want. You can use something like nm-connection-editor for this task.

resolv.conf

NetworkManager overwrites resolv.conf by default.

This can be stopped by adding dns=none to the [main] section in /etc/NetworkManager/NetworkManager.conf.

After that /etc/resolv.conf might be a broken symlink that you will need to remove. Then, just create a new /etc/resolv.conf file.

NetworkManager also offers hooks via so called dispatcher scripts that can be used to alter the /etc/resolv.conf after network changes. See #Network services with NetworkManager dispatcher and NetworkManager(8) for more information.

Use openresolv

To configure NetworkManager to use openresolv, set the rc-manager option to resolvconf with a configuration file in /etc/NetworkManager/conf.d/:

/etc/NetworkManager/conf.d/rc-manager.conf
[main]
rc-manager=resolvconf

Others options are available in NetworkManager.conf(5).

Using iwd as the Wi-Fi backend

To enable the experimental iwd backend create the following configuration file:

/etc/NetworkManager/conf.d/wifi_backend.conf
[device]
wifi.backend=iwd

Troubleshooting

No prompt for password of secured Wi-Fi networks

When trying to connect to a secured Wi-Fi network, no prompt for a password is shown and no connection is established. This happens when no keyring package is installed. An easy solution is to install gnome-keyring. If you want the passwords to be stored in encrypted form, follow GNOME Keyring to set up the gnome-keyring-daemon.

No traffic via PPTP tunnel

PPTP connection logins successfully; you see a ppp0 interface with the correct VPN IP address, but you cannot even ping the remote IP address. It is due to lack of MPPE (Microsoft Point-to-Point Encryption) support in stock Arch pppd. It is recommended to first try with the stock Arch ppp as it may work as intended.

To solve the problem it should be sufficient to install the ppp-mppeAUR[broken link: archived in aur-mirror] package.

See also WPA2 Enterprise#MS-CHAPv2.

Network management disabled

When NetworkManager shuts down but the pid (state) file is not removed, you will see a Network management disabled message. If this happens, remove the file manually:

# rm /var/lib/NetworkManager/NetworkManager.state

Problems with internal DHCP client

If you have problems with getting an IP address using the internal DHCP client, consider dhclient as DHCP client.

After installation, update the NetworkManager config file:

/etc/NetworkManager/conf.d/dhcp-client.conf
[main]
dhcp=dhclient

This workaround might solve problems in big wireless networks like eduroam.

DHCP problems with dhclient

If you have problems with getting an IP address via DHCP, try to add the following to your /etc/dhclient.conf:

 interface "eth0" {
   send dhcp-client-identifier 01:aa:bb:cc:dd:ee:ff;
 }

Where aa:bb:cc:dd:ee:ff is the MAC address of this NIC. The MAC address can be found using the ip link show interface command from the iproute2 package.

Missing default route

On at least one KDE4 system, no default route was created when establishing wireless connections with NetworkManager. Changing the route settings of the wireless connection to remove the default selection "Use only for resources on this connection" solved the issue.

3G modem not detected

See USB 3G Modem#Network Manager.

Switching off WLAN on laptops

Sometimes NetworkManager will not work when you disable your Wi-Fi adapter with a switch on your laptop and try to enable it again afterwards. This is often a problem with rfkill. To check if the driver notifies rfkill about the wireless adapter's status, use:

$ watch -n1 rfkill list all

If one identifier stays blocked after you switch on the adapter you could try to manually unblock it with (where X is the number of the identifier provided by the above output):

# rfkill event unblock X

Static IP address settings revert to DHCP

Due to an unresolved bug, when changing default connections to a static IP address, nm-applet may not properly store the configuration change, and will revert to automatic DHCP.

To work around this issue you have to edit the default connection (e.g. "Auto eth0") in nm-applet, change the connection name (e.g. "my eth0"), uncheck the "Available to all users" checkbox, change your static IP address settings as desired, and click Apply. This will save a new connection with the given name.

Next, you will want to make the default connection not connect automatically. To do so, run nm-connection-editor (not as root). In the connection editor, edit the default connection (e.g. "Auto eth0") and uncheck "Connect automatically". Click Apply and close the connection editor.

Cannot edit connections as normal user

See #Set up PolicyKit permissions.

Forget hidden wireless network

Since hidden networks are not displayed in the selection list of the Wireless view, they cannot be forgotten (removed) with the GUI. You can delete one with the following command:

# rm /etc/NetworkManager/system-connections/SSID

This works for any other connection.

VPN not working in GNOME

When setting up OpenConnect or vpnc connections in NetworkManager while using GNOME, you will sometimes never see the dialog box pop up and the following error appears in /var/log/errors.log:

localhost NetworkManager[399]: <error> [1361719690.10506] [nm-vpn-connection.c:1405] get_secrets_cb(): Failed to request VPN secrets #3: (6) No agents were available for this request.

This is caused by the GNOME NM Applet expecting dialog scripts to be at /usr/lib/gnome-shell, when NetworkManager's packages put them in /usr/lib/networkmanager. As a "temporary" fix (this bug has been around for a while now), make the following symlink(s):

  • For OpenConnect: ln -s /usr/lib/networkmanager/nm-openconnect-auth-dialog /usr/lib/gnome-shell/
  • For VPNC (i.e. Cisco VPN): ln -s /usr/lib/networkmanager/nm-vpnc-auth-dialog /usr/lib/gnome-shell/

This may need to be done for any other NM VPN plugins as well, but these are the two most common.

Unable to connect to visible European wireless networks

WLAN chips are shipped with a default regulatory domain. If your access point does not operate within these limitations, you will not be able to connect to the network. Fixing this is easy:

  1. Install crda
  2. Uncomment the correct Country Code in /etc/conf.d/wireless-regdom
  3. Reboot the system, because the setting is only read on boot

Automatic connect to VPN on boot is not working

The problem occurs when the system (i.e. NetworkManager running as the root user) tries to establish a VPN connection, but the password is not accessible because it is stored in the Gnome keyring of a particular user.

A solution is to keep the password to your VPN in plaintext, as described in step (2.) of #Use dispatcher to connect to a VPN after a network connection is established.

You do not need to use the dispatcher described in step (1.) to auto-connect anymore, if you use the new "auto-connect VPN" option from the nm-applet GUI.

Systemd Bottleneck

Over time the log files (/var/log/journal) can become very large. This can have a big impact on boot performance when using NetworkManager, see: Systemd#Boot time increasing over time.

Regular network disconnects, latency and lost packets (WiFi)

NetworkManager does a scan every 2 minutes.

Some WiFi drivers have issues when scanning for base stations whilst connected/associated. Symptoms include VPN disconnects/reconnects and lost packets, web pages failing to load and then refresh fine.

Running journalctl -f will indicate that this is taking place, messages like the following will be contained in the logs at regular intervals.

NetworkManager[410]: <info>  (wlp3s0): roamed from BSSID 00:14:48:11:20:CF (my-wifi-name) to (none) ((none))

There is a patched version of NetworkManager which should prevent this type of scanning: networkmanager-noscanAUR.

Alternatively, if roaming is not important, the periodic scanning behavior can be disabled by locking the BSSID of the access point in the WiFi connection profile.

Unable to turn on wi-fi with Lenovo laptop (IdeaPad, Legion, etc.)

There is an issue with the ideapad_laptop module on some Lenovo models due to the wi-fi driver incorrectly reporting a soft block. The card can still be manipulated with netctl, but managers like NetworkManager break. You can verify that this is the problem by checking the output of rfkill list after toggling your hardware switch and seeing that the soft block persists.

Tango-inaccurate.pngThe factual accuracy of this article or section is disputed.Tango-inaccurate.png

Reason: Try to use rfkill.default_state and rfkill.master_switch_mode (see kernel-parameters.txt) to fix the rfkill problem. (Discuss in Talk:NetworkManager#)
Unloading the ideapad_laptop module should fix this. (warning: this may disable the laptop keyboard and touchpad also!).

Turn off hostname sending

NetworkManager by default sends the hostname to the DHCP server. Hostname sending can only be disabled per connection not globally (GNOME Bug 768076).

To disable sending your hostname to the DHCP server for a specific connection, add the following to your network connection file:

/etc/NetworkManager/system-connections/your_connection_file
...
[ipv4]
dhcp-send-hostname=false
...
[ipv6]
dhcp-send-hostname=false
...

nm-applet disappears in i3wm

If you use the xfce4-notifyd.service for notifications you must edit the unit and add the following:

/etc/systemd/user/xfce4-notifyd.service.d/display_env.conf
[Service]
Environment="DISPLAY=:0.0"

After reloading the daemons restart xfce4-notifyd.service. Exit i3 and start it back up again and the applet should show on the tray.

See also