How To Set A Static IP Centos 7

By default, most instillation of Centos will end up having the default protocol set to be dynamic (DHCP) for obtaining the IP address. For a web server this is not what we want as it will be no good having the IP change and then having to change DHCP records to correctly point to the new IP address. This tutorial will show you how to change the IP protocol for a Centos 7 OS to use a static IP instead of a dynamic IP.

Start by navigating to the directory that contains the IP config files.

cd \etc\sysconfig\network-scripts\
ls

You should get a list of files that are inside this directory. Most of the time there will be a file named “ifcfg-eth0”, but its not always the case. The name may vary, but it will always begin with “ifcfg”. When you are looking at the results have a look and see what files are in this directory that begin with “ifcfg” and work from there.

Once you have found the correct file you will see that there is a variable near the top of the file called “BOOTPROTO”. This will be set to “dhcp” this needs to be changed to be static. You will then need to go to the bottom of the file and alter or add some values for the network information. Your file should look like the file below once you have finished. (be sure to replace the placeholder info with actual IP information).

TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=ens160
DEVICE=ens160
ONBOOT=yes
IPADDR=1.1.1.1
NETMASK=255.255.255.0
GATEWAY=1.1.1.1
DNS1=8.8.8.8

If you are in a situation where you have no access to the machine other than command line, you will need to use VI to edit the file. Once you have a static IP you should be able to connect to the machine using SFTP and modify the file using a text editor.

Once you have made edits to the file, you will need to restart the networking on the server. The following command will restart the networking and should now allow you to access the server using the static IP that you have defined.

/etc/init.d/network restart

 

Related Articles

Related Questions

Looking for Feedback on Humanitec Use

Hey everyone! I'm diving into Humanitec and would love to hear from anyone who's actually using it. Specifically, I'm curious about the following: What...

Is a 10GB RTX 3080 still worth it in 2025?

My wife's GPU (a 1080 Ti) finally kicked the bucket, and I managed to snag a used setup with an i5-13600K, 32GB DDR5 RAM,...

Looking for Feedback on My PC Parts List!

Hey everyone! I just assembled my PC parts list a few minutes ago and I'm looking for some feedback on it. Here's the link...

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Latest Tools

xAI Grok Token Calculator

This tool is a simple xAI Grok token calculator that helps you estimate the number of tokens your input text might consume when working...

DeepSeek Token Calculator

This tool is a straightforward DeepSeek token calculator, created to help you estimate how many tokens your text may use when working with DeepSeek...

Google Gemini Token Calculator

This tool is a simple Google Gemini token calculator, designed to help you estimate how many tokens your text might use with models in...

Meta LLaMA Token Calculator

This tool is a basic Meta LLaMA token calculator, designed to give you a fast estimate of how many tokens your input text might...

Anthropic Claude AI Token Calculator

This tool is a simple Claude token calculator, built to help you quickly estimate token usage when working with Anthropic’s Claude models. It’s an...

OpenAI Token Calculator

This tool is a simple OpenAI token calculator, web-based utility designed to help you quickly estimate the number of tokens in your text when...

Latest Posts

Latest Questions