1

I have a CentOS 7 Minimal VirtualBox VM that I would like to set a static IP address on. I want to assign the static IP address via a Bash script within the VM (so not using the VirtualBox network interface).

How can this be done?

So far I've tried editing the file : /etc/sysconfig/network-scripts/ifcfg-enp0s8, and putting the below in it (per this question: https://superuser.com/a/365088).

TYPE="Ethernet"
DEVICE="enp0s8"
BOOTPROTO="static"
IPADDR=192.168.100.101
NETMASK=255.255.255.0

But then the network adaptor doesn't restart (service network restart), which after a considerable amount of restarts/resets/trial, and error, and copious Google searches, it seems like it could be dozens of different things.

ip a lists two devices:

  • lo
  • enp0s8

I also have a ifcfg-enp0s3 config file in the sysconfig dir (not sure why).

So, what's a nice, simple, predictable, reliable way of setting a static IP address in CentOS 7 minimal?

Giacomo1968
  • 58,727

1 Answers1

0

Try following:

TYPE=Ethernet
DEVICE=enp0s8
IPADDR=192.168.100.101
NETMASK=255.255.255.0
ONBOOT=yes
NOZEROCONF=yes
USERCTL=no
NM_CONTROLLED=no

I believe your problem is primary in the missing NM_CONTROLLED=no. Except of network restart you may try to set it UP with

ifup enp0s8

You may also need to specify GATEWAY=