14.6 C
Senior Writer and partner

How to set a Static IP address on CentOS 7?

In several of our tutorials, we have referred to the IP address of a server. However, for many, the concept is not entirely clear. Today, I will show how to set a Static IP address using CentOS7.

IP means “Internet Protocol“. An IP address is a number (or set of numbers) that logically and hierarchically identifies a network interface (communication/connection element) of a device (computer, tablet, laptop, smartphone) that uses the IP protocol. Every web page you visit, any computer you work from or even mobile phones and tablets, has one of these addresses when you access the internet.

According to the form and scope of IP addresses, they can be classified into Public and private; static and dynamic; Type A, B or C. Despite all of them, I will focus on dynamic and static IP.

Dynamic IP Address and Static IP Address

In short, a dynamic IP address is one that is obtained via a DHCP server. Among its main advantages are:

  • Reduces the amount of assigned IP inactive.
  • It provides more security because your IP can change constantly.
  • IP addresses are assigned by a server.
- Advertisement -

Otherwise, static IP addresses are assigned manually by a user and will not change until the user assigns another. Nonetheless, a router can also assign this type of address through the device’s MAC address. Its main advantage is that it is easier to deploy network services. However, it is a slightly less secure method as the IP address will never change.

How to do it in CentOS 7

First, you must know what address and what the network interface is called. To do this, open a terminal and run as root user:

:~# yum install net-tools

1.- Installing net-tools packages
1.- Installing net-tools packages

Then, verify the name of the network interface:

:~# ip addr show

2.- Showing the network interface
2.- Showing the network interface

In this case, the interface name is enp0s3. In this section, you can also see the IP address of the computer.

Now you need to edit the interface configuration file.

:~# nano /etc/sysconfig/network-scripts/ifcfg-enp0s3

3.- Showing the configuration file for the network interface
3.- Showing the configuration file for the network interface

This is the contents of the file in my case.


Of all this, you only have to modify BOOTPROTO to static and add the following:


These are the parameters that you must place in your case that require. For example, the IP can be the one you want, and the gateway depends on your network. DNS values are optional.

4.-Network configuration
4.-Network configuration

Finally, restart the network service.

:~# systemctl restart network

Then, verify the IP address.

:~# ip addr show

5.- Showing the new IP address
5.- Showing the new IP address

And that’s it.

As you could see, it’s easy to make the change to the static IP address in CentOS 7. Remember that the configuration parameters are changeable and you must have them for your connection to be correct.

Please share this article in your social networks.


- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
"The best Linux newsletter on the web"


Please enter your comment!
Please enter your name here

Latest article