Labels

Aws (32) MySQL (20) Aurora (12) Rds (7) DynamoDB (6) Cloudformation (4) Python3 (4) Unix (3) MongoDB (1)

Tuesday, 17 March 2020

first approach to network manager nmcli on Ubuntu 18.04

nmcli - command-line tool for controlling NetworkManager
nmcli is a command-line tool for controlling NetworkManager and reporting network status.
It can be utilized as a replacement for nm-applet or other graphical clients. nmcli is
used to create, display, edit, delete, activate, and deactivate network connections, as
well as control and display network device status.

nmcli connection

   nmcli connection {show | up | down | modify | add | edit | clone | delete | monitor |
                    reload | load | import | export} [ARGUMENTS...]

   NetworkManager stores all network configuration as "connections", which are collections of
   data (Layer2 details, IP addressing, etc.) that describe how to create or connect to a
   network. 
   A connection is "active" when a device uses that connection's configuration to
   create or connect to a network. 

   There may be multiple connections that apply to a device,
   but only one of them can be active on that device at any given time. 
   The additional connections can be used to allow quick switching between different networks and
   configurations.

   Consider a machine which is usually connected to a DHCP-enabled network, but sometimes
   connected to a testing network which uses static IP addressing. Instead of manually
   reconfiguring eth0 each time the network is changed, the settings can be saved as two
   connections which both apply to eth0, one for DHCP (called default) and one with the
   static addressing details (called testing). When connected to the DHCP-enabled network the
   user would run nmcli con up default , and when connected to the static network the user
   would run nmcli con up testing.
nmcli connection show
show [--active] [--order [+-]category:...]
List in-memory and on-disk connection profiles, some of which may also be active if a
device is using that connection profile.
    $ nmcli connection show -a
    NAME               UUID                                  TYPE    DEVICE    
    Infostrada-E8583C  97f17c06-1826-48dd-81ff-9152636ad4b5  wifi    wlp2s0    
    Photobox           290de8c8-27fa-4fc5-abba-9a3444ca92cc  vpn     wlp2s0    
    docker0            3e81e495-e9df-4c24-ad3b-3e17e582cc46  bridge  nm-bridge 
    docker0            efb1aa98-359a-4500-9d40-664be86a8c1b  bridge  docker0   
    virbr0             94e4aa5d-75e6-4f07-856d-3fb9ea0b36f4  bridge  virbr0    
    vpn0               24afeddb-2782-40cb-9aac-815d81861a20  tun     vpn0  
Specify connection
show [--active] [id | uuid | path | apath]
    $ nmcli connection show vpn0 
Output in [1]nmcli connection show vpn0
nmcli connection down
down [id | uuid | path | apath] ID...
Deactivate a connection from a device without preventing the device from further
auto-activation. Multiple connections can be passed to the command.
       Be aware that this command deactivates the specified active connection, but the device
       on which the connection was active, is still ready to connect and will perform
       auto-activation by looking for a suitable connection that has the 'autoconnect' flag
       set. This includes the just deactivated connection. So if the connection is set to
       auto-connect, it will be automatically started on the disconnected device again.
nmcli connection modify
   modify [--temporary] [id | uuid | path] ID {option value | [+|-]setting.property value}...
       Add, modify or remove properties in the connection profile.
       To set the property just specify the property name followed by the value. An empty
       value ("") removes the property value.
nmcli connection add
   add [save {yes | no}] {option value | [+|-]setting.property value}...
       Create a new connection using specified properties.

       You need to describe the newly created connections with the property and value pairs.
       See nm-settings(5) for the complete reference. You can also use the aliases described
       in PROPERTY ALIASES section. The syntax is the same as of the nmcli connection modify
       command.
nmcli connection delete
delete [id | uuid | path] ID...
Delete a configured connection. The connection to be deleted is identified by its
name, UUID or D-Bus path. If ID is ambiguous, a keyword id, uuid or path can be used.
See connection show above for the description of the ID-specifying keywords.
others
nmcli connection edit
Edit an existing connection or add a new one, using an interactive editor
nmcli connection clone
Clone a connection. The connection to be cloned is identified by its name,
nmcli connection monitor
Monitor connection profile activity.
nmcli connection reload
Reload all connection files from disk.
nmcli connection import/export
Import an external/foreign configuration as a NetworkManager

nmcli device

   nmcli device {status | show | set | connect | reapply | modify | disconnect | delete |
                monitor | wifi | lldp} [ARGUMENTS...]

   Show and manage network interfaces.
nmcli device status
$ nmcli device status
DEVICE TYPE STATE CONNECTION
docker0 bridge connected docker0
vpn0 tun connected vpn0
wlp2s0 wifi connected Infostrada-E8583C
virbr0 bridge connected virbr0
nm-bridge bridge connecting (getting IP configuration) docker0
enx00249b2ce06c ethernet unavailable --
veth9172d0b ethernet unmanaged --
lo loopback unmanaged --
virbr0-nic tun unmanaged --
nmcli device show
   show [ifname]
       Show detailed information about devices

    $ nmcli device show
Output [2]nmcli device show
nmcli device set
set [ifname] ifname [autoconnect {yes | no}] [managed {yes | no}]
Set device properties.
nmcli device connect
connect ifname
Connect the device. NetworkManager will try to find a suitable connection that will be
activated
nmcli device modify
modify ifname {option value | [+|-]setting.property value}...
Modify the settings currently active on the device.
nmcli device disconnect
disconnect ifname...
Disconnect a device and prevent the device from automatically activating further
connections without user/manual intervention.
nmcli device delete
delete ifname...
Delete a device.
nmcli device wifi
wifi [list [ifname ifname] [bssid BSSID]]
List available Wi-Fi access points.
    $ nmcli device wifi
    IN-USE  SSID               MODE   CHAN  RATE        SIGNAL  BARS  SECURITY  
    *       Infostrada-E8583C  Infra  112   540 Mbit/s  60      ▂▄▆_  WPA1 WPA2

ENVIRONMENT VARIABLES

   nmcli's behavior is affected by the following environment variables.

   LC_ALL
       If set to a non-empty string value, it overrides the values of all the other
       internationalization variables.

   LC_MESSAGES
       Determines the locale to be used for internationalized messages.

   LANG
       Provides a default value for the internationalization variables that are unset or
       null.

nmcli general

nmcli general {status | hostname | permissions | logging} [ARGUMENTS...]
   Use this command to show NetworkManager status and permissions. You can also get and
   change system hostname, as well as NetworkManager logging level and domains.


    $nmcli general status
    STATE      CONNECTIVITY  WIFI-HW  WIFI     WWAN-HW  WWAN    
    connected  full          enabled  enabled  enabled  enabled 

nmcli networking

nmcli networking {on | off | connectivity} [ARGUMENTS...]
   Query NetworkManager networking status, enable and disable networking.

    $  nmcli networking 
    enabled
    $ nmcli networking connectivity
    full

nmcli radio

nmcli radio {all | wifi | wwan} [ARGUMENTS...]
   Show radio switches status, or enable and disable the switches.

Source

Long output

[1]nmcli connection show vpn0
    $ nmcli connection show vpn0
    connection.id:                          vpn0
    connection.uuid:                        24afeddb-2782-40cb-9aac-815d81861a20
    connection.stable-id:                   --
    connection.type:                        tun
    connection.interface-name:              vpn0
    connection.autoconnect:                 no
    connection.autoconnect-priority:        0
    connection.autoconnect-retries:         -1 (default)
    connection.auth-retries:                -1
    connection.timestamp:                   1584454699
    connection.read-only:                   no
    connection.permissions:                 --
    connection.zone:                        --
    connection.master:                      --
    connection.slave-type:                  --
    connection.autoconnect-slaves:          -1 (default)
    connection.secondaries:                 --
    connection.gateway-ping-timeout:        0
    connection.metered:                     unknown
    connection.lldp:                        default
    ipv4.method:                            manual
    ipv4.dns:                               --
    ipv4.dns-search:                        --
    ipv4.dns-options:                       ""
    ipv4.dns-priority:                      100
    ipv4.addresses:                         10.242.16.122/23
    ipv4.gateway:                           --
    ipv4.routes:                            --
    ipv4.route-metric:                      -1
    ipv4.route-table:                       0 (unspec)
    ipv4.ignore-auto-routes:                no
    ipv4.ignore-auto-dns:                   no
    ipv4.dhcp-client-id:                    --
    ipv4.dhcp-timeout:                      0 (default)
    ipv4.dhcp-send-hostname:                yes
    ipv4.dhcp-hostname:                     --
    ipv4.dhcp-fqdn:                         --
    ipv4.never-default:                     no
    ipv4.may-fail:                          yes
    ipv4.dad-timeout:                       -1 (default)
    ipv6.method:                            link-local
    ipv6.dns:                               --
    ipv6.dns-search:                        --
    ipv6.dns-options:                       ""
    ipv6.dns-priority:                      100
    ipv6.addresses:                         --
    ipv6.gateway:                           --
    ipv6.routes:                            --
    ipv6.route-metric:                      -1
    ipv6.route-table:                       0 (unspec)
    ipv6.ignore-auto-routes:                no
    ipv6.ignore-auto-dns:                   no
    ipv6.never-default:                     no
    ipv6.may-fail:                          yes
    ipv6.ip6-privacy:                       -1 (unknown)
    ipv6.addr-gen-mode:                     stable-privacy
    ipv6.dhcp-send-hostname:                yes
    ipv6.dhcp-hostname:                     --
    ipv6.token:                             --
    tun.mode:                               1 (tun)
    tun.owner:                              123
[2]nmcli device show
    GENERAL.DEVICE:                         vpn0
    GENERAL.TYPE:                           tun
    GENERAL.HWADDR:                         (unknown)
    GENERAL.MTU:                            1287
    GENERAL.STATE:                          100 (connected)
    GENERAL.CONNECTION:                     vpn0
    GENERAL.CON-PATH:                       /org/freedesktop/NetworkManager/ActiveConnection/9
    IP4.ADDRESS[1]:                         10.242.16.122/23
    IP4.GATEWAY:                            0.0.0.0
    IP4.ROUTE[1]:                           dst = 0.0.0.0/0, nh = 0.0.0.0, mt = 50
    IP4.ROUTE[2]:                           dst = 10.242.16.0/23, nh = 0.0.0.0, mt = 50
    IP6.ADDRESS[1]:                         fe80::65fa:d638:6455:2d9a/64
    IP6.GATEWAY:                            --
    IP6.ROUTE[1]:                           dst = ff00::/8, nh = ::, mt = 256, table=255
    IP6.ROUTE[2]:                           dst = fe80::/64, nh = ::, mt = 256

EXAMPLES

This section presents various examples of nmcli usage. If you want even more, please refer
to nmcli-examples(7) manual page.
nmcli -t -f RUNNING general
tells you whether NetworkManager is running or not.
nmcli -t -f STATE general
shows the overall status of NetworkManager.
nmcli radio wifi off
switches Wi-Fi off.
nmcli connection show
lists all connections NetworkManager has.
nmcli -p -m multiline -f all con show
shows all configured connections in multi-line mode.
nmcli connection show --active
lists all currently active connections.
nmcli -f name,autoconnect c s
shows all connection profile names and their auto-connect property.
nmcli -p connection show "My default em1"
shows details for "My default em1" connection profile.
nmcli --show-secrets connection show "My Home WiFi"
shows details for "My Home WiFi" connection profile with all passwords. Without
--show-secrets option, secrets would not be displayed.
nmcli -f active connection show "My default em1"
shows details for "My default em1" active connection, like IP, DHCP information, etc.
nmcli -f profile con s "My wired connection"
shows static configuration details of the connection profile with "My wired
connection" name.
nmcli -p con up "My wired connection" ifname eth0
activates the connection profile with name "My wired connection" on interface eth0.
The -p option makes nmcli show progress of the activation.
nmcli con up 6b028a27-6dc9-4411-9886-e9ad1dd43761 ap 00:3A:98:7C:42:D3
connects the Wi-Fi connection with UUID 6b028a27-6dc9-4411-9886-e9ad1dd43761 to the AP
with BSSID 00:3A:98:7C:42:D3.
nmcli device status
shows the status for all devices.
nmcli dev disconnect em2
disconnects a connection on interface em2 and marks the device as unavailable for
auto-connecting. As a result, no connection will automatically be activated on the
device until the device's 'autoconnect' is set to TRUE or the user manually activates
a connection.
nmcli -f GENERAL,WIFI-PROPERTIES dev show wlan0
shows details for wlan0 interface; only GENERAL and WIFI-PROPERTIES sections will be
shown.
nmcli -f CONNECTIONS device show wlp3s0
shows all available connection profiles for your Wi-Fi interface wlp3s0.
nmcli dev wifi
lists available Wi-Fi access points known to NetworkManager.
nmcli dev wifi con "Cafe Hotspot 1" password caffeine name "My cafe"
creates a new connection named "My cafe" and then connects it to "Cafe Hotspot 1" SSID
using password "caffeine". This is mainly useful when connecting to "Cafe Hotspot 1"
for the first time. Next time, it is better to use nmcli con up id "My cafe" so that
the existing connection profile can be used and no additional is created.
nmcli -s dev wifi hotspot con-name QuickHotspot
creates a hotspot profile and connects it. Prints the hotspot password the user should
use to connect to the hotspot from other devices.
nmcli dev modify em1 ipv4.method shared
starts IPv4 connection sharing using em1 device. The sharing will be active until the
device is disconnected.
nmcli dev modify em1 ipv6.address 2001:db8::a:bad:c0de
temporarily adds an IP address to a device. The address will be removed when the same
connection is activated again.
nmcli connection add type ethernet autoconnect no ifname eth0
non-interactively adds an Ethernet connection tied to eth0 interface with automatic IP
configuration (DHCP), and disables the connection's autoconnect flag.
nmcli c a ifname Maxipes-fik type vlan dev eth0 id 55
non-interactively adds a VLAN connection with ID 55. The connection will use eth0 and
the VLAN interface will be named Maxipes-fik.
nmcli c a ifname eth0 type ethernet ipv4.method disabled ipv6.method link-local
non-interactively adds a connection that will use eth0 Ethernet interface and only
have an IPv6 link-local address configured.
nmcli connection edit ethernet-em1-2
edits existing "ethernet-em1-2" connection in the interactive editor.
nmcli connection edit type ethernet con-name "yet another Ethernet connection"
adds a new Ethernet connection in the interactive editor.
nmcli con mod ethernet-2 connection.autoconnect no
modifies 'autoconnect' property in the 'connection' setting of 'ethernet-2'
connection.
nmcli con mod "Home Wi-Fi" wifi.mtu 1350
modifies 'mtu' property in the 'wifi' setting of 'Home Wi-Fi' connection.
nmcli con mod em1-1 ipv4.method manual ipv4.addr "192.168.1.23/24 192.168.1.1,
10.10.1.5/8, 10.0.0.11"
sets manual addressing and the addresses in em1-1 profile.
nmcli con modify ABC +ipv4.dns 8.8.8.8
appends a Google public DNS server to DNS servers in ABC profile.
nmcli con modify ABC -ipv4.addresses "192.168.100.25/24 192.168.1.1"
removes the specified IP address from (static) profile ABC.
nmcli con import type openvpn file ~/Downloads/frootvpn.ovpn
imports an OpenVPN configuration to NetworkManager.
nmcli con export corp-vpnc /home/joe/corpvpn.conf
exports NetworkManager VPN profile corp-vpnc as standard Cisco (vpnc) configuration.