networking - How to setup communication between virtual machines

07
2014-07
  • Andrey Tykhonov

    Probably my issue is not hard to resolve but I got a stuck.

    I have several LXC containers. One of them has MySQL, RabbitMQ, MongoDB (and several other services) installed and configured. Every other container has running on the board a service which requires MySQL, RabbitMQ, MongoDB and others. Beside that every container communicates (HTTP, sockets) between each other.

    The problem is that IPs of these containers changes. And when this happens I need to change config files on each container. IPs changes because they gets IPs from DHCP server which changes when I move my laptop from one place to another. And this is not the only reason why IPs could be changed. Also I need some IPs to be public, so I will be able to connect from other PC to some container within the same LAN.

    One solution which comes to mind is to bring up and configure dnsmasq (or other local DHCP server) on the host machine, but I'm not sure that that will resolve the issue. And also quite important note: I would like to avoid additional configuration of the host machine.

    Is there any other way to setup communication between virtual machines? How would you resolve such a task?

    Edited: Static IPs for sorry are not suitable for my needs because sometimes I want to bring up the set of containers on the different PCs but within the same LAN.

  • Answers
    Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

    Related Question

    windows - Can't ping network machines by hostname when behind wireless router on university network (only IP)
  • Milind Ganjoo

    I have a TP-LINK wireless router (TL-WR340G) that is connected to my university LAN via an Ethernet cable (which assigns a dynamic IP address to each device connected). My Windows 7 computer is behind this router.

    I often need to ping host names of other computers on the university network. Normally, when I'm directly connected to the LAN, I can do this (for example, ping foobar would return a normal response). However, when I am behind the wireless router and try to ping the same machine, I get no response ("Ping request could not find host..."). Pinging via IP still works, which leads me to believe it has something to do with the university DNS server. For now, I've fixed this problem by adding entries directly to my C:\Windows\System32\drivers\etc\hosts file.

    Maybe I'm guessing wrong, but could it have something to do with the DNS server rejecting the IP address of my computer (which is assigned by my wireless router's DHCP, instead of the university DHCP, as it would be if I were connected directly through Ethernet)?

    I'm wondering if there's a way I could route all requests from my computer through my wireless router in such a way that they all carry the router's assigned WAN IP address (which is basically the university LAN's dynamic IP)?


    UPDATE: Based on @grawity's suggestion below, I did a Wireshark capture while connected to Ethernet, and I discovered that the host name was being searched using NBNS, not DNS (more specifically, WINS, as a quick ipconfig /all on the Ethernet connection revealed. From Wireshark:

    7725    25.952920   (My IP)         (IP Addr of WINS)   NBNS    92  Name query NB FOOBAR<00>
    ...
    7729    25.956152   (IP Addr of WINS)   (My IP)         NBNS    104 Name query response NB (IP Addr of FOOBAR)
    

    And from ipconfig /all:

    Secondary WINS Server . . . . . . : <ip address 1>
    Primary WINS Server . . . . . . . : <ip address 2>
    NetBIOS over Tcpip. . . . . . . . : Enabled
    

    It doesn't look like my router supports setting a WINS server, so I just set it in the Wireless Network Connection properties instead.


  • Related Answers
  • grawity

    In Windows, hostname resolution is generally done using one of four methods:

    1. DNS – the most likely option. Your university's DHCP server provides you with DNS servers and with a default suffix that is automatically appended to all bare hostnames. For example, if you ping foobar, and the DHCP server gave you example.edu, Windows will try foobar.example.edu first.

    2. NBNS aka NetBIOS – this is an obsolete name resolution protocol using broadcasts. It does not work across routers, and it is highly unlikely that it is used in an university network.

    3. WINS – same as NBNS but using a central server. Obsolete in favor of DNS, but still used in some places due to relative simplicity.

    4. LLMNR – a newer Microsoft protocol using multicast packets. I don't know how to use it, but it's unlikely to be the cause, as only Windows Vista and 7 support it.

    To find out whether DNS is being used, connect your computer directly to Ethernet, then run ping hostname. If you see "Pinging hostname.example.edu", then the name was resolved by DNS, and you have to use the "example.edu" suffix.

    A better way to find out which protocol is in use is to run ipconfig/flushdns and nbtstat -R to flush the caches, start a Wireshark capture, and try pinging a valid hostname. (Again, must be connected directly to the Ethernet.)

    When using your own DHCP server, you will have to manually configure Windows to use a DNS suffix. In Control Panel → Network and Sharing Center, click the Change adapter settings item. Right-click your network adapter, select Properties → TCP/IPv4 → Properties → Advanced → DNS, and update "DNS suffix for this connection". Alternatively, configure your router's DHCP server to give the correct suffix.

  • RedGrittyBrick

    Configure either your router or your PC with the IP-address of the University's DNS server. It seems your router may be picking up an IP-address (e.g. via DHCP) but either is not picking up the Universities DNS servers or is not propagating them to your PC by DHCP.

    To find out the addresses, connect a PC directly, open a command prompt and type ipconfig /all and look for "DNS Servers"

    Setting one in your PC is something like Start, Control Panel, Network Connections. then right-click your LAN and choose "Properties" then on the "General" tab, select the "Internet Protocol" and click "properties". You can unselect (*) "Obtain DNS server address automatically" and set a preferred DNS server below.

    It would be better to configure your router to do this but you don't give a make/model and they vary a lot in how you configure them.