Difference between revisions of "Use NetworkManager to configure network settings"

From FriendlyELEC WiKi
Jump to: navigation, search
(使用NetworkManager连接WiFi)
(updated by API)
 
(11 intermediate revisions by 2 users not shown)
Line 42: Line 42:
 
$ sudo nmcli dev wifi connect "SSID" password "PASSWORD"
 
$ sudo nmcli dev wifi connect "SSID" password "PASSWORD"
 
</syntaxhighlight>
 
</syntaxhighlight>
请将 SSID和 PASSWORD 替换成实际的 WiFi名称和密码。<br />
+
The "SSID" and "Password" need to be replaced with your actual WiFi's SSID and password.<br />
连接成功后,下次开机,WiFi 也会自动连接。<br />
+
If a connection is successfully established your board will be automatically connected to your specified WiFi on system reboot.<br />
* 多个WiFi硬件时,可以用 ifname参数指定要操作的WiFi设备,例如wlan1:
+
* Disconnect WiFi
 +
<syntaxhighlight lang="bash">
 +
$ sudo nmcli dev disconnect wlan0
 +
</syntaxhighlight>
 +
* If there are mutiple active WiFi devices you can specify your expected WiFi device by using the ifname option in the following command. For example if you want to operate wlan1 you can do it this way:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
sudo nmcli device wifi connect "ssid" password "password" ifname wlan1
 
sudo nmcli device wifi connect "ssid" password "password" ifname wlan1
 
</syntaxhighlight>
 
</syntaxhighlight>
  
===命令行下的图形化操作(nmtui)===
+
===Commandline Based GUI(nmtui)===
nmtui 是一个基于curses的图形化前端界面,输入以下命令即可进入:
+
nmtui is a curses based GUI. You can start it by running the following command:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
$ sudo nmtui
 
$ sudo nmtui
 
</syntaxhighlight>
 
</syntaxhighlight>
使用信息参见man nmtui。
+
For more details refer to "man nmtui".
  
===图形界面操作===
+
===Operations with Windows Utility===
在Debian的桌面环境下,有两个入口可以管理网络: <br />
+
Under Debian there are two options to start a Windows utility:<br />
  
一是点击桌面任务栏右下角的网络图标,会弹出 NetworkManger 的菜单,列出当前的网络连接状态,如果有WiFi网络,会列出周边的无线热点,如下图所示:<br />
+
Option 1: you can click on the network icon on the bottom right of the task bar. After you click on it a NetworkManger menu will pop up and all the available networks will be listed. If there is an active wireless network you will see something similar to the following screenshot:<br />
  
 
[[File:NetworkManagerIcon.png|frameless|400px|NetworkManagerIcon]]<br />
 
[[File:NetworkManagerIcon.png|frameless|400px|NetworkManagerIcon]]<br />
  
你可以点击菜单上的无线热点,即可连接到该热点。
+
You can click on a WiFI AP and connect your board to it.
  
二是通过系统菜单 Preferences -> Network Connections进入:<br />
+
Option 2: you can go to Preferences -> Network Connections and enter the following window:<br />
  
 
[[File:NetworkManangerMenu.png|frameless|400px|NetworkManangerMenu]]<br />
 
[[File:NetworkManangerMenu.png|frameless|400px|NetworkManangerMenu]]<br />
  
==配置静态IP地址==
+
==Setup Static IP==
===方法1:不使用NetworkManager管理,手动设置===
+
===1: Setup Static IP Manually===
以下文字介绍不使用 NetworkManager 来管理网络,改为手动设置,设置静态IP更灵活:
+
You can setup a static IP manually without using the NetworkManager:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
sudo vi /etc/NetworkManager/NetworkManager.conf
 
sudo vi /etc/NetworkManager/NetworkManager.conf
 
</syntaxhighlight>
 
</syntaxhighlight>
编辑 NetworkManger.conf,将ifupdown中的managed设置为false,如下所示:
+
Edit NetworkManger.conf and set the value of "managed" under "ifupdown" to false:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
[ifupdown]
 
[ifupdown]
Line 81: Line 85:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
再将网络设置加入 /etc/network/interfaces 即可:
+
Add network setting to /etc/network/interfaces:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
$ sudo vi /etc/network/interfaces
 
$ sudo vi /etc/network/interfaces
 
</syntaxhighlight>
 
</syntaxhighlight>
  
/etc/network/interfaces文件内容如下:
+
Here is is sample of /etc/network/interfaces:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
# The loopback network interface
 
# The loopback network interface
Line 101: Line 105:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
===方法2:使用NetworkManager设置===
+
===2: Setup Static IP with NetworkManager===
下面我们将以有线网络为例,介绍如何配置静态IP地址。<br />
+
Here is an example demonstrating how to setup a static IP with NetworkManager in a wired network<br />
先通过命令看一下当前的连接信息:
+
Check netowrk connection:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
pi@Smart4418SDK:~$ sudo nmcli connection show
 
pi@Smart4418SDK:~$ sudo nmcli connection show
Line 110: Line 114:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
上面的输出信息中,可以看到有个名称为Wired connection 1的有线连接,接下来用以下命令更改Wired connection 1为静态IP地址:
+
The above messages show that there is a wired connection named "Wired connection 1". You can set a static IP for "Wired connection 1" by running the following commands:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
sudo nmcli connection modify 'Wired connection 1' connection.autoconnect yes ipv4.method manual ipv4.address 192.168.2.199/24 ipv4.gateway 192.168.2.1 ipv4.dns 192.168.2.1
 
sudo nmcli connection modify 'Wired connection 1' connection.autoconnect yes ipv4.method manual ipv4.address 192.168.2.199/24 ipv4.gateway 192.168.2.1 ipv4.dns 192.168.2.1
 
sudo reboot
 
sudo reboot
 
</syntaxhighlight>
 
</syntaxhighlight>
上例中,更新有线网络为静态IP, 地址为192.168.2.199,网关和DNS为192.168.2.1。
+
If this is successful the connection will be assigned a static IP with IP address to be 192.168.2.199 and both gateway and DNS to be 192.168.2.1
  
== NetworkManager的卸载==
+
==Uninstall NetworkManager==
NetworkManager虽然方便,但如果你还是觉得传统的 wpa_supplicant 网络管理方式更顺手,你可以通过以下方式卸载NetworkManager:<br />
+
If you still prefer to use a traditional utility such as wpa_supplicant you can uninstall your NetworkManager by running the following commands<br />
 
<br />
 
<br />
创建一个脚本文件例如 rmnm.sh:  
+
Create a script named rmnm.sh:  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
$vi rmnm.sh
 
$vi rmnm.sh
 
</syntaxhighlight>
 
</syntaxhighlight>
  
脚本内容如下:
+
Here is a sample:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
#!/bin/bash
 
#!/bin/bash
Line 150: Line 154:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
然后执行脚本:  
+
Run this script:  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
$chmod 755 rmnm.sh
 
$chmod 755 rmnm.sh
Line 156: Line 160:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
完成后重启即可。<br />
+
Reboot your board.<br />
 +
 
 +
==Disable WLan if Wired/Cable Network is available==
 +
Please refre to: https://superuser.com/questions/233448/disable-wlan-if-wired-cable-network-is-available
  
==其他参考资料==
+
==Resources==
 +
For more details refer to: [https://wiki.archlinux.org/index.php?title=NetworkManager_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&mobileaction=toggle_view_desktop NetworkManager]<br />
 +
[https://ubuntu.com/core/docs/networkmanager/configure-wifi-connections configure-wifi-connections]<br />
  
更详细的NetworkManager使用指南可参考这篇文章: [https://wiki.archlinux.org/index.php?title=NetworkManager_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)&mobileaction=toggle_view_desktop NetworkManager]<br />
+
==Update Log==
 +
===June-18-2017===
 +
* Released English Version

Latest revision as of 11:05, 22 October 2024

查看中文

1 Introduction to NetworkManager

The NetworkManager is a utility to check network status and manage network connectivity. It can be used to manage both wireless and wired network.
The NetworkManager has a commandline utility nmcli, a commandline based GUI nmtui, and an X-Windows based GUI nm-connection-editor.

2 Images with NetworkManager

All the image files of Linux variants(Debian and Ubuntu) developed by FriendlyElec have this utility. This utility works with the following FriendlyElec boards:

2.1 Board Model

S5P4418 Based Boards:
NanoPi2 / NanoPC-T2 / NanoPi-S2 / Smart4418 / NanoPi2-Fire / NanoPi-M2 / NanoPi-M2A
S5P6818 Based Boards:
NanoPC-T3 / NanoPC-T3T / NanoPi-M3
Allwinner SoC Based Boards:
NanoPi-M1 /NanoPi-NEO /NanoPi-NEO-Air / NanoPi-M1-Plus / NanoPi-NEO2 / NanoPi-M1-Plus2 / NanoPi-NEO-Plus2 / NanoPi-NEO-Core / NanoPi-Duo

2.2 Applicable OS

Debian 8.x jessie (for S5P4418 and S5P6818 only)
Ubuntu core xenial 16.04.x (for all FriendlyElec's nano boards)
These OS images include those based on armhf and aarch64.

3 Setup WiFi Connection with NetworkManager

3.1 Commandline Utility (nmcli)

Command to Check WiFi:

  • Check Device List
$ sudo nmcli dev

Note: if a device's status is unmanaged it means this device is not accessed by the NetworkManager and you need to clear the settings under /etc/network/interfaces and reboot.

  • Start WiFi
$ sudo nmcli r wifi on
  • Scan Surrounding WiFi Hotspots
$ sudo nmcli dev wifi
  • Connect to WiFi Hotspot
$ sudo nmcli dev wifi connect "SSID" password "PASSWORD"

The "SSID" and "Password" need to be replaced with your actual WiFi's SSID and password.
If a connection is successfully established your board will be automatically connected to your specified WiFi on system reboot.

  • Disconnect WiFi
$ sudo nmcli dev disconnect wlan0
  • If there are mutiple active WiFi devices you can specify your expected WiFi device by using the ifname option in the following command. For example if you want to operate wlan1 you can do it this way:
sudo nmcli device wifi connect "ssid" password "password" ifname wlan1

3.2 Commandline Based GUI(nmtui)

nmtui is a curses based GUI. You can start it by running the following command:

$ sudo nmtui

For more details refer to "man nmtui".

3.3 Operations with Windows Utility

Under Debian there are two options to start a Windows utility:

Option 1: you can click on the network icon on the bottom right of the task bar. After you click on it a NetworkManger menu will pop up and all the available networks will be listed. If there is an active wireless network you will see something similar to the following screenshot:

NetworkManagerIcon

You can click on a WiFI AP and connect your board to it.

Option 2: you can go to Preferences -> Network Connections and enter the following window:

NetworkManangerMenu

4 Setup Static IP

4.1 1: Setup Static IP Manually

You can setup a static IP manually without using the NetworkManager:

sudo vi /etc/NetworkManager/NetworkManager.conf

Edit NetworkManger.conf and set the value of "managed" under "ifupdown" to false:

[ifupdown]
managed=false

Add network setting to /etc/network/interfaces:

$ sudo vi /etc/network/interfaces

Here is is sample of /etc/network/interfaces:

# The loopback network interface
auto lo
iface lo inet loopback
 
# network interface not managed by Network Manager
allow-hotplug eth0
iface eth0 inet static
address 192.168.2.199
netmask 255.255.255.0
gateway 192.168.2.1
dns-nameservers 192.168.2.1

4.2 2: Setup Static IP with NetworkManager

Here is an example demonstrating how to setup a static IP with NetworkManager in a wired network
Check netowrk connection:

pi@Smart4418SDK:~$ sudo nmcli connection show
NAME                UUID                                  TYPE            DEVICE 
Wired connection 1  cffa785e-0425-3777-b670-092c79328a1f  802-3-ethernet  eth0

The above messages show that there is a wired connection named "Wired connection 1". You can set a static IP for "Wired connection 1" by running the following commands:

sudo nmcli connection modify 'Wired connection 1' connection.autoconnect yes ipv4.method manual ipv4.address 192.168.2.199/24 ipv4.gateway 192.168.2.1 ipv4.dns 192.168.2.1
sudo reboot

If this is successful the connection will be assigned a static IP with IP address to be 192.168.2.199 and both gateway and DNS to be 192.168.2.1

5 Uninstall NetworkManager

If you still prefer to use a traditional utility such as wpa_supplicant you can uninstall your NetworkManager by running the following commands

Create a script named rmnm.sh:

$vi rmnm.sh

Here is a sample:

#!/bin/bash
 
apt-get --yes --force-yes remove --auto-remove --purge network-manager
apt autoremove -y
 
cat >/etc/network/interfaces <<INTERFACEEOL
source-directory /etc/network/interfaces.d
 
auto lo
iface lo inet loopback
 
allow-hotplug wlan0
iface wlan0 inet dhcp
        wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
INTERFACEEOL
 
cat >/etc/network/interfaces.d/eth0 <<ETH0EOLB
auto eth0
    iface eth0 inet dhcp
    hwaddress 76:92:d4:85:f3:0f
ETH0EOLB

Run this script:

$chmod 755 rmnm.sh
$ sudo ./rmnm.sh

Reboot your board.

6 Disable WLan if Wired/Cable Network is available

Please refre to: https://superuser.com/questions/233448/disable-wlan-if-wired-cable-network-is-available

7 Resources

For more details refer to: NetworkManager
configure-wifi-connections

8 Update Log

8.1 June-18-2017

  • Released English Version