Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

How do I setup ssh from the host to the guest using qemu? I am able to use port redirection when I boot the VM without any special parameters, as follows:

/usr/bin/qemu-system-x86_64 -hda ubuntu1204 -m 512 -redir tcp:7777::8001

But when I try to boot using the following:

/usr/bin/qemu-system-x86_64 \
-m 1024 \
-name vserialtest \
-hda ubuntu1204 \
-chardev socket,host=localhost,port=7777,server,nowait,id=port1-char \
-device virtio-serial \
-device virtserialport,id=port1,chardev=port1-char,name=org.fedoraproject.port.0 \
-net user,hostfwd=tcp:7777::8001

I get the following error and the VM does not boot:

qemu-system-x86_64: -net user,hostfwd=tcp:7777::8001: invalid host
forwarding rule 'tcp:7777::8001'
qemu-system-x86_64: -net user,hostfwd=tcp:7777::8001: Device 'user'
could not be initialized

Please note that I am able to boot the VM without the -net parameter without any issues, however, I want to setup ssh from the host to the guest. ssh from guest to host works fine as expected.

Edit

I have tried using

-net user,hostfwd=tcp::7777-:8001

as well as

-net user,hostfwd=tcp::7777:8001

but still the error persists and the VM does not boot.

share|improve this question
add comment

2 Answers

I think that the error does not come from the -net statement, but from:

-chardev socket,host=localhost,port=7777,server,nowait,id=port1-char

The statement uses already the port 7777. For the port forwarding, with

-net user,hostfwd=tcp::7777-:8001

it works fine when not setting up the virtio serial channel.

If I understand right, you want to set up a virtio serial channel to communicate from the host to the VM using a Unix Domain Socket?

In this case, the following could do the job:

/usr/bin/qemu-system-x86_64 \
-m 1024 \
-name vserialtest \
-hda ubuntu1204 \
-chardev socket,path=/tmp/port1,server,nowait,id=port1-char \
-device virtio-serial \
-device virtserialport,id=port1,chardev=port1-char,name=org.fedoraproject.port.0 \
-net user,hostfwd=tcp::7777-:8001

EDIT:

An example of how to connect from the host using ssh to the VM:

-net user,hostfwd=tcp::10022-:22
-net nic

This hostforwarding maps the localhost (host) port 10022 to the port 22 on the VM. Once the VM was started like this, you can access it from the localhost as follows:

ssh vmuser@localhost -p10022

The -net nic command initializes a very basic virtual network interface card.

share|improve this answer
    
Yes, you are right, I am trying to use virtio-serial to establish communication from host to guest. The VM has booted giving a warning at the host console: Warning: vlan 0 with no nics but when I do ifconfig on the guest I see only lo and I still get ssh: connect to host 10.0.2.15 port 22: Connection timed out when I try to ssh; the IP I used to ssh is 10.0.2.15, which according to man qemu-system-x86_64 is the IP assigned to the first VM booted if static IP is not assigned. And now there is no internet connection on the guest. –  Jobin Apr 15 at 8:06
    
What you might want to do is to map the port 22 used for ssh on another port and then connect to it from the host machine to access the VM. I edited my answer with an example. –  mas_kur1 Apr 15 at 13:23
add comment

I believe you need to use hostfwd=tcp::7777-:8001 or hostfwd=tcp::7777:8001

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.