Software & AppsOperating SystemLinux

How To Assign a Static IP to Ubuntu Server in VirtualBox

Ubuntu 8

In this article, we will walk you through the process of assigning a static IP address to an Ubuntu Server running in VirtualBox. This can be a crucial step when setting up a server environment for testing or development purposes.

Quick Answer

To assign a static IP to an Ubuntu Server in VirtualBox, you need to configure the network settings in VirtualBox to use Bridged mode. Then, edit the network configuration file in Ubuntu Server to specify the static IP address, netmask, gateway, and DNS servers. Apply the changes and verify the configuration using the ifconfig command.

Prerequisites

Before we begin, ensure you have the following:

  • A running instance of Ubuntu Server on VirtualBox.
  • Basic knowledge of networking concepts like IP addresses, gateways, and DNS servers.
  • Familiarity with command-line operations in Ubuntu.

Understanding VirtualBox Network Modes

VirtualBox offers several network modes for your virtual machines, but we will focus on two: NAT (Network Address Translation) and Bridged mode.

NAT allows your virtual machine to access the internet through the host’s network connection, but other devices on the network cannot directly access the virtual machine.

Bridged mode connects the virtual machine directly to the host’s network. This makes the virtual machine appear as another device on the network, allowing other devices to connect to it directly.

Choose the network mode that best suits your needs. For this guide, we will use Bridged mode.

Configuring VirtualBox Network Settings

  1. Open VirtualBox and select your Ubuntu Server virtual machine.
  2. Click on “Settings” and navigate to the “Network” tab.
  3. In the “Attached to:” dropdown, select “Bridged Adapter”.
  4. Ensure the “Name” field is set to the network interface connected to your network.
  5. Click “OK” to save the changes.

Assigning a Static IP to Ubuntu Server

Now, let’s move on to assigning a static IP to your Ubuntu Server.

Editing the Network Configuration File

Open a terminal in your Ubuntu Server and run the following command to edit the network configuration file:

sudo nano /etc/netplan/01-netcfg.yaml

sudo allows you to run the command with administrative privileges, nano is a text editor, and /etc/netplan/01-netcfg.yaml is the network configuration file.

Modifying the Configuration File

In the configuration file, you will see a section for the network interface. Modify it to specify the static IP address, netmask, gateway, and DNS servers. Here is an example:

network:
 version: 2
 renderer: networkd
 ethernets:
 enp0s3:
 dhcp4: no
 addresses: [192.168.1.100/24]
 gateway4: 192.168.1.1
 nameservers:
 addresses: [8.8.8.8, 8.8.4.4]

In this example, enp0s3 is the network interface, dhcp4: no disables DHCP, addresses specifies the static IP address and netmask, gateway4 specifies the gateway, and nameservers specifies the DNS servers.

Applying the New Network Configuration

Save the changes and exit the text editor by pressing Ctrl+X, then Y, then Enter. Apply the new network configuration by running the following command:

sudo netplan apply

Verifying the Configuration

Verify that the static IP address has been assigned to the network interface by running the ifconfig command. You should see the IP address you configured listed.

Testing Network Connectivity

Finally, test the network connectivity by pinging another device on the network or accessing the internet from the virtual machine. If you’re unable to connect, double-check your VirtualBox network settings and the network configuration file on your Ubuntu Server.

Conclusion

Assigning a static IP address to an Ubuntu Server in VirtualBox can be a straightforward process with the right guidance. We hope this article has provided you with the information you need to complete this task successfully. For more information on VirtualBox networking, visit the official VirtualBox documentation.

Can I assign a static IP address to my Ubuntu Server in VirtualBox?

Yes, you can assign a static IP address to your Ubuntu Server in VirtualBox by following the steps outlined in this article.

What are the network modes available in VirtualBox?

VirtualBox offers several network modes, but for this guide, we focus on two: NAT (Network Address Translation) and Bridged mode.

What is the difference between NAT and Bridged mode?

In NAT mode, your virtual machine can access the internet through the host’s network connection, but other devices on the network cannot directly access the virtual machine. In Bridged mode, the virtual machine is connected directly to the host’s network, making it appear as another device on the network and allowing other devices to connect to it directly.

Which network mode should I choose for assigning a static IP?

For assigning a static IP, you should choose Bridged mode as it allows other devices on the network to connect to the virtual machine directly.

How do I edit the network configuration file in Ubuntu Server?

You can edit the network configuration file in Ubuntu Server by opening a terminal and running the command sudo nano /etc/netplan/01-netcfg.yaml.

How do I apply the new network configuration in Ubuntu Server?

After modifying the network configuration file, you can apply the new network configuration by running the command sudo netplan apply.

How can I verify if the static IP address has been assigned correctly?

You can verify if the static IP address has been assigned correctly by running the command ifconfig in the terminal. The assigned IP address should be listed.

What should I do if I’m unable to connect after assigning a static IP?

If you’re unable to connect after assigning a static IP, double-check your VirtualBox network settings and the network configuration file on your Ubuntu Server. Ensure that the IP address, netmask, gateway, and DNS servers are correctly configured.

Where can I find more information on VirtualBox networking?

For more information on VirtualBox networking, you can refer to the official VirtualBox documentation.

Leave a Comment

Your email address will not be published. Required fields are marked *