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.
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.com3. 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.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
