TechRepublic

Account information.

assign ip centos 7

Share with Your Friends

How to configure a static IP address in CentOS 7

Your email has been sent

Image of Jack Wallen

You may have set up a CentOS server and, in the process, accidentally set it up with DHCP. If your CentOS server uses a GUI, changing that IP address from dynamic to static is very simple. But what if your server is a text-only machine? What do you do then? Fortunately, it’s not all that hard to configure that GUI-less server with a static IP address–you just have to know where it’s configured and know the syntax of the configuration. Of course, by nature of what we’re working on this is all done manually, so be prepared to type.

I’ll be working on CentOS 7 . I’ll assume you already have the operating system installed and working properly, have access to the machine, and have an administrative account. With that out of the way, let’s set up that static IP address.

Find your interface

The first thing we must do is find out the name of our ethernet interface. A static IP address cannot be configured without this name. To do this, log into your server and issue the command ip a . The output of this command ( Figure A ) will include the name of the interface.

assign ip centos 7

As you can see, from my output, the name of my interface is enp0s3. Now that we know the name of our interface, we can configure the static address.

Configuring the address

Within the directory /etc/sysconfig/network-scripts/ you should find the file ifcfg-INTERFACENAME (Where INTERFACENAME is the name of your interface). In my instance, the file is ifcfg-enp0s3. It is important that you configure that file, and not the ifcfg-eth file. Open the correct file for editing with the command sudo nano /etc/sysconfig/network-scripts/ifcfg-enp0s3 . We need to modify that file in order to not only change the protocol from dhcp to static, but to add the specific IP address. So when you open up that file, you’ll want to change:

BOOTPROTO=dhcp

BOOTPROTO=static

Now you’ll need to add the entries to set not only the IP address, but the netmask, gateway, and DNS addresses. At the bottom of that file, add the following:

IPADDR=192.168.1.200 NETMASK=255.255.255.0 GATEWAY=192.168.1.1 DNS1=1.0.0.1 DNS2=1.1.1.1 DNS3=8.8.4.4

NOTE: All fields in bold, you will edit to reflect your networking needs. If you have fewer or more DNS entries, add or remove them as needed.

Save and close that file. In order to make the changes take effect, issue the command sudo systemctl restart network. Once the networking system has restarted, issue the command ip a to see that your IP address has changed to reflect your configuration.

And that’s all there is to setting a static IP address on CentOS. That wasn’t so hard, now was it? Don’t think this technique is limited only to GUI-less CentOS servers. You can use the same method to set a static IP address on a CentOS server with a GUI as well.

Enjoy having more control over your CentOS network interfaces.

Subscribe to the Developer Insider Newsletter

From the hottest programming languages to commentary on the Linux OS, get the developer and open source news and tips you need to know. Delivered Tuesdays and Thursdays

  • How to install Kloxo-Mr hosting control panel on CentOS
  • How to install a GUI on top of CentOS 7
  • How to install cPanel/WHM on CentOS 7
  • How to use the nmcli command to gather network device information on Linux
  • Learn how to run Linux on Microsoft's Azure cloud

Image of Jack Wallen

Create a TechRepublic Account

Get the web's best business technology news, tutorials, reviews, trends, and analysis—in your inbox. Let's start with the basics.

* - indicates required fields

Sign in to TechRepublic

Lost your password? Request a new password

Reset Password

Please enter your email adress. You will receive an email message with instructions on how to reset your password.

Check your email for a password reset link. If you didn't receive an email don't forgot to check your spam folder, otherwise contact support .

Welcome. Tell us a little bit about you.

This will help us provide you with customized content.

Want to receive more TechRepublic news?

You're all set.

Thanks for signing up! Keep an eye out for a confirmation email from our team. To ensure any newsletters you subscribed to hit your inbox, make sure to add [email protected] to your contacts list.

Tecmint: Linux Howtos, Tutorials & Guides

How to Configure Network Static IP Address on RHEL/CentOS 8/7

The scope of this tutorial is to explain how we can edit and make changes to Network Configurations on RHEL/CentOS 8/7 from the command line only, and, more specifically how we can set up a Static IP address on network interfaces using system network-scripts, which is a must be configured to serve Internet-facing network services, and how to configure or change RHEL/CentOS system hostname .

Configure Network Interface in CentOS 7

Also will show you, how we can manage or disable unwanted system services, such as Network Manager , which is no longer needed in-case you use a manual static IP configured on network scripts, Avahi-Daemon which is, also, not needed on a server and represents a seriously security gap, unless you installed the server on your Laptop and you want to instantly browse your network for other services, and on the final will present you Network Manager Text User Interface – nmtui , a system utility that can ease the job of editing your system network settings with advanced Interface configurations like creating Bond , Bridge , Team and VLAN Interfaces.

Requirements

  • Installation of “CentOS 8.0″ with Screenshots
  • Installation of RHEL 8 with Screenshots
  • How to Enable RHEL Subscription in RHEL 8
  • CentOS 7.0 Minimal System Installation
  • RHEL 7.0 Minimal System Installation
  • Active RHEL 7.0 Subscriptions and Functional Repositories

Also, be aware that most of the configurations offered by editing system files should not be performed from a remote location using SSH service until you establish a continued and reliable network connection using a fixed IP address.

On this page

  • Disable Unwanted Services in CentOS
  • Set Static IP Address on CentOS
  • Set Hostname in CentOS
  • Set Static IP Address on CentOS Using Nmtui Tool

Step 1: Disable Unwanted System Services in CentOS

1. Before actually starting to do anything we need to make sure that our system has some necessary editing and networking tools like netstat , ifconfig , wget , curl , and lsof installed, some of them will not be used on this step but it’s better to have them installed for future configurations.

Install Networking Tools in CentOS

2. After the tools have installed run ifconfig to get your Network Interfaces settings and status, and, then run netstat or lsof command to check what services are running by default on our server.

Check Network Interfaces and Services Status

3. The netstat command output is pretty self-explanatory and shows a list of sockets associated with their running program name.

If, for example, our system will not be used as a mail service you can stop Postfix master daemon which runs on localhost and, also stop and disable other unwanted services using the following commands – the only service I advise not to stop or disable for now is SSH if you need remote control over the server.

Stop Postfix Service

Stop Postfix Service

Stop Avahi Daemon Service

Stop Avahi Daemon

4. You can, also, use old init commands to stop or disable services but since Red Hat now implements systemd process and service management, you should better get used to systemctl commands and use it often.

If you use Arch Linux then it should be a piece of cake to switch to systemd – although all init commands now are linked and pass-through systemd filter.

5. If you want to get a list of all started services run the service command and for an exhaustive report use systemctl .

List All Services in Linux

6. To manage services run the systemctl command using the most important switches: start , stop , restart , reload , disable , enable , show , list-dependencies , is-enabled, etc. followed by your service name.

Also, another important feature that the systemctl command can also run on a remote server through SSH service on a specified host using -H option and perform the same actions as locally.

For example, see the command and screenshot below.

Run systemctl on Remote Server

Step 2: Configuring Static IP Address on CentOS

7. Before start editing Network Interface Card system files make sure that from now on and until you set static IP, you have physical or any other type of access to your server, because this step requires bringing down your network interface and connections.

Although it can be done smoothly without disrupting your connectivity and activate connection after reboot . There is no way you can test it before reboot if you only have a single NIC attached. Still, I will present to you with the entire method and indicate the steps needed to be avoided in case you want to maintain your connectivity and test it afterward.

8. Now move to /etc/sysconfig/network-scripts/ path, open and choose your Network Interface you want to assign static IP for editing – to get all NICs names to use ifconfig or IP command as shown.

Check Network Interface Name

9. Next, use the following network template to edit the file and make sure that the ONBOOT statement is set on YES , BOOTPROTO is set to static or none and don’t change HWADDR and UUID values provided by default.

Make the following changes as shown.

Configure IP Address in CentOS 8

10. After finishing editing the file, close it, and move to resolv.conf file if you want DNS servers enabled system-wide.

Here just add your DNS servers using nameserver statement.

11. Now Network Interface is configured with a static IP, the only thing remaining is to restart your network or reboot your system and use ifconfig or IP command to view the IP address and test configuration using ping command.

NOTE : After restart use the newly static IP address configured to perform remote login with SSH.

Check New IP Address

Step 3: Setting Hostname in CentOS

12. To adjust system hostname system-wide, open hostname and hosts file located on /etc path and edit both the following way.

Hostname File

Here you can add just the name of the system but it’s a good idea to append the .dot domain to.

Here add the same hostname as above on the 127.0.0.1 line before the localhost.localdomain statements.

Set Hostname in CentOS 7

Alternatively, you can set hostname using the hostnamectl command as shown.

13. To test if your hostname is correctly set use hostname command.

Step 4: Set Static IP Address on CentOS Using Nmtui Tool

14. NetworkManager Text User Interface (TUI) tool, nmtui , is an RHEL intuitive tool which provides a text interface to configure networking by controlling Network Manager, which helps to edit advanced network settings such as assign static IP addresses to Network Interfaces, activate or disable a connection, edit WI-FI connections, set your system hostname or create advanced Network interfaces like InfiniBand, bond, bridge, team or VLAN.

NetworkManager-tui is installed by default in RHEL/CentOS 7.0, but if for some reason its missing issue the following command to install it.

14. To start Network Manager Text User Interface run the nmtui command and use TAB or arrow keys to navigate through and press Enter to select an option. If you want to directly edit or connect a specific interface run the following options.

Configure Static IP in CentOS

If you want to set static IP you can, also, use Network Manager Text User Interface as a facile alternative to actually edit network interfaces files, with a limited number of options that method has to offer, but make sure Network Manager service is enabled and started on your system.

Previous article:

Next article:

Photo of author

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Related Posts

Install NTP Chrony in Linux

How to Install and Configure NTP in RHEL Systems

Install Terraform in Linux

How to Install Terraform (Infrastructure as Code) in Linux

Install GitLab on CentOS 7

How to Install and Configure GitLab on Linux

Create New Services and Units in SystemD

How to Create and Run New Service Units in Systemd Using Shell Script

Install VNC Server in Linux

How to Install and Configure VNC Server in CentOS and RHEL

Migrate CentOS 7 to AlmaLinux 8

How to Migrate CentOS 7 to AlmaLinux 8 Using ELevate Repo

11 thoughts on “How to Configure Network Static IP Address on RHEL/CentOS 8/7”

After 2 hours tests, Good all be fine, it works fine, just Added : In smb.conf file configuration in [Anonymous]

1- be sure that your server has a static connection 2- added user with password : smbpasswd -a username

Thank For Author I have make a samba configuration in 2 hours

I feel learning with quick manner in this site Thank you very much

I also routinely disable NetworkManager on my servers, but do note that “nmtui” (and also nmcli) are NetworkManager clients, so you cannot use them if you have disabled NetworkManager.

Excellent!. This is the ONLY post on setting static IP on Centos which is correct. Simple flow.

All: Just follow the steps as is.

Great explanation. Great job guys.

Great article. The static IP configuration works great on my RHEL 7 server vm.

Just have a question. The Red Hat documentation says that BOOTPROTO should be set to “none”. My copy of your configuration only works with BOOTPROTO=static as you used in your example. If I set it to none the ip address does not get updated. I am having some discussions with our Linux sys admins since they are insisting that I should follow only the Red Had docs and this is a problem as I can’t make it work with BOOTPROTO=none. Is there a reason why it only works with BOOTPROTO=static?

If it works with bootptoto=static then stick with this option as long as it does the job right! As far as i know it should work also with none (none actually specifies that no boot-time protocol should be used but the IP value from IPADDR=1.2.3.4 variable should be updated for NIC at boot time).

@Ehwan Kho: Just use ip link show or ifconfig -a command and you should see all your NICs names. You can also use nmtui to edit your new card settings.

How do I add a new network card – NIC? I tried using lspci | grep Ethernet, it display that it 2 cards. My question now how could I know its name? as they are not using the eth1, eth2 et al.. And I can’t see /etc/udev/rules.d/70-persistent-net.rules. Your thoughts are highly appreciated.

In my opinion you can use both approaches, manual editing NICs interfaces or configure static IP using NM or nmtui if you dont have a GUI. But for a better control and flexibility over your NICs you should go with manual configurations, without NM. If you go with manual without NM don’t forget to use NM_CONTROLLED=no and ONBOOT=yes parameters.

please matie cezar can you teach me how to network a small firm. i will be happy if you can teach me form scratch to the level of networking a firm. i want to learn the installation and configuration

I ALWAYS disable network manager on Servers, it’s too dynamic and wastes resources. Why Red Hat is pushing that crap I don’t know, but I haven’t met anyone who wants it on a server. It’s great for desktops, and laptops, but NOT servers. Also, the DNS settings need to stick to being setup in the resolv.conf file, not spread out in the ifcfg scripts. Keeps the config manageable and easy to troubleshoot.

From going over the documentation on RHEL/CentOS 7, it appears that they’re really pushing for NetworkManager to be the default way to manage networking. For servers (not desktop) do you believe it’s best to disable NetworkManager and just assign static IPs normally as you have instructed or do you believing managing all the network through net manager is worth it?

The reason I ask is because I only deal with servers (not desktops) and I’ve seen many times NetworkManger causing major network issues. So I’m still on the fence whether or not to do things through netManager. Specially considering that rhel 7 is using it by default.

Got something to say? Join the discussion. Cancel reply

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.

Save my name, email, and website in this browser for the next time I comment.

Stack Exchange Network

Stack Exchange network consists of 183 Q&A communities including Stack Overflow , the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

How can I set a static IP address in CentOS 7?

I have a CentOS 7 Minimal VirtualBox VM that I would like to set a static IP address on. I want to assign the static IP address via a Bash script within the VM (so not using the VirtualBox network interface).

How can this be done?

So far I've tried editing the file : /etc/sysconfig/network-scripts/ifcfg-enp0s8 , and putting the below in it (per this question: https://superuser.com/a/365088 ).

But then the network adaptor doesn't restart ( service network restart ), which after a considerable amount of restarts/resets/trial, and error, and copious Google searches, it seems like it could be dozens of different things.

ip a lists two devices:

I also have a ifcfg-enp0s3 config file in the sysconfig dir (not sure why).

So, what's a nice, simple, predictable, reliable way of setting a static IP address in CentOS 7 minimal?

Giacomo1968's user avatar

  • 1 The answer you linked to is correct. –  Ramhound Sep 9, 2017 at 19:12
  • ipcfg-en0s3 –  Ramhound Sep 9, 2017 at 19:50
  • @Ramhound - That may be the "correct" answer, but I'm afraid it's not a working answer. Sure, if I do ip a it reports that enp0s8 is on my new, desired IP address, and I can ping that address from the client itself, but the host machine can't access it. And as noted above, in this configuration, service network restart returns FAILED, although I've just got rid of that by simply deleting the ifcfg-enps03 file. I still can't externally connect to the client despite being able to on the old address before the change. (And firewalld is stopped). –  linux_confusion Sep 9, 2017 at 21:35
  • Neither the answer linked nor RHEL Documentation has quoted values. Did you try your configuration without quotes? –  sebasth Sep 10, 2017 at 6:57
  • @sebasth - the file that already exists (and thus shipped with CentOS) has quote marks. However I've tried both with and without and they make no difference. –  linux_confusion Sep 10, 2017 at 8:34

Try following:

I believe your problem is primary in the missing NM_CONTROLLED=no. Except of network restart you may try to set it UP with

You may also need to specify GATEWAY=

Jaroslav Kucera's user avatar

You must log in to answer this question.

Not the answer you're looking for browse other questions tagged linux networking virtualbox centos ..

  • The Overflow Blog
  • Exploring the inclusive tech revolution sponsored post
  • Would you trust an AI bot to find the fix for vulnerabilities in your code?
  • Featured on Meta
  • Site maintenance - Saturday, February 24th, 2024, 14:00 - 22:00 UTC (9 AM - 5...
  • Upcoming privacy updates: removal of the Activity data section and Google...

Hot Network Questions

  • How does this code work?
  • How do I read aloud a range of years with a slash?
  • High School Combinatorics - I do not agree with the provided explanation
  • Few enigmatic puzzles
  • How to put big brackets around minipage
  • How to add object coordinates to instance coordinates?
  • What spares were taken on Apollo missions, and what was left behind? The question of gloves
  • Why is there a phasor in the transfer function of an ideal LPF?
  • Which heptomino is it obvious can't tile the plane?
  • Compiler for LaTeX
  • A bug with high precision
  • Was Alexei Navalny in 2020 poisoned with Novitschok nerve agents by Russia's Federal Security Service?
  • Trying to understand reality lead to understanding useless things?
  • Adding a dot after section number in the header with fancyhdr
  • Hypothesis testing for detecting a (damped) sinusoidal signal in noise
  • Unable to understand what confidence interval means
  • Why is "tyrannis" in "sic semper tyrannis" interpreted as "to tyrants"?
  • The problem of philosophy?
  • How do I know it is safe to remove eclipse glasses when viewing a total solar eclipse?
  • choosing non adjacent vertices
  • Novel - Disguised alien Tock Von visits Earth, meets a girl, gets committed to a psychiatric hospital
  • Is it bad practice to cite online news articles in solely because it's not a "reputable" source (i.e journal articles or even books)?
  • Lots of electrical noise at boost converter output
  • A simple unit test library for C

assign ip centos 7

logo

How To Configure a Static IP Address on CentOS 7/8

  • Knowledge Base
  • Networking 6
  • Webhosting 10
  • Virtualisation 2

Introduction

This guide details howto configure a static IP on CentOS 7 or 8 on an operating system installed without a GUI.  There are a number of options/methods available to do this outlined below.

Method 1 – Using Network Configuration File

1) First determinte the name of your network adapter by running the following:

2) Using your favourite text editor open the configuration file for your network adapter, replacing X with the name of your network adapter determined in the previous step.

3) Configure the variables in the file for your conneciton:

4) The most common configuration parameters with explanations are:

BOOTPROTO= none, bootp or dhcp IPADDR= DEVICE=<name> –> where <name> is the name of the physical device. DNS{1,2}=<address> –> where <address> is a name server address to be placed in /etc/resolv.conf GATEWAY= MACADDR=<MAC-address> –> Where <MAC-address> is the hardware address of the Ethernet device in the form AA:BB:CC:DD:EE:F NETMASK=

ONBOOT=<answer> –> Where <answer> is one of the following: yes — This device should be activated at boot-time. no — This device should not be activated at boot-time.

PEERDNS= yes – Modify /etc/resolv.conf if the DNS directive is set. If using DHCP, then yes is the default. no – Do not modify /etc/resolv.conf.

USERCTL= yes  – Non-root users are allowed to control this device. no – Non-root users are not allowed to control this device.

4) If you have NetworkManager service running, you’ll need to instruct the network service that network manager doesn’t manage this interface (eth0). This is done by adding the line:

5) Then you can stop NetworkManager service. For CentOS 7/8, this can be done using:

6) After saving the changes, the shut down the interface and bring it back:

7) Then you can stop NetworkManager service. For CentOS 7/8, this can be done using:

8) Check the current adapter settings:

Method 2 – Using ip and ifconfig commands

The ifconfig command is now depreciated in favour of ip tool however is still part of net-tools package and can be installded with:

For clarity in the steps below both iptool and ifconfig commands are shown:

Show Adapters

To show all ip address related infoprmation is ip/config these commands are used:

Bring Up/Down an Interface

Setting a static ip.

Static IP setting can be done using ip or ifconfig. But note that changes made with these commands are not persistent against reboots:

Removing a static IP

Clearing IP information can be done as follows:

Add default route via gateway IP

A default route can be set using ip and ifconfig commands for destinations without static routes defined.

Method 3 – Using Network Manager (nmcli)

In RHEL and CentOS 7 and 8 the networking service is managed by the NetworkManager daemon and it is used to dynamically configure and control network devices and keep connections up and active when they are available.

Howto remove NetworkManager

In case you don’t want to remove network manager you can disable and remove it as follows:

Incase you do wish to use NetworkManager then a reference of commands can be found below:

Howto start NetworkManager

You can check Network Manager is running and started as follows:

Bring Up interfaces using NetworkManager

You can bring network interfaces up and down using network manager as follows:

Configure a static IP using NetworkManager

1) List current connections

2) Delete connections entering UUID or network name from Step 1

3) Create a network with name ethX

4) Configure DNS and make network configurations always be manual for this network interface.

5) Restart the network:

6) View the connection ethX

supermicro server

– Limited Offer –

Dual Core Xeon E3-1220L 2.20Ghz 

Only £29/Month 

assign ip centos 7

How to configure a static IP address on CentOS 7

Last updated on November 7, 2020 by Dan Nanni

If you want to set up a static IP address on a network interface in CentOS 7, there are several different ways to do it, varying depending on whether or not you want to use Network Manager for that.

Network Manager is a dynamic network control and configuration system that attempts to keep network devices and connections up and active when they are available). CentOS/RHEL 7 comes with Network Manager service installed and enabled by default.

To verify the status of Network Manager service:

To check which network interface is managed by Network Manager, run:

assign ip centos 7

If the output of nmcli shows connected for a particular interface (e.g., enp0s3 in this example), it means that the interface is managed by Network Manager. You can easily disable Network Manager for a particular interface, so that you can configure it on your own for a static IP address.

Here are two different ways to assign a static IP address to a network interface on CentOS 7 . We will be configuring a network interface named enp0s3 .

Configure a Static IP Address without Network Manager

Go to the /etc/sysconfig/network-scripts directory, and locate the configuration file of the interface ( ifcfg-enp0s3 ). Create it if not found.

assign ip centos 7

Open the configuration file and edit the following variables:

assign ip centos 7

In the above, NM_CONTROLLED=no indicates that this interface will be set up using this configuration file, instead of being managed by Network Manager service. ONBOOT=yes tells the system to bring up the interface during boot.

Save changes and restart the network service using the following command:

Now verify that the interface has been properly configured:

assign ip centos 7

Configure a Static IP Address with Network Manager

If you want to use Network Manager to manage the interface, you can use nmtui (Network Manager Text User Interface) which provides a way to configure Network Manager in a terminal environment.

Before using nmtui , first set NM_CONTROLLED=yes in /etc/sysconfig/network-scripts/ifcfg-enp0s3 .

Now let's install nmtui as follows.

Then go ahead and edit the Network Manager configuration of enp0s3 interface:

The following screen will allow us to manually enter the same information that is contained in /etc/sysconfig/network-scripts/ifcfg-enp0s3 .

Use the arrow keys to navigate this screen, press Enter to select from a list of values (or fill in the desired values), and finally click OK at the bottom right:

assign ip centos 7

Finally, restart the network service.

and you're ready to go.

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal or credit card

Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License . If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.

assign ip centos 7

Xmodulo © 2021 ‒ About ‒ Write for Us ‒ Feed ‒ Powered by DigitalOcean

How to Configure a Static IP address on CentOS/RHEL 7

This post explains how a static IP address can be set on CentOS/RHEL 7. We can configure the static ip address in /etc/sysconfig/network-scripts/* by setting the properties in the /etc/sysconfig/network-scripts/ifcfg-[interface] file. Here [interface] is the interface of your choice to which you want to assign an IP address.

Sample Example

Below are basic configuration instructions to setup a static IP address on CentOS/RHEL 7.

1. First, list your network interfaces with ip command:

Make a note of network interface you would like to set with static IP address.

2. Next, locate a corresponding script to the network interface name. In our case this is enp0s3 located at /etc/sysconfig/network-scripts/ifcfg-enp0s3.

3. Open this file and enter the following information. Note that your HWADDR,DEVICE,UUID will be different:

4. The above will set our enp0s3 network interface with static IP address 10.1.XX.110. Once you have made the necessary changes restart the system networking using below command:

5. Confirm that your IP address has been updated:

  • How To Change Engine Database Password for OLVM Engine
  • Oracle Linux Virtualization Manager(OLVM) Engine PostgreSQL Database Queries Cheat Sheet
  • How to Configure firewalld in CentOS/RHEL 8 using "Web Console" and "firewall-cmd"
  • Troubleshooting Booting Issues in CentOS/RHEL 7 and 8
  • How to Mount NFS Shares using Automounter in CentOS/RHEL
  • How to reset or recover root password in CentOS/RHEL 8
  • Understanding CentOS/RHEL 8 Boot Process
  • Beginners Guide to Stratis local storage management in CentOS/RHEL 8
  • How to Compress and Deduplicate Storage with VDO in CentOS/RHEL 8
  • How to Extend a Logical Volume in LVM - for XFS, ext4 and swap filesystem

Latest Posts

  • How to Create Index Partitions To Ranged Partitioned Table
  • How to Move Partition Online in Oracle 12c
  • How to add or modify Printer settings in CentOS/RHEL using GUI
  • What is machine-id in Linux

How to setup a static IP address on Centos 7 / RHEL 7

assign ip centos 7

In this article we will explain how to setup a static IP address on Centos 7 / RHEL 7.There are several ways to configure a static IP address.

1. nmtui Tool ( Network Configuration Text User Interface) 2. nmcli Tool ( Network Manager Command Line ) 3. Editing /etc/sysconfig/network-scripts/ifcfg-network_interface_name.fcg

For this tutorial, we’re going to assign to my server on my lab environment: – IP address : 192.168.1.10 – NetMask 255.255.255.0 – Gateway 192.168.1.1 – Domain Name Servers : 192.168.1.2 192.168.1.3 ( In my lab environment i’ve two Dns Servers) – Search Domains : yallalabs.com

Before starting let’s check current IP address and of our Centos 7 / RHEL 7 server :

Here, like you see, my network interface name is enp0s3 and the network configuration is automatically assigned by my DHCP server. Let’s start setting up a static ip address to our server .

1./ nmtui tool:

nmtui set a static ip address centos 7 rhel 7

Remember to check Automatically connect   to start the network device on boot and click ok .

By the way you can directly edit or connect an interface network device using:

Finally, restart the Network configuration daemon

2. nmcli Tool ( Network Manager Command Line )

First, let’s display the network connections.

Let’s start.

if you want to display list of all informations of the network connection use this command.

3. Editing /etc/sysconfig/network-scripts/ifcfg-network_interface_name.fcg

BY default the configuration file will look like the block below.

  To change the above setup to a static IP address configuration, replace BOOTPROTO value from dhcp to static or none as shown below.

Then add the IP address, network mask, gateway, domain search and Dns for the server at the end and save the file.

Finally, restart the network service to insecure change takes effect.

  That’s it for now. Enjoy..  

PS. If you like this post please share it with your friends on the social networks using the buttons below.Thanks. YallaLabs

' src=

Lotfi Waderni

I'm a technical writer with a background in Linux and windows server administration.

How to change the Hostname on CentOS 7 / RHEL 7

How to setup a static ip address on ubuntu 16 lts, you may also like, how to install go on ubuntu 20.04..., how to mount a glusterfs in a..., installing and configuring percona xtradb cluster high..., how to setup loganalyzer with rsyslog on..., leave a comment cancel reply.

ITzGeek

How To Configure IP Address in CentOS 7 / RHEL 7 & CentOS 6 / RHEL 6

assign ip centos 7

Just after the installation of operating systems, you must configure the network to access your system from outside. This guide helps you to Configure IP Address in CentOS 7 / RHEL 7 & CentOS 6 / RHEL 6 .

Here I will show how to configure Static IP addresses for your machine and also configure the network interface to get an IP address from the DHCP server.

Prerequisites

Let’s check the available interfaces on our system. Use the ifconfig command to list interfaces.

From the above output, you can see my system has two interfaces namely lo and ifcfg-enp0s3 . Depends on hardware, the name of the interface will change.

To set an IP address to an interface, go to /etc/sysconfig/network-scripts/ directory, there you will find a file ifcfg-<interfacename> .

As per the above output, my system has a file ifcfg-enp0s3 since CentOS 7 / RHEL 7 uses consistent network interface naming.

Static IP Address

In this mode, we will manually assign an IP address to machines.

Edit the ifcfg-<interfacename> file.

Restart the network service using the below command.

Now you can see the ip address 192.168.0.10 assigned to the interface enp0s3 .

DHCP IP Address

In this mode, the system will get an IP address from the DHCP server. This is the default mode set on CentOS to get an IP address from the DHCP server.

Just modify the lines like this.

Now you can see the ip address 192.168.0.23 assigned to the interface enp0s3 using DHCP.

That’s All. Please share your feedback in the comments section.

Top Important Docker Commands – Working with Docker Containers

Fedora Server 22 Installation – Step by Step with screen shot

How to Install Oracle Java JDK 18 on Linux

How to Install Oracle Java JDK 17 on Linux

How to Upgrade CentOS 7 to Rocky Linux 8

How To Install PHP 8.0 on CentOS 7 / RHEL 7

How To Install NTP (Chrony) On CentOS 8 / CentOS 7 & RHEL 8 / RHEL 7

How To Install Gradle on CentOS 8 / 7 & RHEL 8 / 7

  • CentOS 8 / RHEL 8
  • CentOS 7 / RHEL 7
  • CentOS 6 / RHEL 6
  • LinuxMint 20
  • Linux Mint 19
  • Linux Mint 18
  • Rocky Linux 8
  • Ubuntu 22.04
  • Ubuntu 20.04
  • Ubuntu 18.04
  • MySQL / MariaDB
  • Other Tools

Press ESC to close

configure ip address centos

Configure IP address in Linux (RHEL/CentOS 7)

The first thing that we do after installing an operating system is to configure the IP address i.e. networking on the machine. Whether we want to connect to the internet or only to our local area network (LAN), we must provide information regarding our network to the machine. In this tutorial, we are going to discuss how to configure IP address in Linux (RHEL/CentOS 7) using three different methods.

Also if you would like to assign an IP address to your Ubuntu system, then please refer to this tutorial How to manage network in Ubuntu 18.04 – Netplan Command  or you can also refer to the tutorial for IP COMMAND, using which you can manage the network on all Linux distributions that have IP command installed.

(Recommended Read: IP Aliasing: Assigning multiple IP addresses to single NIC )

Configure IP address in Linux

Method 1- by editing the network interface file.

This method works on all Linux distributions. To configure the IP address, we need to open the network configuration file & pass our network information in the file. In RHEL/CentOS 7, location for all network interfaces in ' /etc/sysconfig/network-scripts ', in our case name of network interface is 'ifcfg-en0s3'. We will now edit the file to configure a static IP address for our system. Open the network interface file,

$ cd /etc/sysconfig/network-scripts $ vi ifcfg-en0s3

configure ip address linux

To configure a static IP address, change the ' BOOTPROTO ' to ' none ' (it's DHCP by default) & enter IP address, gateway & DNS information.  Also, change ' ONBOOT ' to ' yes ' so that we don't have to start networking services every time we restart our system.

configure ip address linux

After making all the changes, save the file & then restart the networking services to implement the changes.

$ systemctl restart network $ vi ifcfg-en0s3

Method 2 - Using the Graphical interface

If we are using RHEL/CentOS with GUI then we can easily configure IP address graphically.  Open 'Network' either by clicking the network icon & then selecting ' Network Settings ' on the top-left corner of the screen or goto Applications-> System Tools-> Settings-> Network.

configure ip address linux

Next, click on the Settings icon (on the bottom right corner of the opened window) & select IPV4 then mention your network information on the opened window.

configure ip address linux

After the IP information has been edited, click on apply & exit from the menu. Lastly restart network services for implementing the changes.

Method 3- Using NMTUI command

This method can be used in GUI as well as in CLI. For using it in GUI mode, open a terminal and enter the command 'nmtui' & press enter or if using CLI, just enter the command 'nmtui' & press enter. This will open a new window with 3 options i.e. we can edit our network interface, activate a network interface, or set a hostname for our system  (read our tutorial on setting hostname HERE ).

To set up networking for the system, select 'Edit a connection', select your network interface & then select 'Edit' using the arrow keys. In the 'IPv4 Configuration' select 'manual' & then enter your network information.

configure ip address centos

After making changes, press 'OK' to save the file & on the next screen press 'Quit' to exit from the menu. Restart your network services for changes to take effect.

Apart from these three methods, you can also configure IP address when installing operating system & also there are two more methods through which we can configure our network on RHEL/CentOS 7 machines i.e. by using ' nmcli command & ifconfig command . This wraps up our tutorial on how to configure IP address in Linux. For any queries/questions, please use the comment box below.

If you think we have helped you or just want to support us, please consider these :-

Connect to us: Facebook | Twitter

Linux TechLab is thankful for your continued support.

Share Article:

Passionate about Linux & open source. Loves to learn, read & write about Linux as well as new technologies.

Install TeamViewer on Ubuntu & CentOS /RHEL

Omd monitoring: install omd on centos 6, one comment.

assign ip centos 7

That was very helpful, thank you. Best regards.

Leave a Reply Cancel reply

Save my name, email, and website in this browser for the next time I comment.

DEV Community

DEV Community

Paula

Posted on Mar 27, 2023

How to configure a static IP address on CentOS 7 with VirtualBox

This article aims to explain how to configure a static IP address on a CentOS 7 virtual machine using VirtualBox.

We will go step by step, and at the end of this blog, you will be able to ssh into your virtual machine using a never-changing IP.

What is a static IP?

Every computer has a random local IP address unless you have specified the contrary. These addresses are not fixed. It means that they could change.

In most cases, you don’t care about the IP address, but you usually do with virtual machines.

If you have a MySQL service running on a virtual machine, you would want to save the connection configuration once and re-use it every time. If the IP address changes, you have to modify the connection settings.

Another approach is to use port-forwarding. This approach is okay until you have 3 or more virtual machines with multiple services and ports to keep track of.

The following image shows the ideal local development environment with static IP addresses.

Image description

Configure VirtualBox Networking

The app VirtualBox has some networking settings we have to set before changing the VM Linux configuration.

We want our VM to have the following:

  • Access to the internet
  • Access to our host computer

And we also want to be able to access the VM by IP.

Step 1: Stop the VM

You have to stop the VM before doing the following steps.

Step 2: Create Ethernet Adapter

Click on Tools - Networks and make sure you have an ethernet adapter created. Write down the IPv4 Prefix, because the static IP will be in this range.

Image description

In the image above:

  • The gateway is 192.168.56.1
  • The network mask is 255.255.255.0 (24 bits)

The static IP of my VM will be in the 192.168.56.xx range.

Step 3: Change adapters

Right-click on the virtual machine and choose the “Network” tab. We are going to add 2 adapters:

  • The first one is going to be a NAT. This way the VM will have internet access.
  • The second one has to be a “Host-only Adapter” with the ethernet adapter of the previous step. This is the adapter that will have the static IP assigned.

Image description

Configure VM Centos 7

Now that we have configured the VirtualBox networking, we will configure the inner VM networking settings.

Step 1: Start the VM

Double-click on the VM or right-click and start.

Step 2: Get the connection name

We know the static IP will be assigned to the second adapter, the Host-only Adapter.

Let’s check the vm networking using ip addr | head -n 20 :

Image description

  • enp0s3: NAT Adapter
  • enp0s8: Host-Only Adapter

Now we know we have to assign an IP to the enp0s8 device. To get its connection name, you have to execute the following statement:

nmcli -p device

Image description

The connection name is “Ethernet connection 1”.

Step 3: Configure connection IP

There are two ways of doing it:

  • Graphically with nmtui
  • With bash statements and nmcli

In our case, we will execute some statements in the console.

If we execute ip addr | head -n 20 again, we will see the previous IP address.

Image description

Step 4: Reboot

The last step is to reboot the VM

Test the connection

Now we can connect to the VM using the command ssh [email protected]

Top comments (0)

pic

Templates let you quickly answer FAQs or store snippets for re-use.

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink .

Hide child comments as well

For further actions, you may consider blocking this person and/or reporting abuse

mhadi2003 profile image

spinnercss - 32 different types of spinners

Mahdi - Feb 6

jaredcodes profile image

From JS Basics to Actually Building Stuff

Jared Weiss - Feb 6

durgesh4993 profile image

Websites That Offer Free Certification Courses

Durgesh kumar prajapati - Feb 18

webbricks profile image

Landing Page vs Website: What Are the Differences?

Web Bricks - Feb 5

Once suspended, pauladj will not be able to comment or publish posts until their suspension is removed.

Once unsuspended, pauladj will be able to comment and publish posts again.

Once unpublished, all posts by pauladj will become hidden and only accessible to themselves.

If pauladj is not suspended, they can still re-publish their posts from their dashboard.

Once unpublished, this post will become invisible to the public and only accessible to Paula.

They can still re-publish the post if they are not suspended.

Thanks for keeping DEV Community safe. Here is what you can do to flag pauladj:

pauladj consistently posts content that violates DEV Community's code of conduct because it is harassing, offensive or spammy.

Unflagging pauladj will restore default visibility to their posts.

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

IMAGES

  1. Configure centos 7 static ip

    assign ip centos 7

  2. How to configure a static IP address on CentOS 7 / RHEL 7

    assign ip centos 7

  3. How to assign ip address on CentOS 7

    assign ip centos 7

  4. How to setup a static IP address on Centos 7 / RHEL 7

    assign ip centos 7

  5. How to configure a static IP address in CentOS 7

    assign ip centos 7

  6. How to assign Static IP Address in CentOS 7.3

    assign ip centos 7

VIDEO

  1. centos 6 IP address configuration part 1

  2. Does Your Router Assign IP Addresses?

  3. 14 CentOS 7 Hostname

  4. Merubah ip centos 6.10

  5. 006 internet connection on centos

  6. Configure static IP address on CentOS 7

COMMENTS

  1. How to configure a static IP address on CentOS 7 / RHEL 7

    Type the following ip command: # ip a Fig.01: List NICs in a CentOS 7 server using ip command Or use the following command: # nmcli -p dev Fig.02: nmcli command in action Here is a typical DHCP configration for eth0 (stored in /etc/sysconfig/network-scripts/ifcfg-eth0 file):

  2. How to configure a static IP address in CentOS 7

    Configuring the address Within the directory /etc/sysconfig/network-scripts/ you should find the file ifcfg-INTERFACENAME (Where INTERFACENAME is the name of your interface). In my instance, the...

  3. How To Configure Static IP Address in CentOS 7 / RHEL 7

    Method 1 In this method, we will edit the network interface file found under /etc/sysconfig/network-scripts/ directory. For interface enp0s3, the file name would be ifcfg-enp0s3. vi /etc/sysconfig/network-scripts/ifcfg-enp0s3 Update the interface file as per the requirement.

  4. How to Configure Network Static IP Address on RHEL/CentOS 8/7

    Step 1: Disable Unwanted System Services in CentOS 1. Before actually starting to do anything we need to make sure that our system has some necessary editing and networking tools like netstat, ifconfig, wget, curl, and lsof installed, some of them will not be used on this step but it's better to have them installed for future configurations.

  5. How to Configure CentOS Network Settings {via terminal or GUI)

    1. First, find the name of the network interface you want to change using the network manager command-line tool. Prompt the system to list all network devices, along with network details: nmcli d In our example, we will change the configuration for the first network. 2. To do so, open the network's configuration file by typing the following:

  6. How can I set a static IP address in CentOS 7?

    1 Answer 1. Sorted by: Reset to default. Highest score (default) Date modified (newest first) Date created (oldest first) 0. Try following: TYPE=Ethernet DEVICE=enp0s8 IPADDR=192.168.100.101 NETMASK=255.255.255. ONBOOT=yes NOZEROCONF=yes USERCTL=no NM_CONTROLLED=no. I believe your problem is primary in the missing NM_CONTROLLED=no.

  7. How To Configure a Static IP Address on CentOS 7/8

    Method 1 - Using Network Configuration File 1) First determinte the name of your network adapter by running the following: sudo lshw -class network -short 2) Using your favourite text editor open the configuration file for your network adapter, replacing X with the name of your network adapter determined in the previous step.

  8. Configure Static IP Address on CentOS 8|CentOS 7

    To configure static IP address on CentOS, you can use any of the following methods: Directing editing network configuration file under /etc/sysconfig/network-scripts/ directory. Using nmcli network configuration command line tool Using nmtui network configuration tool Making static IP address configuration using ip and ifconfig commands.

  9. How to configure a static IP address on CentOS 7

    Here are two different ways to assign a static IP address to a network interface on CentOS 7. We will be configuring a network interface named enp0s3. Configure a Static IP Address without Network Manager Go to the /etc/sysconfig/network-scripts directory, and locate the configuration file of the interface ( ifcfg-enp0s3 ). Create it if not found.

  10. Static IP Configuration on CentOS 7

    How to configure Static IP Configuration on CentOS 7? Network configuration on CentOS 7 is made automatic and simple through the use of Network Manager. It manages network interfaces like Ethernet, WiFi, and Mobile Broadband devices, in addition to the primary network connection.

  11. How to Configure a Static IP address on CentOS/RHEL 7

    Below are basic configuration instructions to setup a static IP address on CentOS/RHEL 7. 1. First, list your network interfaces with ip command: # ip add show. Make a note of network interface you would like to set with static IP address. 2. Next, locate a corresponding script to the network interface name. In our case this is enp0s3 located ...

  12. Easy guide to assign Static IP Address on CentOS / RHEL (7 & 8)

    There are two ways we can assign a static IP address in CentOS 8 systems, 1- Using Network manager 2- Assigning IP using network files. Let's discuss both these methods one by one. Recommended Read: IP Route command: Create static routes or Change the default Gateway in Linux Also Read: How to manage network in Ubuntu 18.04 - Netplan Command 1- Assign static IP using Network Manager

  13. How to setup a static IP address on Centos 7 / RHEL 7

    In this article we will explain how to setup a static IP address on Centos 7 / RHEL 7.There are several ways to configure a static IP address. 1. nmtui Tool ( Network Configuration Text User Interface)

  14. How to Install and Use ifconfig on CentOS 7

    How to Install the ifconfig Command. The ifconfig command is part of the net-tools package available in the YUM repository. 1. Open the terminal window and update the repositories: sudo yum update. 2. Next, download and install net-tools using yum: sudo yum install net-tools -y.

  15. How to configure IP addresses on CentOS

    Step 1: Log in to your server as root Go to directory /etc/sysconfig/network-scripts cd /etc/sysconfig/network-scripts Determine the interface that the OS will be using to add the IP address. /sbin/ifconfig The output should look like this. Step 2: Determining the interface

  16. How To Configure IP Address in CentOS 7 / RHEL 7 & CentOS 6 ...

    This guide helps you to Configure IP Address in CentOS 7 / RHEL 7 & CentOS 6 / RHEL 6. Here I will show how to configure Static IP addresses for your machine and also configure the network interface to get an IP address from the DHCP server. Prerequisites. Let's check the available interfaces on our system. Use the ifconfig command to list ...

  17. Configure IP address in Linux (RHEL/CentOS 7)

    Apart from these three methods, you can also configure IP address when installing operating system & also there are two more methods through which we can configure our network on RHEL/CentOS 7 machines i.e. by using ' nmcli command & ifconfig command. This wraps up our tutorial on how to configure IP address in Linux.

  18. bash

    How assign static ip to centOS 7? Ask Question Asked 5 years, 11 months ago Modified 5 years, 11 months ago Viewed 3k times 3 I am using centOS 7 and my machine is changing IP randomly on restart. So, I want to assign IP static to get-rid from further changes on other areas.

  19. linux

    You must add nic to your VM and centos must have driver for this nic. After that you can ask a question in "Unix & Linux Stack Exchange" (how to configure network connection in centos7) or try to configure it youself. I recommend to do something like: [root@centos7]# nmcli con show NAME UUID TYPE DEVICE enp0s3 d77bd8ad-ec13-4442-bb2b ...

  20. How to Configure Static IP in CentOS 7

    Configuration details. For this tutorial, we will use the following details: IP address: 192.168.12.23 Subnet mask: 255.255.255. 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:

  21. Easy guide to assign Static IP Address on CentOS / RHEL (7 & 8)

    Usually, when we enable our network interface on our CentOS 7 or 8 systems, an IP address is assigned automatically through that DHCP server & we have access to the internet or to our LAN...

  22. How to configure a static IP address on CentOS 7 with VirtualBox

    Step 1: Stop the VM You have to stop the VM before doing the following steps. Step 2: Create Ethernet Adapter Click on Tools - Networks and make sure you have an ethernet adapter created. Write down the IPv4 Prefix, because the static IP will be in this range. In the image above: The gateway is 192.168.56.1

  23. Assign IP range in centOS 7 to network interface

    Assign IP range in centOS 7 to network interface Ask Question Asked 5 years, 8 months ago Modified 5 days ago Viewed 2k times 1 Helllo to all, I'm very new to server administration, so I have a big question for me. What is the best way to assign a ip range to the network interface on the server?