Wednesday, March 30, 2016

Redirect ports for Remote Desktop RDP into QEMU / KVM Virtual Machine in Proxmox NAT Mode

I have a virtual machine running Window 7 for a client. I have been trying to allow the client to use their Window 7 machine via remote desktop (RDP). However since I have configured the QEMU / KVM virtual machine in Proxmox using NAT mode networking, the local IP address that is being assigned to the machine is 10.0.2.15 and I have had difficulty figuring out how to allow RDP traffic to connect to the virtual machine.

Since I have spent hours (barely anything useful googling around) trying to figure this out, I hope this may help somebody.

The solution was to REDIRECT the port from the Proxmox hardware node to the VM using the -redir setting.

First you would want to test the concept by typing the following commands into your SSH Shell:

qm set 123 -args "--redir tcp:30889::3389"
qm set 123 -args "--redir udp:30889::3389"

The commands above will redirect both TCP and UDP protocol from the hardware node's port 30889 to the virtual machine's port 3389.

I choose 30889 (different than the default RDP 3389 port) on purpose to show we are redirecting (kind of like port forwarding). Another reason is because I always use non-default ports to prevent brute force attacks (hope to make it more difficult for hackers to guess).

Once you successfully executed the commands above, you should then try to connect via remote desktop. Remember to use port 30889 to connect.

If the above works... then you need to make this option permanent for your hardware node by adding the following line in your QEMU SERVER configuration file:

args: -redir tcp: 30889::3389 -redir udp: 30889::3389

your vm configuration file should be located in:
/etc/pve/qemu-server

Here is the exact content of my configuration file:

args: -redir tcp: 30889::3389 -redir udp: 30889::3389
bootdisk: ide0
cores: 4
ide0: localmd0:123/vm-123-disk-1.qcow2,format=qcow2,size=64G
memory: 8192
name: ihtirqb
net0: e1000={myhiddenmacaddress}
numa: 0
onboot: 1
ostype: win7
sockets: 1

 

3 comments: