Since kvm-86, there's a handy new monitor command which allows you to set up host to guest port redirection on the fly. Once caveat though is that these commands are only supported in user networking mode, otherwise known as slirp. This is the default mode of networking when running qemu-kvm so if you haven't setup any other type of networking, you're probably running in this mode. Previously, the only other way of setting up host to guest port redirection was using a command line option ( -redir ) which is much less flexible since it is a one time setup during startup. This procedure was described in an older post. We'll do a quick demonstration so you can test it out yourself.
Start your qemu-kvm process in default networking mode and connect to your monitor. As an example, let's say that you want to setup port forwarding for ssh from your host to your guest then you would issue the follwoing command in your monitor. In the following example, I use 222 on the host machine because ssh port is already used by the host. You can use any other free port on the host, I just used 222 for easy association with port 22.
(qemu) host_net_redir tcp:222::22
Note that if you don't specify the protocol, tcp will be used by default. This means that you can also use the following command.
(qemu) host_net_redir :222::22
Now you can connect to your localhost machine ( assuming you're connecting from the same machine) as follows
ssh -p 222 -l root localhost
This command provides much more flexibility than the older way of port mapping at kvm startup. There have been some additional patches submitted by Alexander Graf which should be included in the next release which will support listing and removing current port mapping entries.
Comments
Post new comment