3
  • My local Lubuntu's wifi IP address is 192.168.1.97

  • A remote Lubuntu's wifi IP address is 192.168.1.198,

  • A virtual machine running on the remote Lubuntu has IP address 192.168.122.169.

I can access the virtual machine from my local machine, indirectly by ssh to the remote by ssh t@192.168.1.198, and then ssh to the virtual machine by ssh t@192.168.122.169.

I can access the local machine from the virtual machine, directly by ssh t@192.168.1.97.

Because of the routing table on my local Lubuntu, I can't access the virtual machine directly from my local machine

$ ssh t@192.168.122.169
ssh: connect to host 192.168.122.169 port 22: No route to host

Can I access the virtual machine directly from my local Lubuntu?

  • Do I have to modify the routing tables of my local Lubuntu and the remote Lubuntu?

  • Can NAT help?

Thanks.

The routing table on the local Lubuntu is

$ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.1.1     0.0.0.0         UG    600    0        0 wlx801f02b5c389
172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 docker0
192.168.1.0     0.0.0.0         255.255.255.0   U     600    0        0 wlx801f02b5c389
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0

The routing table on the remote Lubuntu is

$ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.1.1     0.0.0.0         UG    600    0        0 wlp5s0
192.168.1.0     0.0.0.0         255.255.255.0   U     600    0        0 wlp5s0
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0

The routing table on the virtual machine is:

$ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.122.1   0.0.0.0         UG    0      0        0 ens3
169.254.0.0     0.0.0.0         255.255.0.0     U     1000   0        0 ens3
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 ens3
  • 1
    IMHO this is a question about networking rather than about Unix or Linux. You either bridge the network interface on the VM (so it shares the same address range as the host) or forward across the NAT. See for example Introduction to Networking Modes in particular the "VM←Net/LAN" column of Table 6.1 – steeldriver Mar 28 at 12:51
  • I am using kvm. – Tim Mar 28 at 12:54
  • AFAIK the principle is the same regardless of the particular VM platform - if you believe that is not the case, please edit your question to make that clear. – steeldriver Mar 28 at 12:56
3

Use ProxyJump or ProxyCommand.

Add this to your ~/.ssh/config:

Host vmhost
    User t
    Hostname 192.168.1.198

Host vm
    Hostname 192.168.122.169
    User t
    ProxyJump vmhost

or for older versions of ssh instead ProxyJump vmhost:

ProxyCommand ssh -q -W 192.168.122.169:22 vmhost

Connect using:

ssh vm
  • Thanks. Is there a solution which is no ssh specific? – Tim Mar 28 at 12:35
  • This should work for scp and ssh. But for general routing, you somehow need to setup a proxy on the vm host. – pLumo Mar 28 at 12:36
  • Thanks. How do you setup a proxy on the vm host? – Tim Mar 28 at 12:40
  • Sorry, don't know how to do it. Maybe network bridge is enough. Might be worth a second question. – pLumo Mar 28 at 12:48
  • Is the way in your reply called SSH local port forwarding, or something else? – Tim Mar 28 at 12:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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