Software & AppsOperating SystemLinux

Setting up a Static IP for Network-Manager in Virtual Box on Ubuntu Server

Ubuntu 11

In this article, we will walk through the process of setting up a static IP for the Network-Manager in VirtualBox on an Ubuntu Server. This guide is particularly useful for system administrators and developers who want to ensure that their virtual machine (VM) has a consistent IP address, which can be particularly useful when configuring network settings or accessing the VM from other devices on the network.

Quick Answer

To set up a static IP for Network-Manager in VirtualBox on Ubuntu Server, you can use the nmcli command-line client. First, list the available connections using nmcli con show. Identify the connection you want to modify and use the nmcli con mod command to set the static IP address, gateway, and method. Set the DNS servers using nmcli con mod and the ipv4.dns parameter. If you need internet connectivity, you can add a second network interface using nmcli con add. Finally, reboot the system to apply the changes.

Prerequisites

Before you begin, ensure that you have the following:

  • An Ubuntu Server running on VirtualBox.
  • Sufficient permissions to execute system-level commands.
  • Basic understanding of networking concepts like IP addresses, DNS, and gateways.

Understanding Network-Manager and nmcli

Network-Manager is a dynamic network control and configuration system that aims to keep network devices and connections up and active when they are available. nmcli is a command-line client for Network-Manager. It is used to create, display, edit, delete, activate, and deactivate network connections, as well as control and display network device status.

Step 1: Listing Available Connections

First, we need to know the available connections that Network-Manager is handling. Open your terminal and type the following command:

# nmcli con show

This command lists all the available connections known to Network-Manager.

Step 2: Identifying the Connection to Modify

From the list of connections, identify the connection that you want to modify. For example, let’s assume the connection name is “Wired connection 1”.

Step 3: Modifying the Connection to Use a Static IP

Next, we will modify the connection to use a static IP. Use the following command:

# nmcli con mod "Wired connection 1" ipv4.addresses "192.168.56.101/24" ipv4.gateway "192.168.1.1" ipv4.method "manual"

In this command, con mod is used to modify the connection. The string “Wired connection 1” should be replaced with the name of the connection you want to modify. The ipv4.addresses parameter is used to set the static IP address and the network prefix (in this case, “192.168.56.101/24”). The ipv4.gateway parameter is used to set the gateway (here, “192.168.1.1”). The ipv4.method parameter is set to “manual” to specify that we are manually setting the IP address.

Step 4: Setting the DNS Servers

After setting the static IP, we need to set the DNS servers. Use the following command:

# nmcli con mod "Wired connection 1" ipv4.dns "1.1.1.1,1.0.0.1"

In this command, ipv4.dns is used to set the DNS servers. Replace “1.1.1.1,1.0.0.1” with the DNS servers you want to use.

Step 5: Adding a Second Network Interface

If you need internet connectivity on your VM, you can add a second network interface with a dynamic IP. Use the following command:

# nmcli con add type ethernet ifname eth1 con-name intnet autoconnect yes

In this command, con add is used to add a new connection. type ethernet specifies the type of connection. ifname eth1 sets the interface name. con-name intnet sets the connection name. autoconnect yes ensures the connection will be automatically established at boot.

Step 6: Rebooting the System

Finally, reboot your system to apply the changes. Use the following command:

# reboot

Conclusion

By following these steps, you should now have successfully set up a static IP for Network-Manager in VirtualBox on your Ubuntu Server. This will ensure that your VM has a consistent IP address, making it easier to access and configure. If you encounter any issues, you can refer back to the nmcli man page by typing man nmcli in your terminal.

Can I set up a static IP for Network-Manager in VirtualBox on other operating systems besides Ubuntu Server?

Yes, you can set up a static IP for Network-Manager in VirtualBox on other operating systems as well, as long as they have Network-Manager installed.

Can I set up multiple static IP addresses for different connections?

Yes, you can set up multiple static IP addresses for different connections by modifying each connection individually using the nmcli con mod command.

How can I check if my static IP configuration is successful?

After applying the changes, you can use the ip addr show command in the terminal to check if your static IP address is assigned to the correct connection.

Can I revert back to using DHCP instead of a static IP?

Yes, you can revert back to using DHCP by modifying the connection using the nmcli con mod command and setting the ipv4.method parameter to "auto".

Will setting a static IP affect my ability to connect to the internet?

No, setting a static IP should not affect your ability to connect to the internet as long as you configure the correct gateway and DNS servers.

Leave a Comment

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