How to Setup Static IP on CentOS 7?

I am working on setting my own CentOS image that I could use quickly with any sort of things that I want to learn for example install LAMP on CentOS. In this quest the next thing I want to do is setup a static IP. I am adopting @fernandoaleman‘s guide for CentOS 6 here.

Basically, we want to make changes to following three files. Remember on my system I am using ifcfg-enp0s3 and you are responsible for finding interface for your system. Also remember that VirtualBox by default uses NAT for VMs but NAT is limited to the VM but we want to access is beyond the VM. We have two other options Bridged connection or Host Only. Bridged will directly work with your network card and make it available to every terminal in your network whereas Host-only will only allow the access to the host. We want to use Bridged connection so that we can use multiple devices for our virtual server.

/etc/sysconfig/network was empty on my system so I had to just append to the file.

/etc/sysconfig/network-scripts/ifcfg-enp0s3 will require us to change ONBOOT, BOOTPROTO and add IPADDR and NETMASK. See the following example.

The last part of the puzzle is to change the DNS servers in /etc/resolv.conf. You could use either Google’s DNS or OpenDNS as follows.

You can either restart the VM or restart the network.

Source