How to assign static IP to Ubuntu Server (VirtualBox)

9,734

The answer is Yes if you assign a static ip from your router for your virtual box virtual machine. (This need specific ip address from your local router).

The answer is No if you aren't assign a static ip from your router for your virtual box virtual machine.

If not how can we access the virtual machine via our laptop terminal ?

This is the method how to do that !

Keep in mind this is temporary method and all settings are reset after you restart the virtual machine . This will also enable internet access on your virtual box sever.

According to your question ,

First configure NAT (Network Address Translation) setting for Network Adapter 1

NAT Configuration

Then configure Host-only Adapter setting for Network Adapter 2

Host-only Adapter configuration

After that manual IP address assignment

Manual ip address assignment

Here don't enable the DHCP server as below

enter image description here

These are the settings for your server virtual machine hardware (assume that your are using a Ubuntu server virtual machine) !

After that install the Ubuntu server on the virtual hard disk ...

After you log on to the Ubuntu server (i think you provided administrative credentials ) , you have to do the followings.

First issue the following command to see the ip settings assigned for network adapters on the virtual Ubuntu server

 ubuntu@vagrant:~$ ifconfig

On my test server there are eth0 , eth1 network interface cards , I have selected eth1 for this because eth0 is already assigned with an ip address by system default.

On Ubuntu server switch to the root user as ,

 ubuntu@vagrant:~$ sudo -i

Then the appear root user prompt as below ,

 root@vagrant:~#

Then issue the following command

 root@vagrant:~# ifconfig eth1 192.168.188.101 netmask 255.255.255.0

Once you done this exit from the root user by typing exit

Here don't turn off the virtual machine !

Then minimize the virtual machine and fireup a local terminal

After that issue ifconfig on the local terminal . Here you can see the various network adapters including the host only adaptor.

Then try to ping the ip address of the virtual machine as below

user@user-laptop:~$ ping 192.168.188.101

If this ping is success you can now ssh to the your virtual Ubuntu server as below

user@user-laptop:~ ssh [email protected]

Here you can provide the virtual server password .

So I think this method is worked for you if you are interested .

Share:
9,734

Related videos on Youtube

mr_incredible
Author by

mr_incredible

Updated on September 18, 2022

Comments

  • mr_incredible
    mr_incredible over 1 year

    Please see my setup here:

    NAT is set up here:

    enter image description here

    Host-only adapter is enabled here:

    enter image description here

    network for virtual box is configured here:

    enter image description here

    then I set up interface on the server like this:

    enter image description here

    then I run sudo netplan apply and I should be all set. I can ping myself on the server:

    enter image description here

    but can't ping the server from my local computer:

    enter image description here

    Hence the network isn't actually connected to the Internet. What am I doing wrong here ?

    update:

    network connection is now set to "bridged":

    enter image description here

    • John Ronald
      John Ronald about 4 years
      You can either set the network connection to Bridged or set port forwarding on host computer.
    • mr_incredible
      mr_incredible about 4 years
      I've set connection to "bridged" but it didn't help.
    • John Ronald
      John Ronald about 4 years
      If you did so, your IP address should change and should be in the same network as hosted computer. Is that right ?
    • mr_incredible
      mr_incredible about 4 years
      Well ... no, because I assigned static IP of 192.168.56.102 to the server should share the name network with the host. So the IP of the server is unchanged. But I need the server to have access to the Internet from host. Bridged connection is set but didn't make difference to the virtual machine.
    • mr_incredible
      mr_incredible about 4 years
      I know this setup should work hence I created a thread here.
    • John Ronald
      John Ronald about 4 years
      What IP does have your host PC ?
    • mr_incredible
      mr_incredible about 4 years
      It's 192.168.1.229. Though I'm further now. Machines can ping each other now but the server still doesn't have access to the Internet through host.
    • John Ronald
      John Ronald about 4 years