Operations 5 min read

How to Configure Dynamic and Static IP Addresses on Linux VMs

This guide walks through configuring both dynamic and static IP addresses, setting gateways, DNS servers, and hostnames on a Linux virtual machine, including editing network‑script files, restarting the network service, and verifying connectivity with ping.

Liangxu Linux
Liangxu Linux
Liangxu Linux
How to Configure Dynamic and Static IP Addresses on Linux VMs

Linux IP and Gateway Configuration

Configuring the IP address of a virtual machine enables network connectivity. The following steps cover both dynamic (DHCP) and static IP setups, as well as hostname configuration.

1. Configure Dynamic IP (changes with environment)

Open the VM and edit the network script file: vi /etc/sysconfig/network-scripts/ifcfg-ens33 Press i to enter insert mode and modify the file.

Set ONBOOT=yes to enable the interface at boot.

Exit insert mode with Esc, then save and quit using :wq.

Restart the network service: service network restart Verify the assigned address: ip addr Test connectivity: ping www.baidu.com Press Ctrl + C to stop the ping.

2. Configure Static IP

Edit the same network script file: vi /etc/sysconfig/network-scripts/ifcfg-ens33 Change BOOTPROTO=static to set a static address.

In VMware, open the Virtual Network Editor, select NAT mode, and note the subnet IP and mask.

Set IPADDR0 to an address within the subnet (first nine digits match the subnet, last three can be any value from 2‑255, e.g., a middle value).

Configure the gateway and DNS servers in the file:

GATEWAY0=your_gateway_ip
DNS1=your_dns_server_ip

Typical public DNS options include:

Baidu: 180.76.76.76

Alibaba: 223.5.5.5 or 223.6.6.6

Google: 8.8.8.8 or 8.8.4.4

Exit and save the file ( Esc then :wq).

Restart the network service: service network restart Test the configuration: ping www.baidu.com Press Ctrl + C to stop.

3. Set Hostname

Edit /etc/hostname to replace localhost.localdomain with the desired name, then save ( :wq).

Edit /etc/hosts and replace occurrences of localhost.localdomain with the new hostname, then save.

Reboot the virtual machine to apply the hostname change.

After completing these steps, the Linux VM should have a functional network configuration with the chosen IP mode, proper gateway and DNS settings, and a custom hostname.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxVMwareIP ConfigurationStatic IPDynamic IP
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.