Files
cmp-docs/docs/progs/nmcli.md
2024-03-02 02:54:33 +03:00

1.6 KiB

NMCli

Connection start

nmcli con up  ens18

Connection modifity

ifc=eth0 \
nmcli con mod $ifc ipv4.addresses 172.16.23.56/24 && \
nmcli con mod $ifc ipv4.gateway   172.16.23.1     && \
nmcli con mod $ifc ipv4.dns       172.16.20.130   && \
nmcli con mod $ifc ipv4.method    manual          && \
nmcli con mod $ifc ipv6.method    disable         && \
nmcli con up  $ifc restart                        && \
true

Disable IPv6 for all

nmcli con show | awk '{if(NR > 1) { print $1; system("nmcli con mod " $1 " ipv6.method disable"); } }'

Connection event

#!/bin/bash

# This is /etc/NetworkManager/dispatcher.d/0167-cmp.sh

# IFACE="$1" # DEVICE_IFACE
# EVENT="$2" # NM_DISPATCHER_ACTION
#					- connectivity-change
#					- down
#					- up
#					- vpn-down
#					- vpn-up
#
#

	if [ "${NM_DISPATCHER_ACTION}" = "connectivity-change"  ]; then
		if [ "${CONNECTIVITY_STATE}" = "FULL" ]; then
			nmcli conn up ssh-37
			exit 0
		fi

		if [ "${CONNECTIVITY_STATE}" = "LIMITED" ]; then
			nmcli conn up ssh-37
			exit 0
		fi

		if [ "${CONNECTIVITY_STATE}" = "NONE" ]; then
			exit 0
		fi

		# exit 0
	fi

	if true; then
		logger -t 0167-cmp.sh @=$@ "ENV" \
			NM_DISPATCHER_ACTION=$NM_DISPATCHER_ACTION \
			CONNECTION_UUID=$CONNECTION_UUID \
			CONNECTION_ID=$CONNECTION_ID \
			CONNECTION_DBUS_PATH=$CONNECTION_DBUS_PATH \
			CONNECTION_FILENAME=$CONNECTION_FILENAME \
			CONNECTION_EXTERNAL=$CONNECTION_EXTERNAL \
			DEVICE_IFACE=$DEVICE_IFACE \
			DEVICE_IP_IFACE=$DEVICE_IP_IFACE \
			CONNECTIVITY_STATE=$CONNECTIVITY_STATE
	fi