So you have embarked your journey on Microsoft Azure Platform and have set up multiple virtual machines . Though it is easy to install virtual machines, sometimes new Azure users find it difficult to interconnect two or more virtual machines together.
Consider a simple scenario with multiple virtual machines, where one works as web server and the other as a SQL server, how would you connect both? Here are few ways to achieve this.
- The simplest way to do this is to add hostnames and IPs to your /system32/drivers/etc/hosts file if you are using Windows and on /etc/resolv.conf if you are using Linux. Ideally, deploy your VMs with fixed private IPs to avoid changes, in case they are rebooted or shutdown.
- If both of them are on the same Virtual Network, then just turn off Windows Firewall and they will be able to ping and connect with each other. Or either, you can allow all incoming ICMP traffic in Windows Firewall.
However, using this way the virtual machines will be able to connect with each other by IP Addresses but not directly by name. So, if you want to connect your Website (on VM1) to SQL Server (on VM2), you have to address it by full IP Address, not machine name.
To achieve this type of communication and accessibility, you need to add name resolution services to your network. This can be done by;
- Create and manage a dedicated DNS Server for all virtual machines in your virtual network. Learn more here.
- Deploy your VMs in the same cloud service; this does not require a dedicated virtual network.