Skip to main content

Command Palette

Search for a command to run...

How to Configure SSH and Networking in Ubuntu Server on VirtualBox

Easy Steps for Setting Up Networking in VirtualBox with Ubuntu

Updated
7 min read
How to Configure SSH and Networking in Ubuntu Server on VirtualBox
R

IT professional with 20+ years in infrastructure, security, and cloud. I create bilingual (Telugu-English) tutorials and blogs through Yerravalli IT Simplified, making complex tech clear and practical. Explore my work at

TL;DR

This guide continues from the Ubuntu Server installation. You’ll install and enable OpenSSH, configure VirtualBox networking modes (NAT, Bridged, Host-Only, Internal), optionally set up port forwarding, and assign a static IP on Ubuntu using Netplan so you can reliably SSH into the VM.

👉 If you haven’t installed Ubuntu Server yet, start here: How to Install Ubuntu Server on VirtualBox
👉 Next tutorial in the series: Ubuntu Server Management and Security Hardening


What you’ll need (Prerequisites)

  • VirtualBox installed on your host (Windows / macOS / Linux).

  • An Ubuntu Server VM already installed (recap video or installation guide).

  • Basic comfort with the terminal (copy/paste commands provided).

  • Optional: Administrator/owner access to the host machine (for VirtualBox settings).


Quick overview of VirtualBox network modes (one-liner)

  • NAT: Easiest — VM can access the internet. Host cannot connect to VM directly unless you add port forwarding.

  • NAT Network: Multiple VMs can talk to each other and reach the internet; host cannot access VMs unless you configure port forwarding.

  • Bridged: VM is on the same LAN as your host — good for servers that need direct LAN access.

  • Host-Only: Host and VMs can reach each other — great for lab networks but no internet (unless you add another adapter).

  • Internal: VMs only communicate among themselves (isolated).

Step by step

1) Recap — confirm your VM is running

Start VirtualBox and power on your Ubuntu Server VM.

Figure 1 — VirtualBox network adapter settings.

2) Install & enable OpenSSH on Ubuntu

Open a terminal in the VM (or use the VirtualBox console).

# update packages
sudo apt update

# install OpenSSH server
sudo apt install -y openssh-server

# enable and start ssh service
sudo systemctl enable --now ssh

# check status
sudo systemctl status ssh --no-pager

You should see active (running).

Figure 2 — VirtualBox network adapter settings.

Tip: If sshd is not installed (very rare on server images), sudo apt install openssh-server fixes it.

3) Confirm the VM’s network interface name & IP (always do this first)

Find the interface name and IP assigned to the VM:

ip a      # lists network interfaces and addresses

Look for an interface like enp0s3, ensXXX, or eth0. Note the inet address (e.g., 10.0.2.15 or 192.168.56.101).

Figure 3 — VirtualBox network adapter settings.

4) How to connect by SSH (depending on network mode)

If using Bridged mode

The VM gets an IP from your LAN DHCP (same subnet as host). Connect from host:

ssh <username>@<vm-ip>
# e.g.
ssh rajesh@192.168.1.45

If using Host-Only mode

Host and VM are on a private host-only subnet (commonly 192.168.56.x). Use the

host-only IP:

ssh <username>@192.168.56.101

If using NAT mode (default)

VM can reach the internet but host cannot directly reach guest unless you add port forwarding.

  • Power off VM.

  • VirtualBox → Select VM → Settings → Network → Adapter 1 → Advanced → Port Forwarding.

  • Add a rule: Host IP 127.0.0.1, Host Port 2222, Guest IP (leave empty or put guest IP), Guest Port 22.

Figure 4 — VirtualBox network adapter settings.

  • Start VM. Connect from host:
ssh -p 2222 <username>@127.0.0.1
# e.g.
ssh -p 2222 rajesh@127.0.0.1
  • Option B — Port forwarding (VBoxManage CLI):

  • From the host terminal (replace "UbuntuVM" with your VM name):

      VBoxManage modifyvm "UbuntuVM" --natpf1 "guestssh,tcp,,2222,,22"
    
  • Then use ssh -p 2222 user@127.0.0.1 to connect.

    If using NAT Network

    Similar to NAT — you can configure port forwarding for the NAT Network or use other networking (host-only) to allow host access. By default, host cannot access VMs on NAT Network without forwarding.

5) (Optional) Set a static IP on Ubuntu (Netplan) — e.g., for Host-Only or Bridged static IPs

If you want the VM to always have the same IP (recommended for servers), configure netplan.

  1. Find the interface name: ip a (e.g., enp0s3).

  2. Create or edit /etc/netplan/01-netcfg.yaml (filename may differ):

# Example: static IP for Host-Only network (replace interface and addresses)
network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s3:
      dhcp4: no
      addresses: [192.168.56.101/24]
      gateway4: 192.168.56.1
      nameservers:
        addresses: [8.8.8.8,8.8.4.4]
  1. Apply the config:
sudo netplan try      # test the config
# or
sudo netplan apply
  1. Verify: ip a and ping 8.8.8.8.

Important: Replace enp0s3 with the interface name from ip a. Use correct gateway for your network (Host-Only default gateway often 192.168.56.1 in VirtualBox).

6) Make sure firewall allows SSH (UFW example)

If ufw is active, allow SSH:

# allow default OpenSSH profile
sudo ufw allow OpenSSH

# if you used host-side port-forward 2222:
sudo ufw allow 2222/tcp

# enable and check
sudo ufw enable
sudo ufw status

7) Verify connectivity from host

  • Ping the VM IP: ping <vm-ip>

  • SSH test: ssh user@<vm-ip> or ssh -p 2222 user@127.0.0.1.

  • Use netcat to test port: nc -vz <vm-ip> 22 (or 127.0.0.1 2222).

Figure 5 — VirtualBox network adapter settings.

Figure 6 — VirtualBox network adapter settings.

8) Useful VirtualBox GUI checks & tips

  • Cable connected: In VM → Settings → Network → ensure “Cable connected” checkbox is ON.

  • Adapter type: Usually leave as Intel PRO/1000 (Default).

  • Two adapters: You can add two adapters — e.g., Adapter 1 NAT (internet) + Adapter 2 Host-Only (host access). This gives VM internet + stable host access.

  • Create NAT Network: If you want VM-to-VM comms with NAT (NAT Network), use VirtualBox global settings → Network → NAT Networks → Add and configure.

  • Quick internet access, minimal fuss: Use NAT. Use port forwarding to SSH from host.

  • Server accessible on your LAN (others can reach it): Use Bridged. Good for test servers or services to be accessed by other machines on the LAN.

  • Isolated lab where host must access VMs: Use Host-Only (or Host-Only + NAT for internet).

  • Fully isolated multi-VM testing: Internal Network.

Common troubleshooting checklist

  • SSH says Connection refused → Ensure sshd is installed & running: sudo systemctl status ssh.

  • SSH times out → Check firewall (ufw status) or VirtualBox port forwarding.

  • Wrong IP → Re-run ip a inside VM.

  • Port forwarding not working → VM must be powered off to change some NAT settings (use GUI or VBoxManage), and make sure host port is free.

  • Netplan config fails → Run sudo netplan try to rollback if something breaks. Use ip a to confirm interface names.

✅ Wrapping Up

In this tutorial, we configured SSH access and set up networking in VirtualBox for Ubuntu Server. With this setup, you can now connect to your VM remotely and experiment with different networking modes (NAT, Bridged, Host-Only, etc.) just like in a real-world environment.

👉 If you missed the installation steps, check out the first part of this series:
How to Install Ubuntu Server on VirtualBox (Step by Step)

✅ Wrapping Up

In this tutorial, we configured SSH access and set up networking in Ubuntu Server on VirtualBox. With this setup, you can now connect remotely and experiment with different VirtualBox network modes just like in real-world environments.


🔗 What’s Next?

Now that your VM can be accessed via SSH, the next step is to explore Ubuntu Server management and security hardening.

👉 If you missed the installation tutorial, start here:

How to Install Ubuntu Server on VirtualBox

👉 Continue to the next tutorial:

Ubuntu Server Management and Security Hardening


🔔 Call-to-Action

💬 Share your questions in the comments.

👍 If you found this useful, follow me here on Blog.

🎥 Don’t forget to watch the full tutorial on my YouTube channel:

How to Configure SSH and Networking in Ubuntu Server on VirtualBox

👨‍💻 About the Author

I’m Rajesh Kumar, the creator of Yerravalli IT Simplified.

With over 20 years of experience in IT—covering Linux, Windows, Networking, Servers, Cloud, and Cybersecurity—I’m passionate about breaking down complex technical topics into simple, hands-on tutorials.

📺 Watch tutorials on YouTube: Yerravalli IT Simplified


📚 Ubuntu Server on VirtualBox Series

1️⃣ How to Install Ubuntu Server on VirtualBox

2️⃣ How to Configure SSH and Networking in Ubuntu Server on VirtualBox

3️⃣ SSH Brute Force: Ubuntu Server Management and Security Hardening

Stay tuned — new parts will be added here as the series continues! 🚀