UbuntuServer 16.04 VirtualBox Machine - Emergency Mode for Network Interfaces - virtual-machine

I'm using a virtual machine with Ubuntu16.04Server O.S. on a Windows host.
Everything was working perfectly but after switching off everything and then coming back to my virtual server, the machine doesn't start.
It shows:
[FAILED] Failed to start Raise network interfaces. See 'systemctl status networking.service' for details.
So the system goes in Emergency mode!
By typing journalctl -xb, I can see the following issue:
...
ifup[1987]: Cannot find device "ens33"
...
ifup[1987]: Failed to bring up ens33.
systemd[1]: netowrking.service: Main process exited, code=exited ....
So I find my failed to start Raise network interfaces
Subject: Unit networking.service has failed
Defined-By: systemd
By typing ifconfig I see only the lo interface. No ens33 is shown.
In my /etc/network/interfaces I have also the 2 rows:
auto ens33
iface ens33 inet dhcp
By typing lshw I have the following output related to the network:
*-network DISABLED
description: Ethernet interfaces
product: 82540EM Gigabit Ethernet Controller
vendor: Intel Corporation
physical id: 3
bus info: pci#0000:00:03.0
logical name: enp0s3
...
...
configuration: autonegotiation=on broadcast=yes driver=e1000 driverversion=7.3.21-k8-NAPI duplex=full.......
So if I run ifup ens33 I have the error
Cannot find device ens33
Error getting hardware address for "ens33": No such device
The virtual machine has the default ethernet card Intel PRO/1000 MT Desktop (82540EM) connected as NAT.
It is completly stuck and I can't go forward, only emergency mode.

Finally found a solution:
The issue should seems to be related to a mismatch of the ethernet card, and my solution was:
changing card on the virtual machine
entering in emergency mode
Editing the /etc/network/interfaces file, by changing the ens33 interface parameters and adding the new eth0 interface:
auto ens33
iface ens33 inet manual
auto eth0
iface eth' inet dhcp
At this point by restarting the network service I could see the interface up.
After it was necessary the editing of the /etc/default/grub file, changing the line from
GRUB_CMDLINE_LINUX=""
to
GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0"
Then I ran following commands:
sudo update-grub
sudo reboot

Related

EtherCAT with SOEM on WSL Ubuntu 18

Has anyone ever tried connecting to an EtherCAT device via SOEM in WSL linux?
While TwinCAT successfully connects to my Maxon EPOS4 and moves a DC motor on my laptop under Windows 10 using RT-Ethernet Intermediate Driver, SOEM slaveinfo returns no slaves found on eth0 under WSL.
Ps. I use an ethernet to usb-c LAN adaptor with my laptop, automatic IP address, Ubuntu 18.04 on WSL 2 with Hyper-V installed, and tested turning off my windows firewall too. I have not used SOEM under windows yet due to compile issues. Initially, I had no socket found on eth0 issue, but it solved after installing hyper-V and upgrading my WSL current installation of Ubuntu-18.04 to WSL 2.
I have the same issue under WSL Ubuntu 20, when the firewall is deactivated, if I disable all TwinCAT services and uninstall the TwinCAT items from the Ethernet Properties window!
Here is what I do and the outputs:
$ sudo setcap cap_net_raw+ep /opt/ros/melodic/bin/slaveinfo
$ sudo /opt/ros/melodic/bin/slaveinfo
SOEM (Simple Open EtherCAT Master)
Slaveinfo
Usage: slaveinfo ifname [options]
ifname = eth0 for example
Options :
-sdo : print SDO info
-map : print mapping
Available adapters
Description : lo, Device to use for wpcap: lo
Description : bond0, Device to use for wpcap: bond0
Description : dummy0, Device to use for wpcap: dummy0
Description : eth0, Device to use for wpcap: eth0
Description : sit0, Device to use for wpcap: sit0
End program
$ sudo /opt/ros/melodic/bin/slaveinfo eth0
SOEM (Simple Open EtherCAT Master)
Slaveinfo
Starting slaveinfo
ec_init on eth0 succeeded.
No slaves found!
End slaveinfo, close socket
End program
Can you elaborate on your Ethernet controllers? Do you have the one USB-C adapter setup with TwinCAT and the RT-Ethernet driver? If so, I would expect that SOEM running in Ubuntu under WSL does not have access to this controller.
I would test on a system without TwinCAT installed, or rollback the TwinCAT RT-Ethernet driver installation so that the Ethernet controller is available to Windows and presumably WSL. Or can you have an additional adapter that isn't available to TwinCAT?
For me on windows eth0 would not work for epos4. I had to write getmac in a console and copy the line
\Device\Tcpip_{------- copy this part ------}.
Then in my code i would write
init_comm("\\Device\\NPF_{--- your copied part ---}");

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

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

Hook up Raspberry Pi via Ethernet to laptop without router? [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 3 years ago.
Improve this question
I'm working on a balloon project with a Raspberry Pi. When we potentially recover the Raspberry Pi, it will most likely be in a rural location and I'd like to turn off the Pi at that point safely.
Without a router or network nearby, I was wondering if there is a way to hook up a Raspberry Pi with an Ethernet cable directly to a laptop?
It's a solution for Ubuntu (the idea also works for Windows or Mac) I just tried today and it works like a charm.
Material
a cross-over Ethernet cable (the name is fancy but it's just a normal Ethernet cable)
a laptop (ubuntu)
a Raspberry Pi (I have the Pi2)
Prerequisites on your ubuntu
Install network-manager
$sudo apt-get install network-manager
Install nmap
$sudo apt-get install nmap
Edit Wired connection on your laptop (Ubuntu)
Change IpV4 settings to "Share to other computers"
Save the setting
Reboot your laptop
Share WiFi connection of your laptop via Ethernet crossover cable
Hook up your RPi with your laptop using the Ethernet cable
Look up the broadcast address of the Ethernet connection (Laptop),
$/sbin/ifconfig eth1 | grep "Bcast" | awk -F: '{print $3}' | awk '{print $1}' 10.42.0.255
Use this address to find out the IP address of your RPi, it's 10.42.0.96 in my case because 10.42.0.1 is my laptop
$nmap -n -sP 10.42.0.255/24
Starting Nmap 6.40 ( http://nmap.org ) at 2016-02-20 23:07 CET
Nmap scan report for 10.42.0.1
Host is up (0.00031s latency).
Nmap scan report for 10.42.0.96
Host is up (0.0023s latency).
Nmap done: 256 IP addresses (2 hosts up) scanned in 2.71 seconds
Login to your RPi from your laptop (-Y with X-forwarding)
$ssh -Y pi#10.42.0.96
Lo and behold! Now your RPi is connected to your laptop and RPi can share the WiFi connection.
pi#raspberrypi ~ $
Share display & keyboard of your laptop with RPi
Install vncserver on Raspberry Pi
$ sudo apt-get update
$ sudo apt-get install tightvncserver
Install vncviewer on your laptop by downloading RealVNC (it supports multiple platforms)
http://www.realvnc.com/download/vnc/
To be able to copy & paste from VNC server <--> VNC viewer, you need to install autocutsel on your RPi.
$sudo apt-get install autocutsel
If this site doesn't work, try to download the .deb directly from a mirror site, e.g.
mirror.hmc.edu/debian/pool/main/a/autocutsel/autocutsel_0.10.0-1_armhf.deb
and install it
$sudo dpkg -i autocutsel_0.10.0-1_armhf.deb
Start vncserver on your RPi (You have to restart vncserver after installing autocutsel, you can issue $vncserver -kill :1)
$vncserver :1
Add autocutsel -fork to /home/pi/.vnc/xstartup
#!/bin/sh
xrdb $HOME/.Xresources xsetroot -solid grey
autocutsel -fork
#x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#x-window-manager &
# Fix to make GNOME work
export XKL_XMODMAP_DISABLE=1
/etc/X11/Xsession
Start vncviewer on your laptop
$vncviewer
A vncviewer window will pop up and type in the IP address of your RPi (given by your laptop) followed by port 1, which is your VNC server. for example: 10.42.0.96:1 in my case.
Connect it to the vncserver hosted on your RPi by typing in a password (set up a password yourself)
12.Now you can see the desktop of RPi on your laptop, and I opened my browser to show the shared WiFi connection is working as well.
See Raspberry Pi desktop on your ubuntu
No router + no screen + regular Ethernet cable + RPI 2 + Raspbian Lite 2018-11-13 + Ubuntu 18.10
First we must enable the SSH server on the Pi, which is disabled by default for security.
If you already have a shell on the Pi through a non-SSH method such as screen + keyboard or UART (see below), just run:
sudo systemctl enable ssh
sudo service sshd start
as explained at: https://raspberrypi.stackexchange.com/questions/58478/ssh-not-working-with-fresh-install This persists across boots.
Otherwise, insert he SD card on your host, and create a magic empty file named ssh file in the boot/ partition.
On Ubuntu hosts, it gets mounted automatically and you can do just:
sudo touch /media/$USER/boot/ssh
which you can confirm with:
lsblk
which contains:
mmcblk0 179:0 0 14.4G 0 disk
├─mmcblk0p1 179:1 0 43.9M 0 part /media/ciro/boot
└─mmcblk0p2 179:2 0 14.4G 0 part /media/ciro/rootfs
If you don't enable the SSHD daemon on the Pi then SSH connection will fail with:
ssh: connect to host 10.42.0.160 port 22: Connection refused
when we try it later on.
After enabling the SSH server
Next, boot the Pi, and link an Ethernet cable from your laptop directly to the Pi:
On Ubuntu 17.04 to work around this bug as mentioned on this answer you first need:
sudo apt-get install dnsmasq-base
On the host, open the network manager:
nm-connection-editor
And go:
+ sign (Add a new connection)
Ethernet
Create
IPv4 Settings
Method: Shared to other computers
Set a good name for it
Save
Find the IP of the Pi on host:
cat /var/lib/misc/dnsmasq.leases
outputs something like:
1532204957 b8:27:eb:0c:1f:69 10.42.0.160 raspberrypi 01:b8:27:eb:0c:1f:69
10.42.0.160 is the IP, then as usual:
ssh pi#10.42.0.160
I also have the following in my .bashrc:
piip() ( cat /var/lib/misc/dnsmasq.leases | cut -d ' ' -f 3; )
pissh() ( sshpass -p raspberry ssh "pi#$(piip)"; )
From inside the Pi, notice that it can access the internet normally through your host's other interfaces:
ping google.com
For example on my laptop, the Pi takes up the Ethernet, but the host is also connected to the internet through WiFi.
The crossover cable is not required if the host network card supports Auto MDI-X. This is the case for most recent hardware, including for example the 2012 Lenovo T430 I tested with, which has an "Intel® 82579LM Gigabit Network Connection" which documents support for Auto MDI-X.
Now you can also:
access the Internet from the PI through your Ubuntu's Wifi connection
open a VNC to get rid of the display as well: https://raspberrypi.stackexchange.com/questions/14611/how-to-set-up-raspberry-pi-without-a-monitor/54393#54393
UART serial USB converter
This is an alternative to SSH if you just want to get a shell on the Pi: https://en.wikipedia.org/wiki/Serial_port
This does not use SSH or networking itself, but rather the older, simpler, more direct, more reliable, lower bandwidth, lower distance serial interface. The Pi won't have access to the Internet with this method.
Desktop computers still have a serial port which you can connect directly wire to wire with the Pi, but these are hidden in most laptops, and so we need to buy a cheap USB adapter. Here I've used a "DSD TECH USB to TTL Serial Converter" https://www.amazon.co.uk/gp/product/B072K3Z3TL See also: https://unix.stackexchange.com/questions/307390/what-is-the-difference-between-ttys0-ttyusb0-and-ttyama0-in-linux/367882#367882
First plug the SD card on the host, and edit the config.txt file present in the first partition to add:
enable_uart=1
as explained at: https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=141195
This first partition contains the bootloader, its configuration files and the (Linux / your) kernel, config.txt being one of them. The second partition contains the actual Linux root filesystem.
Now connect your computer to the Pi as:
You only need to attach 3 cables:
Ground to Ground
Tx on Pi to Rx on the USB to serial port
Rx on Pi to Tx on tye USB to serial port
This is also documented at: https://www.raspberrypi.org/documentation/usage/gpio/README.md
Be careful not to link the Ground to the 5V, I've already burned 2 UART to USB chips and a RPI UART by doing that!
You don't need to connect the 5V to the 5V at all. I think you can power your Pi like that, but I've read that this is a bad idea, just use the usual USB power source.
Finally, plug the USB side of the connector to your host computer, and get a shell with:
sudo apt install screen
sudo usermod -a -G dialout $USER
screen /dev/ttyUSB0 115200
Exit with Ctrl-A \.
Here is a video by Adafruit showing it: https://www.youtube.com/watch?v=zUBPeoLW16Q
See also
Similar question on RPI SE: https://raspberrypi.stackexchange.com/questions/3867/ssh-to-rpi-without-a-network-connection
You don't need a cross-over cable. You can use a normal network cable since the Raspberry Pi LAN chip is smart enough to reconfigure itself for direct network connections.
Cheers
I've just implemented and test this successfully. Same situation with my project, want to connect to a Raspberry Pi with no router or wifi. Just a simple ethernet cable.
Using ssh putty program put the address as
raspberrypi.local
Log and in and you can access the terminal.
Alternatively if VNC server is setup, use VNC server and put
raspberrypi.local:1
In the server address. input your VNC server password and you've now got GUI access to do what you want.
In may case it was run scripts in a remote location. In the posters situation, safely shutdown the Pi. Simples Pimples.
Configure static ip for your laptop and raspberry pi.
On the rapberryPI configure it as following.
pi#rpi>sudo nano /etc/network/interfaces
Then configure following as required to connect to your laptop.
iface eth0 inet static
address 192.168.1.81
netmask 255.255.255.0
broadcast 192.168.1.255
configure static ip on the raspberry pi:
sudo nano /etc/network/interfaces
and then add:
iface eth0 inet static
address 169.254.0.2
netmask 255.255.255.0
broadcast 169.254.0.255
then you can acces your raspberry via ssh
ssh pi#169.254.0.2
Here are the instructions for Windows users on connecting to a RPi by using just an Ethernet cable and a DHCP server. There is no need for a cross over cable, as the RPi can handle it. I have a blog post that documents this with pictures here which may be easier to follow.
Downloads
Download the DHCP Server for Windows (download link is here). Unzip the zip file and open the dhcpwiz application, which will configure the DHCP server.
DHCP Server Configuration
Hit next on the first screen.
On the second screen, look for a "Local Area Connection" row and verify its IP address is 0.0.0.0 and its status is enabled. Connect the Ethernet cable from the RPi to your laptop, and turn on the Pi. Hit refresh on this screen until the IP address changes to 169.254.*.*. If it is anything else then you should alter your network settings for the Local Area Connection (make sure it is not a static IP/DNS). Click on this Local Area Connection row and hit next.
Check HTTP (Web Server). This makes it much more easy to locate the RPi's IP address. Hit Next.
Take the defaults and hit Next until you get to the Writing the INI file screen. Check Overwrite existing file and hit the Write INI file button. Then hit Next.
On the final screen, check Run DHCP server immediately and hit `Finish.
DHCP Server and Obtaining the IP Address of your Raspberry PI
This launches the actual DHCP server, using the configuration you just created in the previous wizard. Click the Continue as tray app button, and the DHCP server will be minimized to your system tray.
Anywhere from 1 second to 5 minutes from now you will see an alert on the system tray with your laptop and your RPi's new IP address. This alert is really quick and you will probably miss it. Normally your RPi's IP is 169.254.0.2, but it could be *.01 or even something else. It is easier to access the DHCP server's web UI at http://localhost/dhcpstatus.xml. This will list the hostname as "raspberrypi" with its IP address.
Now you can putty or remote desktop into your RPi, and configure its wireless settings or whatever you want to do.
Trouble shooting
This can be somewhat finicky. I've had my connection appear to drop and have been unable to SSH back in using the IP address. Normally, I can restart the Pi and get the IP address again. Sometimes I have to restart both the RPi and the DHCP server. Sometimes I have to do this multiple times. At one point when I wasn't getting a connection for 15 minutes, I copied all of the files in the dhcpsrv2.5.1 folder to a new folder and tried again; it immediately worked.
You could use a cross-over ethernet cable - http://en.wikipedia.org/wiki/Ethernet_crossover_cable
Assuming your RPi is a DCHP Client, then best to run a simple DHCP server on your notebook to assign the RPi an IP address.
Yes, you can connect the raspberry direct to your PC without router.
For this is necessary that the raspberry and your computer are on the same subnet, and they both have a static ip configured (And an Ethernet cable connected between the two devices).
An ideal configuration would be the following:
Raspberry on eth0: IP: 192.168.1.10 SubNet: 255.255.255.0
Your PC: IP: 192.168.1.11 SubNet 255.255.255.0
To set a manual IP on raspberry you can follow this guide
In your PC you can set a manual IP in the network adapter settings,and the procedure depends on your operating system.
When you have configured the two static IP, you can connect to the raspberry via SSH using the IP set (192.168.1.10).
Another simpler method is to attach on GPIO a button to turn off the raspberry! Take a look here!
What worked for me was a combination of the answers from Nicole Finnie and Ciro Santilli along with some answers from elsewhere.
Setting up the pi
We will need to do two things: activate ssh on the pi, and configure the pi to use a static ip.
Activating ssh
Add a file called ssh in the boot partition of the sd card (not the /boot folder in the root partition). This is well documented other places.
Static ip
Open /etc/dhcpcd.conf on the pi's SD-card, and uncomment the example for a static ip (starts around line 40). Set the addresses to
# Example static IP configuration:
interface eth0
static ip_address=10.42.0.182/24
static routers=10.42.0.1
static domain_name_servers=10.42.0.1 8.8.8.8 fd51:42f8:caae:d92e::1
Setting up your laptop
First, make sure you have networkmanager (with GUI) installed on your laptop. Then, make sure dnsmasq is not running as a service:
systemctl status dnsmasq
If this command prints that the service is stopped, then you're good.
Next we have to config networkmanager. Open /etc/NetworkManager/NetworkManager.conf and add the following two lines at the top:
[main]
DNS=dnsmasq
Then reboot. This step might not be necessary. It might be sufficient to restart the NetworkManager service. Now go to the NetworkManager GUI (usually accessed by an icon in the corner of the screen) and choose Edit Connections... In the window that pops up, click the + icon to create a new connection. Choose Ethernet as the type and press Create.... Go to the IPv4 Settings tab and select the method Shared to other computers. Give the connection a good name and save.
Connect the Raspberry Pi and make sure your laptop is using your new connection as its ethernet connection. If it is, your pi should now have an ip given to it by your pc. You can find this by first running ifconfig. This should give you several blocks of text, one for each network interface. You're interested in the one that is something like enp0s25 or eth0. It should have a line that reads something similar to
inet 10.42.0.1 netmask 255.255.255.0 broadcast 10.42.0.255
look at the broadcast address (in this case 10.42.0.255). If it is different than mine, power off the pi and put the SD card back in your laptop to change the static ip_address to something where the first three numbers are the same as in your broadcast address. Also change the static routers and the first of the domain_name_servers to your laptop's inet address. Power the pi back on and connect it. Run ifconfig again to see that the addresses have not changed.
ssh into the pi
ssh pi#10.42.0.182
If you get connection refused, the pi isn't running an ssh server. If you get host unreachable, I'm sorry.
Hope this helps someone!

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.