22

So I'm trying to give a VM a static IP address, this case has been particularly stubborn.

The VM is running on a ESXi cluster with its own public IP range.

I had it (sorta) working with an IPv4 address, except it would be reassigned every boot, now after fiddling with nmcli I can't get any IPv4 address assigned to it.

The interface is ens32 and I've changed ipv4.addresses to XXX.XXX.120.44/24 (want it to have address 120.44), gateway to XXX.XXX.120.1 and set it to manual.

Does anyone have any insights to why this isn't working? all the online guides are for the older network service not NetworkManager.

guntbert
  • 1,597
  • 1
  • 17
  • 23
Space Bear
  • 323
  • 1
  • 2
  • 5

3 Answers3

33

Try:

# nmcli con add con-name "static-ens32" ifname ens32 type ethernet ip4 xxx.xxx.120.44/24 gw4 xxx.xxx.120.1
# nmcli con mod "static-ens32" ipv4.dns "xxx.xxx.120.1,8.8.8.8"
# nmcli con up "static-ens32" iface ens32

Next, find the other connections and delete them. For example:

# nmcli con show
NAME         UUID                 TYPE           DEVICE
ens32        ff9804db5-........   802-3-ethernet --
static-ens32 a4b59cb4a-........   802-3-ethernet ens32
# nmcli con del ens32

On the next reboot, you should pick up the static-ens32 connection, as it is the only one available.

garethTheRed
  • 33,289
  • 4
  • 92
  • 101
  • I am trying to do this from the raw starting point of a fresh installation, which requires a somewhat different sequence of commands. Are you willing to show how to do this from scratch with a fresh installation of CentOS 7? Here is the link: http://unix.stackexchange.com/questions/349607/nmcli-commands-for-static-ip-networking-in-centos-7 – CodeMed Mar 06 '17 at 23:03
0

An individual IPv4 address is /32. /24 designates a network, which in this case would be XXX.XXX.120.[0-255]. Try changing the ipv4.address entry to XXX.XXX.120.44/32 and see what happens. If that doesn't work, I have to then ask the same question asked in comments - is NetworkManager a requirement, or can we configure the address using other means?

John
  • 16,759
  • 1
  • 34
  • 43
0

Changing /32(single) to /24(network) fixed my problem with ipv4.addresses assigning range and first ip address.

I think "manual" could be a problem in your case. Manual may tell nm to not manage at all, or not handle dhcp. Have you tried "shared", and then ipv4.addresses rather than ipv4.address1? Or, if manual, then ipv4.address1 might be correct instead of ipv4.addresses.

Have you looked in /var/log/syslog? dnsmasq said in mine that 32 was too small, and nmcli reported back "too small" in the error output.

BobDodds
  • 31
  • 3