How to assign static IP to Ubuntu Server (VirtualBox)
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
Then configure Host-only Adapter setting for Network Adapter 2
After that manual IP address assignment
Here don't enable the DHCP server as below
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 .
Related videos on Youtube
mr_incredible
Updated on September 18, 2022Comments
-
mr_incredible over 1 year
Please see my setup here:
NAT is set up here:
Host-only adapter is enabled here:
network for virtual box is configured here:
then I set up interface on the server like this:
then I run
sudo netplan apply
and I should be all set. I can ping myself on the server:but can't ping the server from my local computer:
Hence the network isn't actually connected to the Internet. What am I doing wrong here ?
update:
network connection is now set to "bridged":
-
John Ronald about 4 yearsYou can either set the network connection to Bridged or set port forwarding on host computer.
-
mr_incredible about 4 yearsI've set connection to "bridged" but it didn't help.
-
John Ronald about 4 yearsIf you did so, your IP address should change and should be in the same network as hosted computer. Is that right ?
-
mr_incredible about 4 yearsWell ... 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 about 4 yearsI know this setup should work hence I created a thread here.
-
John Ronald about 4 yearsWhat IP does have your host PC ?
-
mr_incredible about 4 yearsIt'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 about 4 yearsLet us continue this discussion in chat.
-