[SOLVED] Set NAT port forwarding in config file

sclarckone

New Member
Jan 21, 2018
3
0
1
54
Hello there,

I'm running a Windows Server VM on Promox v5 in a NAT network configuration (I only have 1 public IP address) and I need to forward some ports from the Proxmox Host to my Windows Guest.

I thought it would be simpler to do it through Qemu rather than iptables but I'm new to KVM/Qemu and it took me a lot of time to figure it out... Anyway, I've finally found that I can do it by adding the 'hostfwd' option to the command used to start my VM. For instance, to forward TCP and UDP ports 3389 for RDP:
Code:
-netdev 'type=user,id=net0,hostname=myhostname,hostfwd=tcp::3389-:3389,hostfwd=udp::3389-:3389'

It works but I can't find a way to add it to the configuration file of my VM (the one located in /etc/pve/qemu-server/), so that I would be able to launch the VM with port forwarding from the Proxmox web front (I didn't find anything in here).

Does anyone know how to specify this option in the Qemu configuration file?

Thanks!
 
Thanks for the tip!

But I must do it wrong because if I add the following line in the configuration file:
Code:
args: -netdev 'type=user,id=net0,hostname=myhostname,hostfwd=tcp::3389-:3389,hostfwd=udp::3389-:3389'

Then when I try to start the VM Proxmox complains that id 'net0' exists twice for 'netdev', and if I remove the id it logically complains that the 'id' parameter is missing for netdev

I don't know how the 'netdev' argument gets generated in the first place (I haven't declared it in this configuration file and didn't find any other configuration file apart from the exact same file under /etc/pve/nodes/myhostname/qemu-server/, even though it doesn't seem that one is a (sym|hard)link of the other).

Is there any way to "append" the 'hostfwd' option to the existing 'netdev' argument?

If it matters: there's already a 'net0:' line in my configuration file but if I try to add the 'hostfwd' options to it like this:
Code:
net0: virtio=BE:C5:2D:EA:07:0C,hostfwd=tcp::3389-:3389,hostfwd=udp::3389-:3389

Then qemu complains that 'hostfwd' exists twice:
Code:
root@myhostname:~# qm show 100
vm 100 - unable to parse value of 'net0' - duplicate key in comma-separated list property: hostfwd
 
you have to remove the 'net0' part in the config, because if you define a netdev in the args you already have the network device
 
  • Like
Reactions: sclarckone
OK, the 'net0' part was used by a 'device' argument to create the emulated network interface so it didn't work if I just removed it. I managed to get it working by adding the 'device' argument to the 'args' option too:
Code:
args: -netdev 'type=user,id=net0,hostname=myhostname,hostfwd=tcp::3389-:3389,hostfwd=udp::3389-:3389' -device 'virtio-net-pci,mac=BE:C5:2D:EA:07:0C,netdev=net0,bus=pci.0,addr=0x12,id=net0,bootindex=300'

Thanks again!
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!