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 googling, 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?

  • 1
    The answer you linked to is correct. – Ramhound Sep 09 '17 at 19:12
  • [ipcfg-en0s3](https://stackoverflow.com/questions/25003419/how-to-configure-internet-on-centos-installation-on-virtualbox) – Ramhound Sep 09 '17 at 19:50
  • @Ramhound - That may be the "correct" answer, but I'm afraid it's not a working answer. Sure, if I do `ip a` it reports that enp0s8 is on my new, desired IP address, and I can ping that address from the client itself, but the host machine can't access it. And as noted above, in this configuration, `service network restart` returns FAILED, although I've just got rid of that by simply deleting the ifcfg-enps03 file. I still can't externally connect to the client despite being able to on the old address before the change. (And firewalld is stopped). – linux_confusion Sep 09 '17 at 21:35
  • Neither the answer linked nor [RHEL Documentation](https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Networking_Guide/sec-Editing_Network_Configuration_Files.html#sec-Configuring_a_Network_Interface_Using_ifcg_Files) has quoted values. Did you try your configuration without quotes? – sebasth Sep 10 '17 at 06:57
  • @sebasth - the file that already exists (and thus shipped with CentOS) has quote marks. However I've tried both with and without and they make no difference. – linux_confusion Sep 10 '17 at 08:34

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=

Jaroslav Kucera
  • 1,492
  • 9
  • 14