Step-by-Step Guide: Changing from DHCP to Static IP Address on CentOS 7 via Command Line
Introduction:
In this tutorial, we will guide you through the process of transitioning from a DHCP (Dynamic Host Configuration Protocol) to a Static IP Address on a CentOS 7 system using the Command Line Interface (CLI). By following these steps, you'll gain control over your network configuration, ensuring a consistent and predictable IP address for your CentOS 7 machine.
**Prerequisites:**
1. A CentOS 7 system with administrative privileges.
2. Basic familiarity with the Linux command line.
**Step 1: Access the Terminal**
Begin by logging in to your CentOS 7 system and opening a terminal window. You should either use a user account with sudo privileges or log in as the root user.
**Step 2: Identify Your Network Interface**
Determine which network interface you wish to configure with a static IP address. To do this, execute the following command:
```bash
ifconfig
```
Locate the interface you want to work with (e.g., eth0, ens33).
**Step 3: Edit the Network Configuration File**
Now, you'll need to edit the network configuration file for the selected interface. Typically, this file is named `ifcfg-<interface_name>`. Replace `<interface_name>` with your actual interface name. You can use a text editor like nano or vi for this purpose:
```bash
sudo nano /etc/sysconfig/network-scripts/ifcfg-<interface_name>
```
**Step 4: Modify the Network Configuration File**
Within the configuration file, make the following adjustments:
- Change `BOOTPROTO` to `static` to specify a static IP configuration.
- Set `IPADDR` to your desired static IP address.
- Specify the `NETMASK` for your subnet (e.g., 255.255.255.0).
- Set `GATEWAY` to your gateway's IP address.
Here's an example of the modified configuration:
```plaintext
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=8.8.8.8
DNS2=8.8.4.4
```
Ensure that you adjust the values to match your network configuration. After making the changes, save the file and exit the text editor.
**Step 5: Restart the Network Service**
To apply the new configuration, restart the network service:
```bash
sudo systemctl restart network
```
**Step 6: Verify the Configuration**
To confirm that your network interface now has the desired static IP address, use the following command:
```bash
ifconfig <interface_name>
```
You should see your configured static IP address, subnet mask, and gateway listed.
**Step 7: Test Network Connectivity**
To validate that your network settings are functioning as expected, test network connectivity by pinging a known IP address or domain:
```bash
ping google.com
```
If you receive responses, your CentOS 7 system has successfully transitioned to a static IP address.
**Conclusion:**
By following this step-by-step guide, you've effectively shifted your CentOS 7 system from DHCP to a static IP address configuration using the Command Line Interface. This alteration provides stability and predictability in your network setup, ensuring that your server or workstation consistently uses the specified static IP address.
Comments
Post a Comment