Telnet connections from a Hyper-V Ubuntu virtual machine may fail when outbound network traffic is blocked by misconfigured virtual switches, firewall policies, or network settings on Windows Server 2012 R2. This connectivity issue can prevent essential troubleshooting and remote access tasks. Below are detailed methods to identify and resolve the problem, ensuring your Ubuntu VM can successfully initiate telnet sessions to external hosts.

Check Hyper-V Virtual Switch Configuration

Step 1: Open the Hyper-V Manager on your Windows Server 2012 R2 system. This tool controls all aspects of your virtual machines and their network settings.

Step 2: In the right-hand pane, select Virtual Switch Manager. Review the list of existing virtual switches. Ensure your Ubuntu VM is connected to an External virtual switch, which provides direct access to the physical network, rather than an Internal or Private switch that restricts traffic.

Step 3: If your VM is not connected to an external switch, create one by selecting New virtual network switch and choosing External. Assign the switch to the appropriate network adapter and apply the changes.

Step 4: Shut down the Ubuntu VM if it is running. In the VM settings, attach the newly created external switch to the VM’s network adapter. Start the VM and verify network connectivity.


Verify Windows Firewall Rules

Step 1: From the Windows Server 2012 R2 desktop, open Windows Firewall with Advanced Security via the Control Panel or by running firewall.cpl.

Step 2: Check inbound and outbound rules for the Hyper-V virtual switch and the network adapter used by your Ubuntu VM. Confirm that there are no rules blocking outbound TCP traffic (especially on port 23, which telnet uses).

Step 3: If necessary, create a new outbound rule to allow TCP traffic from the VM subnet or specific IP address range. Select New Rule > Port > TCP > Specific local ports: 23, then allow the connection and specify the appropriate profiles.

Step 4: Apply the changes and test telnet connectivity from the Ubuntu VM to an external host.


Configure Ubuntu Network Settings

Step 1: Log into your Ubuntu VM. Verify the network interface is configured to use DHCP or has a valid static IP address in the correct subnet. Use the command:

ip addr

Step 2: Test basic network connectivity by pinging an external IP, such as ping 8.8.8.8. If ping fails, the issue may be with the VM’s network configuration or the Hyper-V switch.

Step 3: If you have a static IP, ensure the correct gateway and DNS servers are set in /etc/network/interfaces or /etc/netplan/*.yaml (depending on your Ubuntu version). Restart networking with:

sudo systemctl restart networking

Step 4: Once basic connectivity is verified, attempt a telnet connection to an external server:

telnet example.com 23

If the connection still fails, proceed to the next troubleshooting step.


Test Telnet from Windows Host

Step 1: On the Windows Server 2012 R2 host, open a Command Prompt and attempt to telnet to the same external server. If telnet is not installed, enable it by running:

dism /online /Enable-Feature /FeatureName:TelnetClient

Step 2: Run:

telnet example.com 23

Step 3: If telnet fails from the host as well, the issue may be with the external network or ISP. If it succeeds, but fails from the Ubuntu VM, the problem is isolated to the VM or Hyper-V network configuration.


Disable Ubuntu Firewall Temporarily

Step 1: Ubuntu systems may have ufw (Uncomplicated Firewall) enabled by default. Temporarily disable it to check if it is blocking outbound telnet connections:

sudo ufw disable

Step 2: Retry the telnet command. If it works, adjust your firewall rules to allow outbound connections on port 23, then re-enable the firewall:

sudo ufw allow out 23/tcp
sudo ufw enable

Step 3: Only leave the firewall disabled for troubleshooting; always re-enable it with the correct rules in place.


Additional Troubleshooting Steps

Step 1: Verify that the destination server is accepting telnet connections on port 23. Some modern servers disable telnet for security reasons.

Step 2: If you are behind a corporate firewall or proxy, consult your network administrator to confirm outbound port 23 is permitted.

Step 3: Consider using alternative connectivity tools such as SSH (ssh user@host) if telnet is not required by your workflow.


Resolving telnet connectivity issues from a Hyper-V Ubuntu VM on Windows Server 2012 R2 usually involves checking virtual switch settings, firewall rules, and network configurations. Following these steps should restore outbound telnet functionality and streamline your troubleshooting process.