星期四, 5月 23, 2019

nmcli NMCLI






Ethernet:

  • sudo nmcli  c add autoconnect yes save yes type ethernet ifname eth0 con-name jeth ip4 192.168.2.210/24 gw4 192.168.2.1 
  • sudo nmcli c mod jeth ipv4.addresses "192.168.2.210/24"
  • sudo nmcli c mod jeth ipv4.gateway 192.168.2.1
  • sudo nmcli c mod jeth ipv4.dns 168.95.1.1 
  • sudo nmcli c mod jeth ipv4.method manual
  • sudo nmcli con up jeth
  • nmcli connection show
  • modify
    • sudo nmcli con modify jeth ipv4.address "192.168.1.198/24"
    • sudo nmcli con mod jeth ipv4.gateway 192.168.1.201
    • sudo nmcli con up jeth
Wifi:
  • sudo nmcli con add autoconnect yes save yes con-name jwifi ifname wlan0 type wifi ssid iSSA_ASUS_50_2.4G
  • sudo nmcli con mod jwifi wifi-sec.key-mgmt wpa-psk
  • sudo nmcli con mod jwifi wifi-sec.psk 54098542   
  • sudo nmcli con up jwifi  (很多秒)
  • nmcli connection show
  • Modify
    • sudo nmcli con mod jwifi wifi.ssid iSSA_ASUS_50_2.4G
    • sudo nmcli con mod jwifi wifi-sec.psk 54098542 
Extend:
  • sudo nmcli c reload jack
  • nmcli -p con show my-con-em1
  • Example 1. Listing available Wi-Fi APs
    • nmcli device wifi list  ( Signal Bar)
    • nmcli -f all dev wifi list ( All Signal Bar)
  • Example 2. Showing general information and properties for a Wi-Fi interface
    • nmcli -p -f general,wifi-properties device show wlan0



Renew eth0 connection status, if incorrect:

  • nmcli dev | grep "ethernet"


Dispatcher: put in /etc/NetworkManager/dispatcher.d/70-wifi-wired-exclusive.sh 
#!/bin/bash
export LC_ALL=C

enable_disable_wifi ()
{
    result=$(nmcli dev | grep "ethernet" | grep -w "connected")
    if [ -n "$result" ]; then
        nmcli radio wifi off
    else
        nmcli radio wifi on
    fi
}

if [ "$2" = "up" ]; then
    enable_disable_wifi
fi

if [ "$2" = "down" ]; then
    enable_disable_wifi
fi
      

nmcli dev show eth0|grep CARRIER|tr -s ' '|cut -d ' ' -f2

沒有留言: