Introduction
This article aims to help users who are experiencing an issue with SSH connections between two Ubuntu Virtual Machines (VMs) running in VirtualBox. The issue is characterized by incorrect hostnames being displayed during the connection process.
Detailed Situation
In this scenario, we have two Ubuntu VMs named myserver01 and myserver02, both running in VirtualBox. When attempting to SSH from myserver01 to myserver02, the incorrect hostname is displayed:
myserver01$ ssh myserver02
SSH connection refused: connect to host 'myserver01' port 22
Despite the error message displaying the incorrect hostname (myserver01 instead of myserver02), the actual connection is being established between the two VMs.
Possible Causes
There are a few possible reasons for this issue:
- Incorrect Hosts File: The hosts file on the local machine (myserver01) might be causing the incorrect hostname to be resolved.
- VirtualBox Networking: VirtualBox networking settings might be causing the incorrect hostname to be displayed.
Solution: Incorrect Hosts File
To check if the issue is caused by an incorrect hosts file, follow these steps:
- Edit the hosts file on myserver01 using a text editor:
- Make sure the correct IP address and hostname are listed for myserver02:
- Save and close the file.
sudo nano /etc/hosts
192.168.0.10 myserver02
Solution: VirtualBox Networking
To check if the issue is caused by VirtualBox networking settings, follow these steps:
- Open the VirtualBox Manager and select myserver01.
- Click on "Settings" and then "Network" tab.
- Make sure the "Adapter Type" is set to "Internal Network" and the "Name" is set to the correct name for the network.
- Repeat the process for myserver02.
- Restart both VMs.
Conclusion
Incorrect hostnames during SSH connections between Ubuntu VMs running in VirtualBox can be caused by an incorrect hosts file or VirtualBox networking settings. By following the solutions provided in this article, you should be able to resolve the issue and establish correct SSH connections between your VMs.