Score:0

How to connect to VM from another computer in the local network

cc flag

I have a host system (running Debian 11) where I installed a virtual machine (Ubuntu 22.04) using KVM. I can ssh between host and VM using their IPs (192.168.122.1 and 192.168.122.230). I also can ssh between the host and other computers in my network using their local IPs (let say 123.123.123.123 for the host).

What I want to do now is to assign a port (8001) to the VM and be able to connect directly to it (i.e. with login first into the host). Something like this:

ssh -p 8001 [email protected]

I tried setting up iptables to assign the port 8001 to the VM ip

iptables -t nat -A POSTROUTING -s 192.168.122.0/24 -o eno1 -j SNAT --to 123.123.123.123
iptables -t nat -A PREROUTING -p tcp -d 123.123.123.123 --dport 8001 -i eno1 -j DNAT --to-destination 192.168.122.230:22

This strategy had worked for me using other virtualization tools (openvz) but I can make it work with KVM. Is there any steps I'm missing? Thank you so much in advance!!

us flag
Did you also configure ssh daemon to listen to a different port? In my system it's `grep "Port " /etc/ssh/sshd_config #Port 22`. If this is not what you're looking for, please clarify what exactly doesn't work.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.