How to Configure a Static IP Address on CentOS7

Introduction

A static IP address is important for servers that need a consistent and reliable network address. Unlike a DHCP-assigned IP address, a static IP does not change automatically, making it suitable for servers hosting websites, applications, DNS, DHCP, FTP, and other mission-critical services.

In this guide, we will explain how to configure a static IP address on a CentOS 7 Minimal Server using the network interface configuration file.

Prerequisites

Before configuring a static IP address, ensure that:

  • You have a CentOS 7 Minimal Server.
  • You have root access or an account with sudo privileges.
  • You know the required IP address, Subnet Mask, and Gateway.
  • You know the name of the network interface.
  • You have access to the server’s command line.

Implementation

To set a static IP address on a CentOS 7 server, follow,

  1. Log in as root or an account with root privileges.
  2. From the command line, type, vi /etc/sysconfig/network-scripts/ifcfg-ens33   (ens33 is the network adapter of my OS, this may vary. To check your installed network adapter, use IP addr or IP Link or route -n. Try the Output yourself).
  3. Delete the config in the file and input the lines below,
    TYPE="Ethernet"
    BOOTPROTO="static"
    IPADDR=192.168.55.170
    NETMASK=255.255.255.0
    GATEWAY=192.168.55.2
    DEFROUTE="yes"
    PEERDNS="yes"
    PEERROUTES="yes"
    NAME="ens33"
    UUID="9de06be5-a36b-4937-9c11-b64f829eeac4"
    DEVICE="ens33"
    ONBOOT="yes"
    ZONE=public

    Note: Enter your preferred IP address, netmask, and Gateway.

  4. Save the config file and restart the network service using the command, systemctl restart network This will set a static IP address for your CentOs7 machine.

Conclusion

Configuring a static IP address on a CentOS 7 server ensures that the server remains accessible through a consistent network address. This is especially important for web, application, DNS, DHCP, FTP, and other production servers.

By updating the network interface configuration and restarting the network service, you can successfully assign a static IP address to the CentOS 7 server.

FAQs

1. How can I find the network interface name in CentOS 7?
Use the ip addr or ip link command to identify the network interface.

2. How can I verify that the static IP is configured successfully?
After restarting the network service, use ip addr to verify the assigned IP address and ping to test network connectivity.

3. What happens if I configure the wrong IP address, subnet mask, or gateway?
The server may lose network connectivity. Always verify these network details before restarting the network service.

How to find default gateway in CentOs7 Minimal Server

Talk to our experts

Looking for the right technology solution for your business? Our team of experts can help you with development, cloud, DevOps, design, and a wide range of other technology needs. Get in touch with our team here.

admin

Writes about Web & Architecture at Pheonix Solutions.

Leave a Reply

Scroll to Top