How to connect raspberry to WEP encrypted and dhcp enabled Ad-Hoc network - raspbian

I have Three Rasbperry Pi3 and I have configured 2 of them as dhcp enabled ad-hoc network server they are working fine and I can connect to them using Windows PC and Linux PC as well as from Mobile. The dhcp also assigns the 'Laptop, PC and Mobile' the dynamic IP within specified range but when I try to connect from other Raspberry Pi with wpa_supplicant it can't connect to Raspberry Pi hosting ad-hoc network. I am using WEP encryption. My Raspberry Pi are equiped with internal wifi card.
Network Model
#1 Raspberry Pi3 with dhcp enabled ad-hoc
#2 Raspberry Pi3 with dhcp enabled ad-hoc
#3 Raspberry Pi3 is a moving node with managed network mode wpa_supplicant configurations which will connect to the either of those Raspberry Pi's based on which one has good signal strength and quality.
#1 Raspberry Pi with dhcp enabled ad-hoc
I have the following
interface configuration
my /etc/network/interfaces file looks like this
auto wlan0
iface wlan0 inet static
address 192.168.1.1
netmask 255.255.255.0
wireless-channel 1
wireless-essid Node1
wireless-key 6172736869
wireless-mode ad-hoc
dhcp configuration
and my Configuration for /etc/dhcp/dhcpd.conf is
ddns-update-style interim;
default-lease-time 600;
max-lease-time 7200;
authoritative;
log-facility local7;
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.5 192.168.1.150;
}
#2 Raspberry Pi with dhcp enabled ad-hoc
I have the following
interface configuration
my /etc/network/interfaces file looks like this
auto wlan0
iface wlan0 inet static
address 192.168.2.1
netmask 255.255.255.0
wireless-channel 1
wireless-essid Node2
wireless-key 6172736869
wireless-mode ad-hoc
dhcp configuration
and my Configuration for /etc/dhcp/dhcpd.conf is
ddns-update-style interim;
default-lease-time 600;
max-lease-time 7200;
authoritative;
log-facility local7;
subnet 192.168.2.0 netmask 255.255.255.0 {
range 192.168.2.5 192.168.2.150;
}
It is working fine. I can connect anything other than raspberry Pi with wpa_supplicant configuration. I have been working on it from almost 12 days and I tried almost every solution regarding WEP connection with wpa_supplicant and still no chance of connection.
I have the following configuration for
#3 Raspberry Pi3 with wpa_supplicant configuration
wpa_supplicant configuration
my /etc/wpa_supplicant/wpa_supplicant.conf looks like this
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=GB
network={
ssid="IoT-Lab"
psk="12323233"
key_mgmt=WPA-PSK
}
network={
ssid="Node1"
wep_key0="6172736869"
#wep_key0=6172736869
key_mgmt=NONE
}
When I connect to the Node1 it doesn't establish connection but create the the entry in wpa_supplicant.
Then read about removing the wep_key0 quotes and I did that but didn't work
I also read about a lots of tweaks to play with but nothing worked and did each of them but nothing seems to be work.
interface configuration
# interfaces(5) file used by ifup(8) and ifdown(8)
# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
iface eth0 inet manual
allow-hotplug wlan0
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
I also check with interface configuration for wlan0 from manual to dhcp and but it doesn't work. I'll be thankful if you help me out.

Related

Ping between two vm in kvm

I have configured a net with one host ( my computer) and two virtual machines. I don't want to use libvirt now to connect vm to host, so i manually created bridge and two tap interfaces.
Here is the configuration:
vm1 /etc/network/interfaces:
auto lo
iface lo inet loopback
auto enp0s2
iface enp0s2 inet static
address 192.168.50.3
netmask 255.255.255.0
dns-nameservers 8.8.8.8
up ip route add default via 192.168.50.1 dev enp0s2
the same for another one vm2:
auto lo
iface lo inet loopback
auto enp0s2
iface enp0s2 inet static
address 192.168.50.2
netmask 255.255.255.0
dns-nameservers 8.8.8.8
up ip route add default via 192.168.50.1 dev enp0s2
this is host :
auto enp4s0
13 iface enp4s0 inet manual
12
11 auto br0
10 iface br0 inet static
9 address 192.168.50.1
8 netmask 255.255.255.0
7 network 192.168.50.0
6 broadcast 192.168.50.255
5 # gateway 192.168.50.1
4 bridge_ports enp4s0 tap0 tap1
3 bridge_stp off
2 bridge_fd 0
1 bridge_maxwait 0
45 dns-nameservers 8.8.8.8
Host can ping vm and vms can ping host now. But from 192.168.50.3 vm 192.168.50.2 is unreachable. What is the problem here? I have read in "mastering kvm virtualization", that this is enough for getting the connection (ip forwarding is enabled, but this does not matter for bridge, as I understood)
can you try assigning same vlan to both vms xml(config) file ?

cannot connect to internet from virtual machine

I am using Vmware Player to use Ubuntu 14.04 but I am unable to get any internet connection in my virtual machine even though my system is connected to the internet. The original OS in my system is Windows 7. Can anybody suggest the way out.
Found the solution by browsing through multiple threads. Compiling it here.
EDIT : Please check if your network is in bridged mode or not if you are using VMWare/ VirtualBox before following the steps below. Enabling bridge mode and restarting guest OS can resolve the issue.
First check if your network is disabled by using the following cmd in terminal:
sudo lshw -C network
If it shows disabled after the name of your adapter ( note down the logical name for later use)
*-network DISABLED
description: Ethernet interface
product: 82545EM Gigabit Ethernet Controller (Copper)
vendor: Intel Corporation
physical id: 1
bus info: pci#0000:02:01.0
logical name: ens33
All we need to do is enable the adapter, so lets get started.
open up your interfaces file by using the following cmd:
sudo gedit /etc/network/interfaces
My file had the following data written:
auto lo
iface lo loopback
But the logical name of my NIC was ens33 ( not lo), so i changed it to read the following and saved the file.
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
auto wlan0
iface wlan0 inet dhcp
Now time to restart the networking service.
sudo /etc/init.d/networking restart
check if network is back up, it shouldn't have that disabled tag anymore.
sudo lshw -C network
Enjoy your internet :)
If that doesn't work -> But as explained earlier change the network adaptor settings to bridged in your virtual machine settings.
If all that does not work, the best way to resolve the issue is
Restore your VM network settings
If you are using an older version download a new version (trial version would also work) - we are just updating your settings
Follow the steps:
Depending on how you are connected to the network, try either Bridged or NAT mode for the VM's network adapter. Keep in mind that you may lose connectivity from the host machine to the VM. In this case you'll need another network adapter.
In most cases NAT should work. In this case only your host machine's IP is visible to the network, and ports are allocated for the VM to communicate to the outside world. The problem is that you can't connect to the VM from the host machine if you need to. Add another adapter as I mentioned above and connect to its IP address. You will have two adapters - one for the Internet and the other for host-to-guest.
In the bridge mode the VM is visible to the outside network, so a network configuration is required that enables the VM to get an IP address and participate in the network (for example, network administrators may block unknown MAC addresses). The host machine talks with the VM as it were just a computer on the network.
Update your question with additional information if my suggestion does not work: guest OS, how your host computer is connected to the network, what the current configuration of the VM's network adapters is. Is it a home or a workplace computer?
UPDATE
So I guess if you are connected to a corporate LAN, then NAT will work while Bridge will not. To add another interface 1) add an adapter in VMWare Player; 2) Add an interface in Ubuntu. Assuming your existing interface is eth0, edit /etc/network/interfaces, adding these lines:
auto eth1
iface eth1 inet dhcp
Then restart the networking service:
sudo /etc/init.d/networking restart
UPDATE 2
Another reason for your not being able to connect to the Internet may be a proxy server. Make sure that the proxy configuration in the VM is the same as in the host machine.
CLose VM,
Go to VM Settings and Network adapters
Then click on adapter 1 and select Shared Networking NAT.
Start VM

Emulating a virtual host for UDP communication

First of all this question is not about virtual host in Apache.
I have a network with the following address: 1.1.1.0
I have several host on this network: 1.1.1.1, 1.1.1.2, 1.1.1.3 and 1.1.1.4
The first host send a broadcast UDP paquet answer and expect other host to answer him.
Is it possible for my dev machine (1.1.1.4) to emulate the following virtual host : 1.1.1.5, 1.1.1.6, etc. ?
I'm using QUdpSocket from Qt 5.2.1 on MacOS 10.9 but I am open to any other tech that would help me do the trick.
It depends on you OS.
On linux, you can create multiple virtual network devices, and bind each of those devices to a different network address. The virtual network devices have the name of a real device with a :xxx numeric suffix. For example, if your primary network device is eth0, you can run the command
ifconfig eth0:1 1.1.1.5
to create the virtual device eth0:1 and bind it to the address 1.1.1.5. This is only temporary (it will go away when you reboot); if you want it to come back when you reboot, you can edit the `/etc/network/interfaces file to look something like:
auto eth0
iface eth0 inet static
address 1.1.1.4
netmask 255.255.255.0
gateway 1.1.1.1
auto eth0:1
address 1.1.1.5
netmask 255.255.255.0
the lack of a gateway in the eth0:1 part means that it won't use this interface for routing, so it just exists for receiving packets and explicit binding to an ip address.
Install VirtualBox (here) and make a tiny disk image big enough for a small Linux distro. Run several copies, each one at a different IP address and run a tiny netcat script in each one that listens and sends replies.
#!/bin/bash
while :
do
command=$(nc -ul 1234)
process $command and reply
done
Or, read this and go with Chris's idea which is lighter weight on resources!

Configure SQL Connection with jdbc - vagrant

I have a vagrant server:
postgres#precise32:/home/vagrant/teste/pg-hostname-master$ ifconfig
eth0 Link encap:Ethernet
inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0
eth1 Link encap:Ethernet
inet addr:33.33.33.33 Bcast:33.33.33.255 Mask:255.255.255.0
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
The port is:
name | port
setting | 5432
My question is, what is the correct data to use jdbc?
I already tried:
jdbc:postgresql://localhost:5432/test
jdbc:postgresql://33.33.33.33:5432/test
jdbc:postgresql://127.0.0.1:5432/test
None of these works.
org.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
Update:
tcp 0 0 0.0.0.0:5432 0.0.0.0:* LISTEN 1020/postgres
In postgresql.conf
Listen_adresses = '*'
vagrant log
C:\Users\xx>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
[default] Clearing any previously set forwarded ports...
[default] Clearing any previously set network interfaces...
[default] Preparing network interfaces based on configuration...
[default] Forwarding ports...
[default] -- 22 => 2222 (adapter 1)
[default] Booting VM...
[default] Waiting for machine to boot. This may take a few minutes...
DL is deprecated, please use Fiddle
[default] Machine booted and ready!
[default] Configuring and enabling network interfaces...
[default] Mounting shared folders...
[default] -- /vagrant
[default] VM already provisioned. Run `vagrant provision` or use `--provision` to force it
Basically, I need to know how can I set a remote db connection between vagrant (ubuntu) and windows desktop. Both running in the same desktop.
First a disclaimer - I have used virtualbox and postgresql quite a lot, but I have not used vagrant, so advice I can give about that is limited.
From your description and the information in the comments, I think your problem is related to network connectivity between the VM and the host environment.
Virtualbox supports a few different network emulations - eg NAT, Bridged, Internal Network, Host-only. When using vagrant, vagrant will attempt to administer the VM to align to the configuration in the 'vagrantfile'.
The 'NAT' adapter uses a simulated NAT. It is a bit like having the VM on the inside of a private network with a router connecting it to the internet. You can make outgoing connections via the NAT interface but not incoming connections, unless you set up port forwarding. Your vagrant log file says this:
[default] -- 22 => 2222 (adapter 1)
indicating that port 2222 is being forwarded to port 22 on the VM (at least that is how I interpret this printout). This would allow you to connect to the VM via SSH from a client such as putty running in the windows environment. Virtualbox listens on port 22 on the loopback adaptor (127.0.0.1) in the Windows environment, forwarding any connections to the NAT adaptor in the VM.
Your ifconfig shows two ethernet adapters (aside from the loopback) - one configured for address 10.0.2.15 and the other for 33.33.33.33.
10.0.2.15 is the address used by the NAT adaptor.
33.33.33.33 seems to have been configured by the following lines in your vagrantfile:
# Create a private network, which allows host-only access to the machine
# using a specific IP.
config.vm.network :private_network, ip: "33.33.33.33"
So, this is configuring an internal network, probably using a 'host-only' adaptor in virtualbox. The problem is, I suspect that the IP address 33.33.33.33 is not valid for such a network. The default internal network in virtualbox is set up for the network 192.168.56.0/24.
Here are the steps I recommend you follow to resolve this:
Before doing anything else, double check that you can establish a connection to the postgresql server using:
su - postgres
psql -h 127.0.0.1 template1
from a shell on the VM (ie. either log in via ssh or using the VM console). This ensures that postgresql is running and accepting connections from network interfaces.
Confirm that the Virtualbox VM is configured for a host-only adaptor as 'Adaptor 2'. From the virtualbox GUI, select VM -> settings -> Network -> Adaptor 2. It should say 'Host-only adaptor'. Note the name of the adaptor.
Check the configuration of the host only network. From the Virtualbox GUI, File -> Preferences -> Network -> Host-Only Networks -> double click the named network from step 1. Note the IPv4 address and netmask. The defaults for that are 192.168.56.0 and 255.255.255.0.
You should be using a private network.
In your vagrantfile, change the ip address to one that is in the range of the network seen in step 2 - eg. 192.168.56.10. Then restart vagrant using whatever command is needed to get it to reconfigure the VM.
Confirm that you can ping the address you have used from the windows command prompt. Also that you can connect the VM using an SSH client on the windows side, using the same address.
If all of that has worked, you should be able to connect to the postgresql server using jdbc:postgresql://{ipaddr}:5432/test where {ipaddr} is the ip address you used in step 3,4.
First check that you don't have any other VMs running with the same IP. vagrant halt that machine and try to ping "33.33.33.33". It shouldn't respond. (By the way, 33.33.33.x is a public network that somebody own, you should use a private network like 192.168.33.x.)
Also some VPN software can mess up the routing. Are you running any?
The localhost addresses won't work from host, unless you set port forwarding:
Vagrant.configure("2") do |config|
config.vm.network "forwarded_port", guest: 5432, host: 5432
end

How to SSH to a VirtualBox guest externally through a host? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
I have a Ubuntu VM running on my Windows 7 machine. How do I set it up so that I can access the webserver externally through SSH?
I found steps (Setup SSH access between VirtualBox Host and Guest VMs) to be able to ssh to my guest from my host, but that still leaves me with the problem of accessing it through my router.
I suppose that I could install an SSH server on my Windows machine and then tunnel a few times (though I'm not 100% sure what to use in terms of local, dynamic, etc. or how to set up multiple tunnels?), but is there a way to make the VM directly accessible to my router so I could directly port forward to it?
The best way to login to a guest Linux VirtualBox VM is port forwarding. By default, you should have one interface already which is using NAT. Then go to the Network settings and click the Port Forwarding button. Add a new Rule. As the rule name, insert "ssh". As "Host port", insert 3022. As "Guest port", insert 22. Everything else of the rule can be left blank.
or from the command line
VBoxManage modifyvm myserver --natpf1 "ssh,tcp,,3022,,22"
where 'myserver' is the name of the created VM. Check the added rules:
VBoxManage showvminfo myserver | grep 'Rule'
That's all! Please be sure you don't forget to install an SSH server in the VM:
sudo apt-get install openssh-server
To SSH into the guest VM, write:
ssh -p 3022 user#127.0.0.1
Where user is your username within the VM.
Change the adapter type in VirtualBox to bridged, and set the guest to use DHCP or set a static IP address outside of the bounds of DHCP. This will cause the Virtual Machine to act like a normal guest on your home network. You can then port forward.
Keeping the NAT adapter and adding a second host-only adapter works amazing, and is crucial for laptops (where the external network always changes).
http://muffinresearch.co.uk/archives/2010/02/08/howto-ssh-into-virtualbox-3-linux-guests/
Remember to create a host-only network in virtualbox itself (GUI -> settings -> network), otherwise you can't create the host-only interface on the guest.
You can also use a Bridged Network (or "Bridge Adapter", in newer versions) in network settings. This will put your VM in a VLAN with your machine. So you can just ssh into the VM like this.
ssh user#IP_OF_VM
How to do host-only network (better than bridged) for Solaris 10 and Ubuntu 16.04
Add Host-only interface
Virtualbox > File > Preferences > Network > Host-only Networks > Add
Shutdown vm.
VM's Settings > Network. First adapter should be Nat, second Host-only.
Start cmd.exe and run ipconfig /all. You should see lines:
Ethernet adapter VirtualBox Host-Only Network:
...
IPv4 Address. . . . . . . . . . . : 192.168.59.1
Second adapter in guest should also be in 192.168.59.*.
Start VM.
Solaris 10
Check settings ifconfig -a. You should see e1000g0 and e1000g1. We are interested in e1000g1.
ifconfig e1000g down
ifconfig e1000g 192.168.56.10 netmask 255.255.255.0 up
Check from host if this interface is reachable: ping 192.168.56.10
Preserve those settings upon reboot
# vi /etc/hostname.e1000g1
192.168.56.10 netmask 255.255.255.0
# reboot
Configure ssh service (administering) to login as root (not adviced)
Check if ssh is enabled
# svcs -a | grep ssh
online 15:29:57 svc:/network/ssh:default
Modify /etc/ssh/sshd_config so there is
PermitRootLogin yes
Restart ssh service
svcadm restart ssh
From host check it
ssh root#192.168.56.10
Ubuntu 16.04
List interfaces:
ip addr
You should see three interfaces like lo, enp0s3, enp0s8. We will use the third.
Edit /etc/network/interfaces
auto enp0s8
iface enp0s8 inet static
address 192.168.56.10
netmask 255.255.255.0
Then sudo ifup enp0s8. Check if enp0s8 got correct address. You should see your ip:
$ ip addr show enp0s8
...
inet 192.168.56.10/24 brd 192.168.56.255 scope global secondary enp0s8
If not, you may run sudo ifdown enp0s8 && sudo ifup enp0s8
https://superuser.com/questions/424083/virtualbox-host-ssh-to-guest/424115#424115
In order to ssh to a Ubuntu VM running in VirtualBox from your host machine, you need to set up two network adapters for the VM.
First of all, stop the VM if not yet.
Then select the VM and click the Settings menu in the VirtualBox toolbar:
Set up Adapter 1
Set up Adapter 2
(Note: you don't need to set up any port forwarding.)
That's it. Once set up, you can start your VM. In your VM, the network configuration will look like below and you'll have Internet access too:
Also in your host machine, you can ssh to your VM:
Be sure that the SSH server has been installed and up running in the VM.
$ ps aux | grep sshd
root 864 0.1 0.5 65512 5392 ? Ss 22:10 0:00 /usr/sbin/sshd -D
If not, install it:
$ sudo apt-get install openssh-server
Also for your information:
My VirtualBox version: 5.2.6 r120293 (Qt5.6.2), 2018
My Ubuntu version: Ubuntu 16.04.3 LTS
My host machine: Windows 10
SSH Back to Your Home / Office VirtualBox Guest Machine From The INTERNET
The answers provided by other users here : How to SSH to a VirtualBox guest externally through a host?
... helped me to accomplish the task of connecting from out on the internet to my home computer's guest machine. You should be able to connect using computers, tablets, and smart phones (android, IPhone,etc). I add a few more step in case it might be helpful to someone else:
Here is a quick diagram of my setup:
Remote device ---> INTERNET --> MODEM --> ROUTER --> HOST MACHINE --> GUEST VM
Remote device (ssh client) ---> PASS THRU DEVICES ---> GUEST VM (ssh server)
Remote device (leave ssh port 3022) ---> INTERNET --> MODEM --> ROUTER (FWD frm:p3022 to:p3022)--> HOST MACHINE (FWD frm:p3022 to:p22) --> GUEST VM (arrive ssh port 22)
The key for me was to realize that ALL connections was PASSING-THROUGH intermediary devices to get from my remote PC to my guest virtual-machine at home --Hence port forwarding!
Notes:
* Need ssh client to request a secure connection and a running ssh server to process the secure connection.
I will forward the port 3022 as used in the chosen answer from above.
Enter your IPs where needed (home modem/router, host IP, guest IP,etc.), Names chosen are just examples-use or change.
1.Create ssh tunnel to port 3022 on your modem's IP / router's external IP address.
ssh client/device possible commands: ssh -p 3022 user-name#home_external_IP
2.Port forward = we are passing thru the connection from router to host machine
Also make sure firewall /IPtable rules on router is allowing ports to be forward (open if needed)
Router's Pfwd SCREEN required entries: AppName:SSH_Fwd, Port_from: 3022, Protocol:both (UDP/TCP), IP_address:hostIP_address, Port_to:3022, everything else can be blank
DD-WRT router software resources / Info:
DD-WRT Port_Forwarding
DD-WRT Static_DHCP
3.Host Machine Firewall: open port 3022 #so forwarded port can pass thru to guest machine
Host Machine: Install VirtualBox, guest additions, and guest machine if not done already
Configure guest machine and then follow the Network section below
I used VirtualBox GUI to setup guest's network- easier than CLI
If you want to use other methods refer to : VirtualBox/manual/ch06.html#natforward
4.Some suggest using Network Bridge adapter for guest = access to LAN and other machines on your LAN. This also pose an increase security risk, because now your guest machine is now exposed to LAN machines and possibly the INTERNET hackers if firewall not setup properly. So I selected Network adapter attached to NAT for less exposure to bridged security risks.
On the guest machine do the following:
Guest Machine VirtualBox Network settings: Adapter 1: Attached to NAT
Guest Machine VirtualBox Port Forwarding Rule: Name:External_SSH, Protocol:TCP, Host Port: 3022, Guest Port 22, Host&guest IPs:leave blank
click on advance in Network section then click on Port forwarding to enter rules
Guest Machine Firewall: open port 22 #so ssh connection can enter
Guest Machine: Make sure that ssh server is installed, configured properly, and running
LINUX test to see if ssh server running w/command: sudo service ssh status
Can check netstat to see if connection made to port 22 on the guest machine
Also there are different ssh servers and clients depending on platform using.
wikipedia/Secure_Shell
wikipedia/Comparison_of_SSH_servers
wikipedia/Comparison_of_SSH_clients
For Ubuntu Users:
ubuntu community: SSHOpenSSH/Configuring
ubuntu/community: OpenSSH/Keys
That should be it. If I made a mistake or want to add anything -feel free to do so-- I am still a noob.
Hope this helps someone. Good luck!
For Windows host, you can :
In virtualbox manager:
select ctrl+G in your virtualbox manager,
then go to network pannel
add a private network
make sure that activate DHCP is NOT selected
In network management (windows)
Select the newly created virtualbox host only adapter and the physical network card
Right-Click and select "Make bridge"
Enjoy
You can also initiate a port forward TO your HOST, OR ANY OTHER SERVER, from your Guest. This is especially useful if your Guest is 'locked' or can't otherwise complete the ModifyVM option (e.g. no permission to VBoxManage).
Three minor requirements are 1) you are/can log into the VirtualBox Guest (via 'console' GUI, another Guest, etc), 2) you have an account on the VirtualBox HOST (or other Server), and 3) SSH and TCP forwarding is not blocked.
Presuming you can meet the 3 requirements, these are the steps:
On the Guest, run netstat -rn and find the Gateway address to the default route destination 0.0.0.0. Let's say it's "10.0.2.2". This 'Gateway' address is (one of) the VirtualBox Host virtual IP(s).
On the Guest, run ssh -R 2222:localhost:22 10.0.2.2 where "10.0.2.2" is the VirtualBox server's IP address -OR- any other server IP you wish to port forward to.
On the Host, run ssh 10.0.2.2 -p2222 where 10.0.2.2 is the default gateway/VBHost virtual IP found in step 1. If it is NOT the VirtualBox host you are port forwarding to, then the command is ssh localhost -p2222
Follow below steps to login to your ubuntu VM running in virtual box from the host machine using putty (Without port forwarding):
On Virtualbox manager select the vm, click on settings icon. Then go Networks and enable two adaptors as below:
Adaptor 1 (For internet access): Attached to -> NAT, Advanced -> Check the cable connected.
Adaptor 2: Attached to -> Host only adaptor, Advanced -> Check the cable connected and Promiscuous mode -> Allow all.
Start the ubuntu vm.
Login to the VM as root.
Edit the file '/etc/network/interfaces' as below and save it:
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
auto eth1
iface eth1 inet dhcp
Restart the VM.
Login to the VM and run below command to check the IP allocated to eth1:
ifconfig
Use this IP to open putty session for the VM.
A good explanation about how to configure port forwarding with NAT is found in the VirtualBox documents:
http://www.virtualbox.org/manual/ch06.html#natforward
Ubuntu 18.04 LTS
Configuration with bridged to see the server ip, and connect without "port forwarding"
VirtualBox > right click in server > settings > Network > enable adapter 2 > select "bridged" > Promiscuous mode: allow all > Check the cable connected > start server
On ubuntu server, edit sudo nano /etc/netplan/*init.yaml file,
My sample file:
network:
ethernets:
enp0s3:
addresses: []
dhcp4: true
enp0s8:
addresses: [192.168.0.200/24]
dhcp4: no
dhcp6: no
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
version: 2
Commands that will help you
nano /etc/netplan/file.yaml # file to specify the rules of network
reboot now # restart ubuntu server right now
netplan apply # do after edited *.yaml, to apply changes
ifconfig -a # show interfaces with ip, netmask, broadcast, etc...
ping google.com # to see if there is internet
Configure Static IP Addresses On Ubuntu 18.04 LTS Server - with NetPlan
Simply setting the Network Setting to bridged did the trick for me.
Your IP will change when you do this. However, in my case it didn't change immediately. ifconfig returned the same ip. I rebooted the vm and boom, the ip set itself to one start with 192.* and I was immediately allowed ssh access.
On secure networks setting your network to bridge might not work. Administrators could only allow one mac address per port or even worse block the port should the switches detect multiple macs on one port.
The best solution in my opinion is to set up additional network interfaces to handle additional services you would like to run on your machines. So I have a bridge interface to allow for bridging when I take my laptop home and can SSH into it from other devices on my network as well as a host only adapter when I would like to SSH into my VM from my laptop when I am connected to the eduroam wifi network on campus.
Use NAT network adapter and Add port forward. Mention actual host ip.Do not use 127.0.0.1 or localhost.