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 ------------------------ NETWORKING=yes HOSTNAME=centos6 GATEWAY=192.168.1.1
/etc/sysconfig/network-scripts/ifcfg-enp0s3 will require us to change
BOOTPROTO and add
NETMASK. See the following example.
DEVICE="enp0s3" NM_CONTROLLED="yes" ONBOOT=yes HWADDR=A4:BA:DB:37:F1:04 TYPE=Ethernet BOOTPROTO=static NAME="System enp0s3" UUID=5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03 IPADDR=192.168.1.44 NETMASK=255.255.255.0
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.
/etc/resolv.conf -------------------- # Google IPv4 nameservers nameserver 220.127.116.11 nameserver 18.104.22.168
You can either restart the VM or restart the network.
systemctl restart network