The below code will query all connections and use grep to find the line of text which includes the “GENERAL.CONNECTION”. That line will be processed and the connection extracted.
device=($(nmcli device show | grep GENERAL.CONNECTION | awk '{ print $2 }'))
Below we’ll use the information to change the DNS settings of the connection.
nmcli connection modify $device ipv4.dns "10.100.0.2"
nmcli connection modify $device ipv6.dns "fd00:64::2"
nmcli connection down $device
nmcli connection up $device
On DNS,DHCP:
Keep in mind that there may be more DNS servers being announced and processed automatically on a network than you initially think there are.