NetworkManager (Česky)
Template:Article summary text Template:Article summary heading Template:Article summary text Template:Article summary end
NetworkManager je program pro poskytování detekce a konfigurace pro systém k automatickému připojení k síti. Funkcionalit NetworkManageru může být použitelná jak pro bezdrátové tak i pro drátové sítě. Pro bezdrátové sítě, NetworkManager upřednostňuje známé bezdrátové sítě a má schopnost vhodně přepínat do nejhodnověrnějších sítí. NetworkManager-vnímající aplikace mohou přepínat mezi online a offline módem. NetworkManager also prefers wired connections over wireless ones, má podporu pro modemová připojení a určitých druhů VPN. NetworkManager byl původně vyvinut společností RedHat a nyní je hostován projektem GNOME.
Contents
- 1 Základní instalace
- 2 Grafická nástavba
- 3 Nastavení
- 4 Testing
- 5 Troubleshooting
- 5.1 Permission problems
- 5.2 Network Management Disabled
- 5.3 NetworkManager prevents DHCPCD from using resolv.conf.head and resolv.conf.tail
- 5.4 Preserving changes to resolv.conf
- 5.5 DHCP problems
- 5.6 How to bypass Gnome keyring for normal users connecting with wireless
- 5.7 Missing default route
- 5.8 3G modem not detected
- 5.9 VPN problems in Networkmanager 0.7.999
- 5.10 Switching off WLAN on laptops
- 5.11 Static IP Settings Revert To DHCP
- 6 Tips and tricks
Základní instalace
NetworkManager je dostupný z oficiálních repozitářů:
# pacman -S networkmanager
Grafická nástavba
Ke konfiguraci a snadnému přístupu k NetworkManageru bude mnoho lidí chtít nainstalovat miniaplikaci. Tato GUI nástavba se obvykle usadí v system tray (nebo oznamovací oblasti) a dovolí výběr sítě a nastavení NetworkManageru. Různé miniaplikace existují pro rozdílné druhy desktopů.
GNOME
GNOME miniaplikace (dříve gnome-network-manager) je dostatečně odlehčené a pracuje přes všechna prostředí:
# pacman -S network-manager-applet
Jestliže chcete uchovávat autentizační detaily (Wireless/DSL) a zapnout globální nastavení připojení, např "dostupnost pro všechny uživatele":
# pacman -S gnome-keyring
KDE4
KNetworkManager nadstavba je dostupná v KDE verzy 4.4 jako plasma widget:
# pacman -S kdeplasma-applets-networkmanagement
GNOME protějšek pracuje stejně pěkně nebo dokonce lépe (má více prvků a detekuje víc hardwaru).
KDE3
Ačkoliv již není podporován, Template:Package AUR je dostupný z AUR. Název balíčku:
knetworkmanager
Openbox
GNOME miniaplikace pracuje dobře s xfce4-notifyd notification daemon:
# pacman -S network-manager-applet xfce4-notifyd hicolor-icon-theme gnome-icon-theme
Jestliže chcete uchovávat autentizační detaily (Wireless/DSL):
# pacman -S gnome-keyring
K vyhnutí se nm-applet dbus chybám, upravte ~/.xinitrc a změňte "exec openbox-session" na "exec ck-launch-session openbox-session".
Aby Openboxový autostart.sh nastartoval nm-applet dobře, bude možná potřeba smazat soubor /etc/xdg/autostart/nm-applet.desktop (Je možné, že bude potřeba mazat tento soubor po každé změně v network-manager-apletu)
Potom v autostart.sh, nastartuje nm-applet tímto řádkem:
(sleep 3 && /usr/bin/nm-applet --sm-disable) &
Ostatní desktopy a Okenní manažery
Je doporučeno používat GNOME miniaplikaci. Také je potřeba zajistit, že GNOME hicolor theme je nainstalováno, kvůli zobrazení této miniaplikace:
# pacman -S hicolor-icon-theme gnome-icon-theme
Příkazový řádek
Balíček Networkmanager od verze 0.8.1 obsahuje nmcli
Nastavení
NetworkManager vyžaduje pár dodatečných kroků, aby mohl pracovat korektně.
Ověřte zda je váš Template:Filename je správný, před tím než budete pokračovat. Jestliže jste se předčasně pokoušeli připojit před následujícím krokem, NetworkManager to může oznámit. Příklad hostname řádku v Template:Filename:
#<ip-address> <hostname.domain.org> <hostname> 127.0.0.1 localhost.localdomain localhost dell-latitude
Vypnutí současného síťového nastavení
Abyste správně otestovali NetworkManagera, změnte své současné síťové nastavení. Zaprvé (Při použítí Arch Linux síťových skriptů) zastavte sítě:
/etc/rc.d/network stop
Ukončete vaše NIC's (Network Interface Controllers, tj. síťové karty). Například:
ifconfig eth0 down ifconfig wlan0 down
Upravte Template:Filename a kde je definováno DHCP nebo statická IP adresa, okomentujte:
#eth0="dhcp" #wlan0="dhcp" INTERFACES=(!eth0 !wlan0)
Úprava démonů
Musíte odstranit základního network démona a přidat networkmanager démona, za dbus démona:
DAEMONS=( ...dbus networkmanager... )
Ujistěte se, že balíček Template:Package Official je nainstalován tak jak to NetworkManager vyžaduje. Ke nastartování ostatních služeb (démonů) které vyžaduje síťové připojení si ukážeme v následující sekcí na jejich nastavení. Ačkoliv je zde NetworkManager démon nastartován, nepřipojí se (v základu) do sítě dokud není miniaplikace nahraná a specifikace miniapletu potřebné k připojení. To znamená, že síťové služby je potřeba specifikovat NetworkManageru až když běží.
Síťové služby s NetworkManager Dispatcher
Je zde pár síťových služeb, které nebudou chtít běžet na rozhraní spuštěném NetworkManagerem. Dobrým příkladem jsou openntpd a síťová souborová připojení různých typů (například netfs). NetworkManager má schopnost spustit tyto služby když se připojujete k síti (interface up), a zastavit je když už nejsou potřeba (interface down).
Pro použítí těchto pruvku může být přidán skript do adresáře Template:Filename. Tyto skripty potřebují mít uživatelské právo ke spuštění. Kvůli bezpečnosti je dobrým zvykem udělat jejich vlastníkem uživatele root:root a příznak zápisu jen pro vlastníka.
Skripty budou spouštěny v abecedním pořadí v čase připojení (s argumenty interface up), a v obráceném abecedním pořadí v čase odpojení (interface down). Pro zajištění správného pořadí, je běžné použití číslic před jménem skriptu (například Template:Filename nebo Template:Filename (který zajišťuje že portmapper je spuštěn před pokusem o přimountování NFS).
Následují skript nastartuje démona openntpd když je rozhraní spouštěno. Uložte soubor jako Template:Filename a udělte mu práva ke spuštění.
#!/bin/sh INTERFACE=$1 # The interface which is brought up or down STATUS=$2 # The new state of the interface case "$STATUS" in 'up') # $INTERFACE is up exec /etc/rc.d/openntpd start ;; 'down') # $INTERFACE is down # Check for active interface and down if no one active if [ ! `nm-tool|grep State|cut -f2 -d' '` == "connected" ]; then exec /etc/rc.d/openntpd stop fi ;; esac
Use dispatcher to connect to a vpn after a network-connection is established
In this example we want to connect automatically to a vpn-connection we defined previously with NetworkManager. First thing to to is to create the dispatcher-script that defines what to do after we connected to the network.
1. Create the dispatcher script in Template:Filename
case "$2" in up) sudo -u username DISPLAY=:0 /usr/bin/python /etc/NetworkManager/vpn-up.py ;; esac
Remember to make it executable with chmod +x and change username to the right one.
2. Create the Template:Filename and change network-ESSID to the desired one. You'll find the code here.
Now NetworkManager should try to connect to your vpn which you had defined in your profile.
Proxy settings
Network Manager does not directly handle proxy settings, but if you are using GNOME, you could use proxydriver wich handles proxy settings using Network Manager's informations. Package Template:Package AUR is in the AUR.
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:your_username
See: Proxy settings
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. First start the daemon:
/etc/rc.d/networkmanager start
Some applets will provide you with a .desktop file so that the NetworkManager applet can be loaded through the application menu. If it doesn't, you're 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 IPs you will have to configure NetworkManager to understand them. The process usually involves right-clicking the applet and selecting something like 'Edit Connections'.
Troubleshooting
Some fixes to common problems.
Permission problems
Make sure consolekit is installed and use
exec ck-launch-session wm
instead of
exec wm
in Template:Filename. Most Display Managers will take care of consolekit automatically, but if you use SLiM, follow SLiM#PolicyKit.
Network Management Disabled
Sometimes when NM shuts down the pid (state) file does not get removed and you will get a 'Network management disabled' message. If this happens, you'l have to remove it manually:
rm /var/lib/NetworkManager/NetworkManager.state
If this happens upon reboot, you can add an action to your Template:Filename to have it removed upon bootup:
nmpid=/var/lib/NetworkManager/NetworkManager.state [ -f $nmpid ] && rm $nmpid
NetworkManager prevents DHCPCD from using resolv.conf.head and resolv.conf.tail
Sometimes it's problematic to add static items to resolv.conf when it's constantly rewritten by nm and dhcpcd. You can use networkmanager-dhclient package from AUR but a better solution is to use this simple script:
#!/bin/bash # # /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"
Preserving changes to resolv.conf
NetworkManager will attempt to write DNS information from DHCP into /etc/resolv.conf
, overwriting the existing contents. To prevent this, you can set the immutable bit on the file (as root):
# chattr +i /etc/resolv.conf
To modify the file in the future, first remove the immutable bit:
# chattr -i /etc/resolv.conf
DHCP problems
If you have problems with getting an IP via DHCP try to add the following to your Template:Filename:
interface "eth0" { send dhcp-client-identifier 01:aa:bb:cc:dd:ee:ff; }
Where Template:Codeline is the MAC-adress of this NIC.
How to bypass Gnome keyring for normal users connecting with wireless
It's super simple! First, create a group called networkmanager with the following command (or any other method you prefer):
# groupadd networkmanager
Then add your user to that group using the following command (or any other preferred method):
# gpasswd -a username networkmanager
Replace username in the above command with your actual username.
Now, as root, launch nm-connection-editor and configure the connections:
# nm-connection-editor
Put a check mark next to "Available to all users" and apply the settings.
Now you won't be bothered by Gnome keyring! (citation needed) Also, if you additionally enable "connect automatically", your connection will be available and connected before you even log in to your desktop, making your whole startup process even faster!
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
If NetworkManager (from v0.7.999) does not detect your 3G modem, but you still can connect using wvdial, try installing modemmanager package using Template:Codeline and restart NetworkManager daemon with Template:Codeline. Replug your modem or restart. This utility provides support for hardware not in networkmanager's default database.
VPN problems in Networkmanager 0.7.999
If you get the error message "invalid secrets" when trying to connect to your VPN provider using the PPTP protocol, try installing the git versions instead: networkmanager, nm-applet and the pptp plugin.
Switching off WLAN on laptops
Sometimes networkmanager won't work when you disable your Wifi-adapter with a switch on your laptop and try to enable it again afterwards. This is often a problem with rfkill. Install rfkill from the repo:
# pacman -S rfkill
and use
$ watch -n1 rfkill list all
to check if the driver notifies 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):
# rfkill event unblock X
Static IP Settings Revert To DHCP
Due to an unresolved bug, when changing default connections to static IP, nm-applet may not properly store the configuration change, and will revert to automatic DHCP. A workaround for this issue follows.
Edit the default connection (eg "Auto eth0") in nm-applet. Change the connection name (eg "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.
Next, you will want to make the default connection not connect automatically. To do so, run
$ sudo nm-connection-editor # you must use sudo, not su
In the connection editor, edit the default connection (eg "Auto eth0") and uncheck "Connect automatically". Click Apply and close the connection editor.
Tips and tricks
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.
Automatically unlock keyring after login
Gnome
- Right click on the NM 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.
*In Template:Filename (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 Template:Filename, 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.
KDE
- Put a script like the following in ~/.kde4/Autostart:
$!/bin/sh echo PASSWORD | /usr/bin/pam-keyring-tool --unlock --keyring=default -s
- Similar should work with openbox, lxde, etc.
Automatically connect on boot
Since version 0.7 the NetworkManager is able to connect on boot, before a user has logged in and unlocked the keyring.
- First make sure that the keyfile plugin is loaded; Template:Filename should look like this:
[main] plugins=keyfile
- If this was not in the file before, you have to restart nm-system-settings:
# killall -TERM nm-system-settings
- or simply reboot.
- Now grant your user the right to modify system-connections:
With polkit:
Place the following in /etc/polkit-1/localauthority/50-local.d/10-org-freedesktop-network-manager-settings.pkla
[Allow user YOURUSERNAME to create wireless connections for all users] Identity=unix-user:YOURUSERNAME Action=org.freedesktop.network-manager-settings.system.modify ResultAny=no ResultInactive=no ResultActive=yes
- Finally, in the connection-editor (of the gnome applet), check the Available to all users box.
The connection is now saved in /etc/NetworkManager/system-connections/"CONNECTION NAME". On reboot, NetworkManager will try to connect to it, when in range.
Please vote for the bug!
Ignore specific devices
Sometimes it is desired, that network manager ignores some devices and do not try to get an IP.
- First you have to find out the Hal UDI (e.g. with lshal):
... info.product = 'Networking Interface' (string) info.subsystem = 'net' (string) info.udi = '/org/freedesktop/Hal/devices/net_00_1f_11_01_06_55' (string) linux.hotplug_type = 2 (0x2) (int) linux.subsystem = 'net' (string) ...
- Add the udi to /etc/NetworkManager/nm-system-settings.conf:
[keyfile] unmanaged-devices=/org/freedesktop/Hal/devices/net_00_1f_11_01_06_55
- Multiple devices can be specified, delimited by semicolons:
[keyfile] unmanaged-devices=/org/freedesktop/Hal/devices/net_00_1f_11_01_06_55;/org/freedesktop/Hal/devices/net_00_2c_6d_e2_08_af
You do not need to restart NetworkManager for the changes to take effect.
- Ignoring a type of device at boot time.
this script was used to ignore all ethernet devices at boot time of a archiso build, it can be changed to ignore wifi devices etc. /!\being used on a non-persistant filesystem, the nm-system-settings.conf is default at run time
#!/bin/sh # author: tim noise <darknoise@drkns.net> COUNT=0 TARGET_FILE="/etc/NetworkManager/nm-system-settings.conf" for i in `lshal | grep -A6 'Networking Interface' | awk -F "'" '/info.udi = / {print $2}'`; do if [ $COUNT = 0 ]; then COUNT=$COUNT+1; echo "unmanaged-devices=$i" >> $TARGET_FILE else echo -n ";$i" >> $TARGET_FILE fi done printf "\n" >> $TARGET_FILE