en
  English
Phone :  +370 (5) 204-1903
Email: sales@1gbits.com

How to Configure Static IP in CentOS 7

In CentOS 7 and other Linux distributions, the default protocol for network configuration is DHCP. If your CentOS has a graphical user interface (GUI), it won't be difficult to change the IP address from dynamic state to static. However, if you only have the shell, it should be configured manually (get ready for some typing). It is a reasonably straightforward process to configure the static IP address if you know where and how to do it.

Centos Tutorials Feb 06, 18 by Mery 4 min Read
How to Configure Static IP in CentOS 7

This tutorial will show you how to configure the static IP address on CentOS 7 using two different methods.

Prerequisites

  • A VPS or dedicated server with CentOS 7 installed.
  • Configuration details. For this tutorial, we will use the following details:
    • IP address: 192.168.12.23
    • Subnet mask: 255.255.255.0
    • Gateway: 192.168.12.1
    • DNS Server 1: 8.8.8.8
    • DNS Server 2: 8.8.4.4
    • Domain name: 1gbits.test

Configure Static IP in CentOS 7

Step 1

Verify your network adapter status using the following command:

 systemctl status NetworkManager.service

This command will display whether your network adapter in on or off.

Step 2

Now we need to find the names of network interfaces. Note these names down as it will be needed in the following steps.

nmcli dev status

To configure the static IP on CentOS, we will show you two methods.

  1. First method: Using terminal commands.
  2. Second method: Using the Network Manager tool.

Configure Static IP on CentOS 7 Using Terminal Commands

Change directory to /etc/sysconfig/network-scripts.cd /etc/sysconfig/network-scripts

Issue the ls command to find your interface name. The interface name will start with ifcfg- prefix. For example, our interface name is ifcfg-eno16777984.

  • Open the network interface configuration file using the nano command:

nano ifcfg-eno16777728

  • You will see the following content in this file. Enter your IP details.
  • Save and exit the file.

TYPE="Ethernet"

 BOOTPROTO="none"

 DEFROUTE="yes"

 IPV4_FAILURE_FATAL="yes"

 IPV6INIT="yes"

 IPV6_AUTOCONF="yes"

 IPV6_DEFROUTE="yes"

 IPV6_FAILURE_FATAL="no"

 NAME="eno16777728"

 UUID="6515e1f5ff46-410f97bc47d35c6d7bf8"

 ONBOOT="yes"

 IPADDR0="192.168.12.23"

 PREFIX0="24"

 GATEWAY0="192.168.12.1"

 DNS1=8.8.8.8

 DNS2=8.8.4.4

 HWADDR=00:50:56:AD:6D:41

 DOMAIN=1gbits.test

 IPV6_PEERDNS=yes

 IPV6_PEERROUTES=yes

  • Now restart your network service using the following command:

systemctl restart network.service

  • To verify your configuration, you can use the following command.

ip add

That is all! You can now use the newly configured static IP address on your system.

Configure Static IP on CentOS 7 Using Network Manager

In this method, you can use the Network Manager package to simplify the network configuration tasks. Network Manager package is a default installation in CentOS 7. If for some reason you will not find it, you can install it using the following command:

yum install NetworkManager-tui

  • In order to edit the network interface, use the following command:

nmtui edit eno16777728

  • Enter your specific IP details in the appeared window. In this picture, we have entered our sample configurations:

  • Once the configs have been set in place, click OK at the end. 
  • Restart your network service using the following command:

systemctl restart network.service

Final Words

In this short tutorial, we went through setting the static IP address on CentOS 7. Like we said in the beginning, it isn't a difficult task. Also, the above-mentioned methods will work for CentOS with a GUI as well.

Let us know in the comments below if you have any questions regarding the configuration of the static IP address.

author img

Mery

Leave A Comment