0. Goals
- manage network on Ubuntu without GUI.
- which kind of network type
- ethernet
- wifi
The topic is useful for developer who want develop a linux application, for example snap application in ubuntu.
1. Network Manager On Ubuntu
Use the NetworkManager to manage the network device and connections. NetworkManager can manage network types:
- ethenet
- wifi
- mobile boardband(WWAN)
- PPPoE device for VPN
2. Usage Of NetworkManager
2.1 Install NetworkManager
1 | # a. find the application |
when execute the command c the output looks like:
1 | name: network-manager |
we can find that the network manager command-line interface(nmcli) will be installed. the nmcli is key command what is used to manage network. If you wan to learn more about nmcli, you can use nmcli help command.
2.2 Manage WIFI
1 | # check whether the wifi is open |
Other wifi configuration:
- powersave option(0: default, 1: ignore, 2: disable, 3: enable)
1
nmcli c modify <name> 802-11-wireless.powersave 2
2.3 Manage Ethernet
before modify the Ethernet, backup the contents of /etc/netplan is a best practice.
1 | # check whether support enthernet by network manager |
after the reboot, you can edit the ethernet with nmcli. There two way to midfy the ethernet:
- interactive console: print/set/save
- connection modify command
We choose the second way because it can be warpped as shell script or api.
1 | # list all connection |
You can get usage detail by executing nmcli connection modify help, looks like below:
1 | Usage: nmcli connection modify { ARGUMENTS | help } |
3. Program
- python-networkmanager: Easy communication with NetworkManager
- dbus-network-manager: A node.js API to interact with NetworkManager via DBus. This is currently extremely new and incomplete