share
Unix & Linuxhow to set static ip on cento 7 in virtualbox and make it internet facing
[-1] [2] Jack
[2020-04-15 12:13:23]
[ centos virtualbox ]
[ https://unix.stackexchange.com/questions/580199/how-to-set-static-ip-on-cento-7-in-virtualbox-and-make-it-internet-facing ]

I have decided to install the cento OS via virtual box in my dedicated windows online server which i am accessing it through RDP. I have 5 ipv4 attached to the windows server.

My ipconfig file output is below:

Windows IP Configuration


Ethernet adapter Ethernet:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::5964:102:b4ca:d22%12
   IPv4 Address. . . . . . . . . . . : 79.195.157.66
   Subnet Mask . . . . . . . . . . . : 255.255.255.252
   Default Gateway . . . . . . . . . : fe80::219:a9ff:fe80:7400%12
                                       79.195.157.65

Ethernet adapter VirtualBox Host-Only Network:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::d2:24be:d862:14c2%24
   IPv4 Address. . . . . . . . . . . : 192.168.56.1
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . :

Tunnel adapter Local Area Connection* 11:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Tunnel adapter Local Area Connection* 12:

   Connection-specific DNS Suffix  . :
   IPv6 Address. . . . . . . . . . . : 2002:45c3:9d42::45c3:9d42
   Default Gateway . . . . . . . . . : 2002:c058:6301::1

Tunnel adapter isatap.{CE18702E-41F3-4A46-AA41-33647FD7EC47}:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Can anyone guide me how to attach the static ip to the centos virtual box install so that i can make it internet facing server?

During the centos instalation, i have configured the lan network adapter like this:

https://i.imgur.com/GOmjSSX.png

I am not sure whether it will help me achieve the static ip for the centos but my centos vm can't even access the internet.

yum update return unable to access the mirror server

Can anybody point me how to attach the static ip and make the linux internet facing?

Based on your printscreen (imgur) , you've selected Automatic (DHCP), so the IP address would get an IP address from DHCP. Also, use a valid DNS if your router doesn't provide one (by default your gateway has a resolving service running). Valid public DNS servers are 8.8.8.8 or 8.8.4.4 - Valentin Bajrami
Valentin, It seems to be working. My server has only 1 ip, asked a host to provide one more static ip so that i can attach it to centos server. Right now I can only access 1 server at a time, either RDP or centos in a virtualbox. - Jack
[0] [2020-04-15 12:38:17] okwaho

Under virtual box you can also go to file--> host network manager and create another adapter with a static IP, this way you can use them independently or bridge them if need be.


1
[0] [2020-04-15 12:43:14] string_not_found

First of all you should check the VirtualBox config.

  • Stop the new created VM
  • Right click at the top of this VM and select Config...
  • Go to Network
  • In adapter 1, select Bridge adapter.

Later on, login to Centos and modify the following file as root

sudo vim /etc/sysconfig/network-scripts/ifcfg-enp0s3

I like use VIM, but you can use your favourite, editor.

Later inside that file you should change/or add the following fields

BOOTPROTO="static"
IPADDR=<<THE IP YOU WANT>>
GATEWAY=<<YOUR NETWORK GATEWAY IP>>
NETMASK=255.255.255.0
DNS1=8.8.8.8
DNS2=8.8.4.4

Later you can reboot the VM and you should have internet on it


Thanks for the solution. - Jack
Your welcome. Does it work as u expected? - string_not_found
I have tried a little different approach, instead of editing the file via vim, i have done it via nmtui command. Set the connection to Manual instead of automatic and set the static ip. and systemctl restart network. Seems to work. - Jack
2