# How to Configure SSH and Networking in Ubuntu Server on VirtualBox

## 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](https://blog.yerravalliitsimplified.com/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.](https://cdn.hashnode.com/res/hashnode/image/upload/v1758247798230/913a344c-f85b-4e82-91fa-a28baf916e5e.png align="center")

### 2) Install & enable OpenSSH on Ubuntu

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

```plaintext
# 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.](https://cdn.hashnode.com/res/hashnode/image/upload/v1758244880412/82f17321-ce15-471d-95c5-42f7805fa50b.png align="center")

> 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:

```plaintext
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.](https://cdn.hashnode.com/res/hashnode/image/upload/v1758247529268/ab14e275-3633-4193-920f-e2cd0976c403.png align="center")

> ### 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:
> 
> ```plaintext
> 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:
> 
> ```plaintext
> 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.](https://cdn.hashnode.com/res/hashnode/image/upload/v1758247248361/d343f294-a038-4be4-b675-f224a886fbea.png align="center")

> * Start VM. Connect from host:
>     
> 
> ```plaintext
> 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):
>     
>     ```plaintext
>     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):
    

```plaintext
# 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]
```

3. Apply the config:
    

```plaintext
sudo netplan try      # test the config
# or
sudo netplan apply
```

4. 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:

```plaintext
# 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.](https://cdn.hashnode.com/res/hashnode/image/upload/v1758246983399/5026ebaa-eeca-4573-b232-86de5e721bb4.png align="center")

![Figure 6 — VirtualBox network adapter settings.](https://cdn.hashnode.com/res/hashnode/image/upload/v1758247067327/92ddaa16-c403-418c-a2e6-b743cd3cfd92.png align="center")

### 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.
    

### 9) Example lab setups & recommended use

* **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)**](https://blog101.yerravalliitsimplified.com)

## ✅ 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**](https://it-forge.yerravalliitsimplified.com/how-to-install-ubuntu-server-on-virtualbox)

👉 Continue to the next tutorial:

[**Ubuntu Server Management and Security Hardening**](https://www.notion.so/End-of-the-EachAritcle-2747f71515da8043973fc08499dd3fa0?pvs=21)

---

### 🔔 Call-to-Action

💬 Share your questions in the comments.

👍 If you found this useful, follow me here on [**Blog**.](https://it-forge.yerravalliitsimplified.com/)

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

[**How to Configure SSH and Networking in Ubuntu Server on VirtualBox**](https://youtu.be/PQv7o5gIh6o)

<iframe width="560" height="315" src="https://www.youtube.com/embed/PQv7o5gIh6o?si=PSHdSbfltcc5jFl5"></iframe>

## 👨‍💻 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](https://www.youtube.com/@YerravalliITSimplified)

---

## 📚 Ubuntu Server on VirtualBox Series

1️⃣ [How to Install Ubuntu Server on VirtualBox](https://it-forge.yerravalliitsimplified.com/how-to-install-ubuntu-server-on-virtualbox)

2️⃣ [How to Configure SSH and Networking in Ubuntu Server on VirtualBox](https://it-forge.yerravalliitsimplified.com/how-to-configure-ssh-and-networking-in-ubuntu-server-on-virtualbox)

3️⃣ **SSH Brute Force**: [**Ubuntu Server Management and Security Hardening**](https://youtu.be/EooJ87GRWFs)

<iframe width="560" height="315" src="https://www.youtube.com/embed/EooJ87GRWFs?si=xq9VG9V-V5Gm0xLw"></iframe>

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