Linux serverNETWORK ADMINISTRATIONS

How to Assign a Static IP Address in CentOS 7

Disclaimer/Disclosure: Some of the content was synthetically produced using various Generative AI (artificial intelligence) tools; so, there may be inaccuracies or misleading information present in the video. Please consider this before relying on the content to make any decisions or take any actions etc. If you still have any concerns, please feel free to write them in a comment. Thank you.

Summary: Learn the step-by-step process for configuring a static IP address on a CentOS 7 system, including necessary configuration file edits and service restarts. Ideal for network administrators and IT professionals managing CentOS servers.

How to Assign a Static IP Address in CentOS 7

Configuring a static IP address in CentOS 7 is a common task for network administrators and IT professionals who manage servers. Unlike dynamic IP addresses assigned by a DHCP server, a static IP does not change, making it essential for servers hosting websites, applications, or services where a consistent address is necessary.

Step 1: Access the Network Configuration File
To set a static IP, you first need to modify the network configuration files. In CentOS 7, network interfaces are managed by the NetworkManager service and configuration files are located in /etc/sysconfig/network-scripts/. Here’s how you access and modify the necessary file:

Identify the interface you wish to configure:

[[See Video to Reveal this Text or Code Snippet]]

Look for the device you want to configure under the DEVICE column.

Open the corresponding configuration file using a text editor such as vi or nano. For instance, if your network interface is ens33, the file will be named ifcfg-ens33:

[[See Video to Reveal this Text or Code Snippet]]

Step 2: Edit the Configuration File
Within the configuration file, you will set several parameters to configure a static IP. Here are the essential directives:

BOOTPROTO: Set this to none to disable DHCP.

ONBOOT: Set to yes to activate the interface at boot.

IPADDR: Your desired static IP address.

NETMASK: The netmask, which defines the subnet.

GATEWAY: The default gateway.

DNS1: The primary DNS server.

DNS2: (Optional) The secondary DNS server.

Here is an example of what the configuration file might look like:

[[See Video to Reveal this Text or Code Snippet]]

Make sure to replace the IP address, netmask, gateway, and DNS servers with those appropriate for your network.

Step 3: Restart the Network Service
After saving your changes, restart the NetworkManager service to apply the new configuration:

[[See Video to Reveal this Text or Code Snippet]]

Step 4: Verify the Configuration
To ensure that your changes have been applied correctly, use the following command to check your network interface settings:

[[See Video to Reveal this Text or Code Snippet]]

This command will display the current settings for ens33. Verify that the static IP address and other settings are correctly applied.

Conclusion
Setting a static IP in CentOS 7 involves editing the network interface’s configuration file and restarting the NetworkManager service. This setup is crucial for maintaining reliable network connectivity for services that require a fixed IP address. Remember to always back up configuration files before making changes to prevent issues if a mistake occurs.

source

centos 7