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?
-
Static IP's and a text editor
Jonathan Haddad : I don't have the option to use static IPs, as I mentioned above.Chopper3 : Ah, sorry, kind of misread/musunderstood that.From Chopper3 -
Setup a cronjob that makes a wget to a .php file that tells the hostname of the machine and the ip and you done.
David Mackintosh : I would only get it at boot time, but yeah, good idea.From adam -
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.
womble : +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.Jonathan Haddad : I wish I could mark more than 1 item as accepted answer - this is a great solution... both this and the NAT solution work.From SteveM -
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.
From Stéphane -
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 than87.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 to192.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?
From MidnighToker
0 comments:
Post a Comment