1. List interfaces:# sudo nmcli device status
Example output:
DEVICE TYPE STATE CONNECTION ens18 ethernet connected Wired connection 1 lo loopback connected (externally) lo2. List current connections:# sudo nmcli connection show
NAME UUID TYPE DEVICE Wired connection 1 be3443b1-e1a3-491b-9eb9-3e8bdb1df0c8 ethernet ens18 lo 2896417b-a577-418d-a45f-3c19b2a33f1e loopback lo3. Check if connection is using DHCP (auto) or not:# sudo nmcli connection show "<CONNECTION_STRING_NAME>" | grep ipv4.methodFor example, if connection name is "Wired connection 1" (use either 'nmcli device status' or 'nmcli connection show' to get actual name):# sudo nmcli connection show "Wired connection 1" | grep ipv4.method
Output if using static IP:ipv4.method: manualOutput if using DHCP autoconfig:ipv4.method: auto
WARNING: Not recommended to do this over a remote session. You'll get disconnected.
You can use this to setup static IP from DHCP or change static IP.Before you begin, you need to have these information ready:
- Valid Connection Name = <CONNECTION_STRING_NAME> (from nmcli)
- Valid IP Address. (0.0.0.0 - 255.255.255.255) = <IP_Address>
- Valid IP Netmask in bits. (0 - 32) <NetMask>
- Gateway IP Address = <GW_IP>
- DNS Server IP 1 = <DNS_1> (required)
- DNS Server IP 2 = <DNS_2> (optional - you do not need to specify second DNS server)
1. Command syntax:# sudo nmcli connection modify "<CONNECTION_STRING_NAME>" ipv4.addresses <IP_Address>/<NetMask> ipv4.gateway <GW_IP> ipv4.dns "<DNS_1> <DNS_2>" ipv4.method manual
Example:# sudo nmcli connection modify "Wired connection 1" ipv4.addresses 192.168.100.1/24 ipv4.gateway 192.168.100.254 ipv4.dns "8.8.8.8" ipv4.method manual
2. Stop the interface.
WARNING: Not recommended to do this over a remote session. You'll get disconnected.
# sudo nmcli connection down "<CONNECTION_STRING_NAME>"NOTE: This command will bring down the interface and disconnect any remote sessions!Example:# sudo nmcli connection down "Wired connection 1"
3. Start the interface.
# sudo nmcli connection up "<CONNECTION_STRING_NAME>"
Example:# sudo nmcli connection up "Wired connection 1"
1. Command syntax:# sudo nmcli connection modify "<CONNECTION_STRING_NAME>"ipv4.method auto
Example:# sudo nmcli connection modify "Wired connection 1" ipv4.method auto
2. Stop the interface.
WARNING: Not recommended to do this over a remote session. You'll get disconnected.
# sudo nmcli connection down "<CONNECTION_STRING_NAME>"NOTE: This command will bring down the interface and disconnect any remote sessions!Example:# sudo nmcli connection down "Wired connection 1"
3. Start the interface.
# sudo nmcli connection up "<CONNECTION_STRING_NAME>"
Example:# sudo nmcli connection up "Wired connection 1"