Operations 5 min read

Step‑by‑Step Guide to Configure Dynamic/Static IP and Hostname on Linux

This article walks you through configuring a Linux virtual machine's network settings, covering dynamic IP setup, static IP assignment with gateway and DNS, and hostname changes, using command‑line edits and verification commands to ensure connectivity.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Step‑by‑Step Guide to Configure Dynamic/Static IP and Hostname on Linux

Linux IP and Gateway Configuration

Purpose: enable a virtual machine to access the network.

1. Configure Dynamic IP (IP changes with environment)

Open the VM and edit the interface file: vi /etc/sysconfig/network-scripts/ifcfg-ens33 Press i to edit, change ONBOOT=yes to enable the interface, then exit and save with :wq.

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

2. Configure Static IP

Edit the same file and set the boot protocol to static: vi /etc/sysconfig/network-scripts/ifcfg-ens33 Change BOOTPROTO=static. Obtain the subnet IP and mask from VMware NAT settings, then configure the following parameters in the file: IPADDR0 – an address in the same subnet (e.g., 192.168.56.100) GATEWAY0 – the gateway shown in the virtual network editor DNS1 – a DNS server (e.g., 8.8.8.8, 223.5.5.5, etc.)

Save and exit, then restart the network: service network restart Verify the configuration: ip addr Test connectivity:

ping www.baidu.com

3. Set Hostname

Edit the hostname file to replace localhost.localdomain with the desired name: vi /etc/hostname Then edit the hosts file to map the new hostname to the loopback address: vi /etc/hosts Reboot the virtual machine to apply the changes.

After these steps the Linux VM will have a configured IP address (dynamic or static), 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.

LinuxIP ConfigurationStatic IPnetwork gatewayhostnameDynamic IP
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

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.