SSH to virtual System

Discussions related to using VirtualBox on Linux hosts.
Post Reply
nigromante
Posts: 3
Joined: 10. Jun 2021, 19:38

SSH to virtual System

Post by nigromante »

Hi. The local host is fedora 34

And I have a virtual machine with ubuntu server 16.04

I want to do a ssh from local host to conect ubuntu server 16.04 but is not working...Example

Local host -------------ssh nigromante@127.0.0.1----------Virtual Machine
Fedora 34 --------------------------------------------------------->Ubuntu 16.04
ip: 127.0.0.1---------------------------------------------------------ip:127.0.0.2------(I change the ip with ifconfig option)


I dont know if i'm making a mistake.

In virtual box i have Bridge Adapter active....I know is possible with NAT.....Remember that in ubuntu 16.04
I will make a simple html page and in the local host i will try to call it with the browser. Somethin like this

local host -----------------127.0.0.2/index.html---------virtual machine
firefox ------------------------------------------------------> /var/www/index.html
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: SSH to virtual System

Post by scottgus1 »

127.0.0.1 is a "fake" IP address which stands for the loopback address, which allows a computer to always be able to network with itself. 127.0.0.2 is not a real IP address, to the best of my knowledge.
nigromante wrote:In virtual box i have Bridge Adapter active
See Virtualbox Networks: In Pictures: Bridged Adapter. If your host PC had an active normal wired Ethernet network connected to it, the VM should have gotten an IP address in the same IP range, provided no configuration was done inside the VM OS. You could use that IP address to contact the VM.

Now that fixed IP addresses are being used (and possibly invalid IP addresses), we need to reset stuff.

Did your VM get an IP address from the LAN when your VM was attached to Bridged? Were you Bridging to a wired adapter or Wi-Fi (see the link re Wi-Fi)? Was the physical adapter connected?
fth0
Volunteer
Posts: 5668
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: SSH to virtual System

Post by fth0 »

FWIW, all IPv4 addresses in the 127.0.0.0/8 network (127.0.0.1 - 127.255.255.254) are loopback addresses. IPv4 packets with a loopback destination address are not allowed to be forwarded to another host, so they are confined to the host where they were created. All major OSs have a loopback interface, which usually gets the first loopback address 127.0.0.1 assigned. Since there is rarely a practical use case of more than one loopback interface, you don't often see the other loopback addresses. If you're curious, google for 127.0.53.53. ;)
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: SSH to virtual System

Post by scottgus1 »

Fascinating. So they're all not allowed....

There you go, nigromante, the use of 127.0.0.2 for the VM's IP address is invalid, and you'll have to reset the network settings.
nigromante
Posts: 3
Joined: 10. Jun 2021, 19:38

Re: SSH to virtual System

Post by nigromante »

Thanks for your answer.

What I do is reinstall all ubuntu 16.04 32 bits in virtual box. I install the packages
-Openssh server
- lamp server
I dont install yet apache2.

This is the schema, i trhink is correct

local_host---------ssh nigromante@127.0.0.1-------------------->virtualBox (With bridge adapter)--->wlo1
fedora34--------------------------------------------------------------------Ubuntu 16.04
ip:127.0.0.1----------------------------------------------------------------ip:127.0.0.1
netmask:255.0.0.0-------------------------------------------------------netmask:255.255.255.0
-
_____________________________________________________________________________________________
[localhost-fedora34]: ifconfig

eno1: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether 38:ea:a7:fa:f2:d2 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 252 bytes 28139 (27.4 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 252 bytes 28139 (27.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

wlo1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.0.52 netmask 255.255.255.0 broadcast 192.168.0.255
inet6 fe80::5be8:5289:ae60:68b1 prefixlen 64 scopeid 0x20<link>
ether a4:17:31:91:bb:49 txqueuelen 1000 (Ethernet)
RX packets 924146 bytes 1067841341 (1018.3 MiB)
RX errors 0 dropped 4 overruns 0 frame 0
TX packets 338354 bytes 34250207 (32.6 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
-
______________________________________________________________________________________
[virtualbox-ubuntu 16.04]: ifconfig
ifconfig-ubuntu 16.04.png
ifconfig-ubuntu 16.04.png (9.21 KiB) Viewed 2486 times
______________________________________________________________________________________


This is the default configuration. I dont touch anything. And I try this commands

bridged adapter in wlo1

ssh nigromante2@127.0.0.1
message error_1: ssh: connect to host 127.0.0.1 port 22: Connection refused

ssh nigromante2@10.0.2.15
message error_2: ssh: connect to host 10.0.2.15 port 22: Connection timed out


bridged adapter in eno1

ssh nigromante2@10.0.2.15
message error_2: ssh: connect to host 10.0.2.15 port 22: Connection timed out

ssh nigromante2@127.0.0.1
ssh: connect to host 127.0.0.1 port 22: Connection refused

___________________________________________________________________________

For if someone ask I do a ping 8.8.8.8 in the virtualbox.

eno1
From 10.0.2.15 icmp_seq=1 Destination Host Unreachable

wlo1
From 10.0.2.15 icmp_seq=1 Destination Host Unreachable

__________________________________________________________________________
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: SSH to virtual System

Post by scottgus1 »

Thanks for the info!

These IP addresses:
nigromante wrote:local_host---------ssh nigromante@127.0.0.1-------------------->virtualBox (With bridge adapter)--->wlo1
fedora34--------------------------------------------------------------------Ubuntu 16.04
ip:127.0.0.1----------------------------------------------------------------ip:127.0.0.1
are the loopback addresses mentioned above.

Your host IP address is actually the host wlo1 Wi-fi adapter's 192.168.0.52 The VM's IP address is the enp0s3 adapter's 10.0.2.15 (when connected via NAT) or a 192.168.0.### address from the host's LAN when Bridged, if Bridged can work while you're on Wi-Fi, see the "network pictures" link above.

If you use NAT, you must open ports in the NAT's Port Forwarding button, see the link, for the host to talk to the VM (though the host cannot ping the VM, because ping does not have a port to open). Then you would ask the host to talk to the VM through 127.0.0.1:VMportnumber

If you use Bridged and your VM Bridges to your Wi-Fi adapter correctly, then you can talk to the VM on the VM's 192.168.0.### IP address.

If you cannot get Bridged to work, try wired Ethernet for the host.
nigromante
Posts: 3
Joined: 10. Jun 2021, 19:38

Re: SSH to virtual System

Post by nigromante »

Thanks very much.

I connect the laptop via ethernet instead of wifi. It is working.
I had to change /etc/network/interfaces.

and write these lines:
auto enp0s3
iface enp0s3 inet dhcp

and then use this command: sudo service networking restart

Is there no way to connect via wifi with bridged adapter?
Or i have to change something in the switch-router?
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: SSH to virtual System

Post by scottgus1 »

nigromante wrote:Is there no way to connect via wifi with bridged adapter?
The linked "network pictures" tutorial covers this. Did you read it?
Post Reply