3

I am currently working on a project that involves three independent modules running on three separate machines (currently done in 3 different VMs) that all must talk to each other. An annoyance that I'm running into is that when I transfer the VMs to a different computer or to a different network, the VMs acquire different IP addresses than what has been hardcoded into each module.

I feel that there has to be an easier, more portable way to do this. Is it possible to assign each VM an alias IP in, say, the 10.0.0.x subnet and refer to them by that address instead of their actual 192.168.1.x address? Each VM and the host is running Ubuntu 9.04 64-bit.

Thanks in advance, Dave McClelland

Edit: Copying my /etc/network/interfaces file instead of commenting it below -- it got mangled

auto eth0

iface eth0 inet dhcp

iface eth0:0 inet static
address 192.168.14.21
network 192.168.14.0
netmask 255.255.255.0
broadcast 192.168.14.255
gateway 192.168.14.1

2 Answers 2

5

Edit /etc/network/interfaces:

iface eth0 inet static
  address 192.168.0.10
  network 192.168.0.0
  netmask 255.255.255.0
  broadcast 192.168.0.255
  gateway 192.168.0.1

Change to suit your preferred network subnet/settings.

To make an alias on the DHCP'd eth0:

# The primary network interface
auto eth0
iface eth0 inet dhcp
iface eth0:0 inet static
      address 192.168.0.10
      network 192.168.0.0
      netmask 255.255.255.0
      broadcast 192.168.0.255
      gateway 192.168.0.1

Bring the interface up:

$ sudo ifup eth0:0
$ ifconfig eth0:0
eth0:0    Link encap:Ethernet  HWaddr 00:0c:29:b0:fe:76  
          inet addr:192.168.0.10  Bcast:192.168.0.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:19 Base address:0x2000 
4
  • With this, will I also be able to use the automatic interfaces that detect what network I'm on and set up proper internet access as well as keep the alias that I set up? Aug 27, 2009 at 18:32
  • Updated with an alias interface, see the interfaces(5) man page for more information on options you can set in the file.
    – jtimberman
    Aug 27, 2009 at 18:35
  • I know this shouldn't be so complicated, but the following isn't working: auto eth0 iface eth0 inet dhcp iface eth0:0 inet static address 10.0.0.100 network 10.0.0.0 netmask 255.255.255.0 broadcast 10.0.0.255 gateway 10.0.0.1 After I edit the file, I run sudo /etc/init.d/networking restart, but the new interface does not show up. Any thoughts? Aug 27, 2009 at 19:00
  • Don't bother trying to decipher the file in the comment. I edited my OP and added the interfaces file Aug 27, 2009 at 19:04
0

I ran into the same thing in Ubuntu. Just because you edit the interface file to hardcode the IP doesn't stop the DHCP client from leasing a new IP.

sudo /etc/init.d/dhcp stop

Once you see that is working, you can remove the DHCP client for good so it doesn't come back:

sudo apt-get remove dhcp3-client
2
  • 1
    I did this and now I lost all networking in the VM as well as internet access, so I can't even use apt-get to reinstall dhcp3-client :-\ Aug 27, 2009 at 19:17
  • @CoverosGene -- BAD! It does stop it, if you change the type from dhcp to static.
    – Codebling
    May 10, 2012 at 20:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .