Lab 1 static IP addressing
1 Change From dhcp leased address to static address
Changing a Centos vm from dhcp leased address to static using nmcli
The following instructions are for a subnet 192.168.111.0 Replace the ip address as needed
cd /etc/sysconfig/network-scripts sudo cp ifcfg-ens3 ifcfg-ens34.original cat ifcfg-ens3 ip -4 addr nmcli connection nmcli device
Rename the connection to something easier, like ens3 to match the device:
nmcli connection modify Wired\ connection\ 1 connection.id ens3
Change the connection's ip address
nmcli connection modify ens3 ipv4.addr "192.168.111.12"
Confirm the connection
cat ifcfg-Wired-connection_1= or =cat ifcfg-ens3
Add a gateway to ens3
nmcli connection modify ens3 ipv4.gateway 192.168.111.1
Check the existing ip address
ip -4 addr
Add the netmask (can do it in one step on the ip address)
nmcli connection modify ens3 ipv4.addresses 192.168.112.12/24
This next one is not needed.
nmcli connection modify ens3 ipv4.netmask 255.255.255.0 * so not needed # nmcli connection modify ens3 ipv4.dns "8.8.8.8 8.8.4.4"
Add the dns server (leave it as the same as the default gw)
nmcli connection modify ens3 ipv4.dns 192.168.111.1
Finally, change the ipv4.method to manual (and not dhcp)
nmcli connection modify ens3 ipv4.method manual
Check how the file has changed
cat ifcfg-Wired_connection_1
Already done
nmcli c mod ens3 ipv4.dns 192.168.111.1 # let host resolve for guest VMs
View connections (all)
nmcli connection
Delete any old connections no longer needed
nmcli connection delete eth0
Confirm what devices you have, and which ones are active
nmcli device
See what ifcfg-* files you have
ls -lt
Check the ip addresses (they should still be the old addresses from dhcp)
ip -4 addr
restart the network to have the static addresses take effect
nmcli network off
and back on
nmcli network on
Check the ip addresses again. Now they should be the static ones.
ip -4 addr
Confirm you have internet acccess
ping -c 3 -n cbc.ca