Pages

Wednesday, 18 January 2012

Gentoo系统的Network Manager配置

installation
Possible USE flags for NetworkManager are:

avahi - Adds avahi(zeroconf) support (automatic network configuration)
connection-sharing - Adds support for internet connection sharing with net-dns/dnsmasq and net-firewall/iptables
dhclient - Use dhclient from net-misc/dhcp for DHCP
dhcpcd - Use net-misc/dhcpcd for DHCP
doc - Adds documentation
gnutls -Adds support for net-libs/gnutls (TLS and SSL).
nss - Adds support for Network Security Service
resolvconf - Use net-dns/openresolv for managing DNS information
bluetooth - Enables support for bluetooth (>=0.8)

Set the USE flags you need and install networkmanager.

echo net-misc/networkmanager dhcpcd resolvconf >> /etc/portage/package.use
emerge -av networkmanager
After the installation you can start networkmanager:

/etc/init.d/NetworkManager start
To make sure that it is started everytime you boot your system add it to your default runlevel

rc-update add NetworkManager default
You also have to prevent the init scripts from controlling the network interfaceses because that can lead to problems.

rc-update del net.eth0 boot
On your laptop/desktop you may want to use NetworkManager as a non root user. To do this you have to edit the NetworkManager config at /etc/dbus-1/system.d/NetworkManager.conf

Code: NetworkManager.conf 
<policy group="plugdev">
    <allow send_destination="org.freedesktop.NetworkManager"/>

    <allow send_destination="org.freedesktop.NetworkManager"
           send_interface="org.freedesktop.NetworkManager"/>
</policy>
 

or ( 1 of these 2 solutions works )

Code: NetworkManager.conf 
<policy group="plugdev">
    <allow send_destination="org.freedesktop.NetworkManager"/>
</policy>
 

This section will allow every user in the plugdev group to change the network settings. If you are not part of the group add yourself and log out for the changes to take effect

 gpasswd -a YOURUSERNAME plugdev
After you have installed NetworkManager you should enable the networkmanager use flag in your /etc/make.conf. It enables support for networkmanager in other applications.

Configuration
Ignore Devices
If you have some network devices which you want to configure by yourself (For example mobile phones which connect over a USB network interface) NetworkManager can ignore these devices. Just add the MAC Adresses of the devices you want to ignore to your configuration file /etc/NetworkManager/nm-system-settings.conf

Code: NetworkManager.conf 
[keyfile]
   unmanaged-devices=00:11:22:ab:cd:ef;33:44:55:66:77:88
 

Connection Sharing
To enable this feature of NetworkManager you have to set the connection-sharing USE flag. This feature enables a quick and dirty way to share a network connection for example an internet connection over UMTS. It is not recommended to use this feature in your real router. In the following example PC-A is connection with PC-B over eth0 and PC-A wants to share the internet connection from an UMTS modem. Right click on the NetworkManager icon in the tray area -> Edit connections. Now select the network interface that is connected to the other host (eth0) Select IPv4 Settings -> Method: Shared to other computers. Now PC-B will get an ip adress from DHCP and you are done.

Integration with udev
If you are using udev, you will also need to block it from attempting to automatically initialize your network interfaces. This can be done by modifying the /etc/conf.d/rc file (or /etc/rc.conf on OpenRC). For example, to block eth0 from loading, add this:

Code: /etc/conf.d/rc 
RC_PLUG_SERVICES="!net.eth0"
 

(Optional) Automatically connect on boot
Source: http://wiki.archlinux.org/index.php/NetworkManager#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; /etc/NetworkManager/nm-system-settings.conf 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 policykit:

 $ sudo polkit-auth --grant org.freedesktop.network-manager-settings.system.modify --user "YOURUSERNAME"
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, 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.

Note: As per this bug report, knetworkmanager does not yet implement this feature. You will need to use the GNOME network applet (nm-applet). Install it as described above in this page, "killall knetworkmanager", then start nm-applet.
[edit] (Optional) Dependencies of Baselayouts Networking Script
Any dependencies of baselayouts networking script (ntp, samba...) will require the use NetworkManagerDispatcher to start them. This is needed since NetworkManager does not initialize the network till after the desktop is loaded. To start these scripts they will need to be identified to NetworkManager.

Now follows the short but important script, which starts our dependent script when we're online for the first time. ntp-client is used and an example here:

Code: /etc/NetworkManager/dispatcher.d/50-ntp-client 
#!/bin/bash

/etc/init.d/ntp-client status | grep -q "started"

if test "$2" == "up" -a "$?" != "0" ; then
        rc-config start ntp-client
else
        rc-config stop ntp-client
fi
 

Don't forget to delete ntp-client from startup-level

rc-update del ntp-client
Now, ntp-client won't start until NetworkManager starts.

User Interface
You can choose different user interfaces for NetworkManager. A QT and GTK GUI and also a CLI is available.

GTK
The GTK Application is running in the system tray area and is called gnome-extra/nm-applet. The ebuild pulls in the gnome-base/gnome-panel by default. If you have a desktop envirionment that is not Gnome or XFCE you will have to install x11-misc/trayer to satisfy the application depencies.

emerge -av trayer
If you have Gnome or XFCE running it should work with emerging nm-applet

emerge -av nm-applet
You will have to edit the nm-applet config /etc/dbus-1/system.d/nm-applet.conf to allow a normal user to modify settings.

Code: nm-applet.conf 
<policy group="plugdev">
    <allow own="org.freedesktop.NetworkManagerUserSettings"/>
    <allow send_destination="org.freedesktop.NetworkManagerUserSettings"
           send_interface="org.freedesktop.NetworkManagerUserSettings"/>

    <deny send_interface="org.freedesktop.NetworkManagerSettings.Secrets"/>
</policy>

To start the applet you will need a WM or a panel or some other application which can handle system tray applications. Start the applet with

nm-applet
An icon should appear immediately in your system tray area.

QT
If you want to have a QT application you are probably using KDE. In KDE there is a plasmoid available to control the NetworkManager settings. If you want to use a stand alone app you can try kde-misc/knetworkmanager but it seems that nobody is developing it at the moment.

CLI
The Command Line Interface is marked as unstable in the portage tree. You will have to unmask it before installation

echo net-misc/cnetworkmanager ~x86>> /etc/portage/package.keywords
emerge -av net-misc/cnetworkmanager
Retrieved from "http://en.gentoo-wiki.com/wiki/NetworkManager"

No comments:

Post a Comment