How to assign Static IP address to CentOS virtual machine through command prompt

 Step 1: Identify the Network Interface

Run the following command to list all network interfaces and their current configurations:

Command- ip a

Identify the name of the interface for which you want to assign a static IP address (e.g., eth0, ens33, etc.).

Step 2: Edit the Network Configuration File

Network interfaces are configured in files located under /etc/sysconfig/network-scripts/. You need to edit the configuration file of the specific network interface.

For example, if the interface is eth0, open its configuration file with:

Command- sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0

Step 3: Modify the Configuration

In the configuration file, you need to ensure that the settings reflect the manual IP address assignment. Update or add the following lines:

TYPE=Ethernet

BOOTPROTO=static

NAME=eth0

DEVICE=eth0

ONBOOT=yes

IPADDR=192.168.1.100    # Replace with your desired IP address

NETMASK=255.255.255.0    # Replace with your appropriate netmask

GATEWAY=192.168.1.1      # Replace with your gateway

DNS1=8.8.8.8             # Replace with your preferred DNS server

Step 4: Restart the Network Service

Once the configuration is updated, restart the network service to apply the changes:

Command-

sudo systemctl restart network

Step 5: Verify the Changes

To ensure the changes were applied, you can check the interface's new configuration using:

ip a

This will show the manually assigned IP address for the interface.







Comments

Popular posts from this blog

How to enable AWS EBS Volume snapshots encryption

Reset Jenkins Admin Password

Deploying App through AWS EKS by using ingress and fargate