Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm trying to get a Virtualbox instance running with a very specific networking setup.

Here's what I have right now:

I have a laptop running Ubuntu, hosting a Debian Virtualbox. My loptop regularly has dhcp addresses assigned to it's wireless card in either the 192.168.*.*** range or 10.***.***.*** range. I've set up my Debian VB with a bridged network adapter connected to my laptops's wlan0 connection.

The Debian machine always grabs a dynamic address, so if I want to access virtual hosts running on it, or want to ssh into it, I must first run ifconfig to find its ip address.

Here's what I want:

I want to set up the Debian virtual machine with another network adapter on a private network between my laptop and it, that will always have a static ip, no matter what dhcp address my laptop has.

How do I do this?

share|improve this question

migrated from serverfault.com Nov 14 '11 at 2:22

This question came from our site for professional system and network administrators.

2 Answers 2

up vote 11 down vote accepted

Change the virtualbox network settings to Host-only networking and edit the following file in the virtual machine:

 /etc/network/interfaces

You can that change it to have a static IP like this:

iface eth0 inet static
       address 192.168.2.10
       netmask 255.255.255.0
       network 192.168.2.0
       broadcast 192.168.2.255
       gateway 192.168.2.1

Then, you should change the settings for the virtual Network Adaptor in Ubuntu to also have a static IP (192.168.2.1 in this example).

share|improve this answer
    
I've never heard of this virtual network adapter in ubuntu. How do I go about editing it? –  bejonbee Nov 5 '11 at 23:31
    
Don't know by heart. Whats the result from ifconfig? –  Bart De Vos Nov 5 '11 at 23:34
    
Hmm. I have it set up as you suggested. Virtualbox added an entry to my host so ifconfig shows the new network. However, my guest only has the loopback. If I try to add an entry for eth0 I get the error that there's no such device. –  bejonbee Nov 6 '11 at 0:11
1  
After more reading and playing with settings I finally got it. Your settings proved correct. I had used Network Adapter 2, which equates to eth1, not eth0 on the host machine. Once I figure that out it was elementary to get your answer working. Thanks. –  bejonbee Nov 6 '11 at 4:56

If like me, you happen to be on a Redhat based system like CentOS, just edit /etc/sysconfig/network-scripts/ifcfg-eth1 with the following:

DEVICE=eth1
BOOTPROTO=static
IPADDR=192.168.56.101
NETMASK=255.255.255.0

Obviously, I've assigned the static IP to eth1 but you need to change it according to what ifconfig tell you.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.