Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I've got several VMs set up here, all running linux (mostly centos but 1 ubuntu). I connect to them over SSH, but it's annoying having to go back to the VM server to check on IP addresses. Also, on reboot they usually get a different IP due to the network setup here, which I have no control over.

What's the easiest way for me to track all the IPs that my VMs are using?

share|improve this question

5 Answers 5

up vote 1 down vote accepted

Is it a requirement that you use bridge mode, versus NAT mode? Cause of course if you have NAT enabled, then you could forward various different ports for your ssh access, and the IP (and of course port) would remain constant through reboots.

You can find details on this in the VirtualBox 3.1.2 user manual, section #6.3.1 "Configuring port forwarding with NAT".

Another thought: I cannot help but notice that my IP address shows up in my virtual machine's XML file:

    <GuestProperty
        name="/VirtualBox/GuestInfo/Net/0/V4/IP"
        value="10.0.2.15" timestamp="1261587087753023000"
        flags=""/>

(On linux, you can find this in ~/.VirtualBox/Machines/MyVMName/MyVMName.xml)

So especially if you are using vboxmanage to start/stop your VMs, you could grep the machine's xml and update "something" -- like a web page, or a text file? -- so you'd always know the IP address of each VM. I'm guessing this will work regardless of whether you're using NAT or bridged networking, though I haven't personally tried it...I have a static IP in my VM. I don't know who/when/where this value gets updated in the XML file. Presumably VBox updates it when it detects a DHCP reply it needs to redirect to the VM.

share|improve this answer

A lot of your options depend on your exact network configuration. Most of the easy options involve some network modification, which you indicate is not the case. Here are some options given that constraint:

  • If you use a Microsoft DHCP server integrated with Active Directory, then you may be able to register the hostname with the Active Directory, and inherit a DNS name. Check out http://www.centos.org/docs/5/html/Deployment%5FGuide-en-US/s1-dhcp-configuring-client.html I believe that DHCP_HOSTNAME needs to be set. I've never actually done this, so there may be additional steps to make this work within a Microsoft context (perhaps having all the machines joining the domain, etc).
  • If your looking for a pure Linux solution, you may want to look at the avahi daemons. It uses multicast DNS to push hostnames and services on a local network. Assuming avahi is running on all your boxes, you should be able to edit /etc/nsswitch.conf, verify that mdns4 or mdns4_minimal is included on the hosts line, and should be able to resolve the hostname for all your servers directly. Again, I've not set this up in a production environment, so there might be other configuration that is required.

Both of these are pretty messy, so your much better off working with whomever manages your network to get static IPs and DNS names, as Chopper3 mentions. You might even be able to get away with static DHCP assignments, and then modify the hosts files, but again requires cooperation of your network team.

share|improve this answer
    
+1 to everything said here. Absent any possibility of cooperation from your netops team, I'd say that mDNS is probably going to be your least-worst option. –  womble Dec 30 '09 at 2:15
    
I wish I could mark more than 1 item as accepted answer - this is a great solution... both this and the NAT solution work. –  Jonathan Haddad Feb 5 '10 at 22:42

Setup a cronjob that makes a wget to a .php file that tells the hostname of the machine and the ip and you done.

share|improve this answer
    
I would only get it at boot time, but yeah, good idea. –  David Mackintosh Dec 30 '09 at 1:49

When the machines get an IP address via DHCP on the network, do they not get DNS as well? eg. you should be able to connect to them via their hostname, which would stay static.

You could run all the virtual machines within their own "Virtual Network" and run your own DHCP/DNS/router which connects to the real network, but you'd still need your network admin to add route/dns forwarding which he might not like.

The other way of doing it, and which would leave you in some control, would be to cheat and use one of those external dns services. eg:

dyndns.org is a free service that lets you have a static hostname that gets mapped to a dynamic IP address. They also have a tonne of clients for various OS's to keep this upto date. Usually, you'd have this set to an external address (eg your home router) so you can just remember myhouse.dyndns.org rather than 87.42.80.0 or whatever its changed to recently.

In your situation, I would do similar for each of your virtual machines. Set yourself up an account and get a hostname for each machine. Install the client tell them to keep updates. So you end up with myvirt1.dyndns.org and it points to 192.168.x.x or whatever IP you've just been given.

-saying that, could you not just ask your network admin for a block of static address's?

share|improve this answer

Static IP's and a text editor

share|improve this answer
    
I don't have the option to use static IPs, as I mentioned above. –  Jonathan Haddad Dec 29 '09 at 23:48
    
Ah, sorry, kind of misread/musunderstood that. –  Chopper3 Dec 30 '09 at 1:02

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.