Question: On CentOS 7, I want to switch from DHCP to static IP address configuration with one of my network interfaces. What is a proper way to assign a static IP address to a network interface permanently on CentOS or RHEL 7?

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:

$ systemctl status NetworkManager.service

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

$ nmcli dev status

<img src="https://farm4.staticflickr.com/3861/15295802711_a102a3574d_z.jpg">

If the output of nmcli shows "connected" for a particular interface (e.g., enp0s3 in the 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 its configuration file (ifcfg-enp0s3). Create it if not found.

<img src="https://farm4.staticflickr.com/3911/15112399977_d3df8e15f5_z.jpg">

Open the configuration file and edit the following variables:

<img src="https://farm4.staticflickr.com/3880/15112184199_f4cbf269a6.jpg">

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:

# systemctl restart network.service

Now verify that the interface has been properly configured:

# ip add

<img src="https://farm6.staticflickr.com/5593/15112397947_ac69a33fb4_z.jpg">

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.

# yum install NetworkManager-tui

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

# nmtui edit enp0s3

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:

<img src="https://farm4.staticflickr.com/3878/15295804521_4165c97828_z.jpg">

Finally, restart the network service.

# systemctl restart network.service

and you're ready to go.

How to configure a static IP address on CentOS 7(CentOS7静态IP地址设置)的更多相关文章

  1. CentOS 6.5静态IP的设置(NAT和桥接都适用)

    CentOS 6.5静态IP的设置(NAT和桥接都适用) 为了方便,用Xshell来.并将IP设置为静态的.因为,在CentOS里,若不对其IP进行静态设置的话,则每次开机,其IP都是动态变化的,这样 ...

  2. CentOS 7 配置静态IP后不生效 & Job for network.service failed

    参考:http://tieba.baidu.com/p/3233996339#57290767555l 在CentOS中配置静态IP后不生效. 解决办法:将/etc/sysconfig/network ...

  3. 为CentOS 7配置静态IP地址及遇到的问题解决策略

    为CentOS 7配置静态IP地址及遇到的问题解决策略 1. 为CentOS 7配置静态IP地址的两种方法 (原文地址:http://www.linuxidc.com/Linux/2014-10/10 ...

  4. centos系统设置局域网静态IP

    ---恢复内容开始--- centos系统设置局域网静态IP 很多时候,我们并不希望漏油器重启之后,自己的服务器动态的获取IP,这样很不利,因为你可能装了mysql,redis,等软件,然后需要远程去 ...

  5. centos 7配置静态IP,并配置DNS

    注意:四 个文件 cat /etc/sysconfig/network-scripts/ifcfg-eth0 cat /etc/sysconfig/network cat /etc/resolv.co ...

  6. 33. CentOS7 静态ip设置

    1.网络连接选择NAT模式: 2.关闭vmware的dhcp:选择编辑-->虚拟网络编辑器,选择VMnet8,去掉使用本地DHCP服务将ip地址分配给虚拟机(D). 3. 点击NAT设置(S)查 ...

  7. 如何为CentOS 7配置静态IP地址

    问题:在CentOS 7上,我想要将我其中一个网络接口从DHCP改为静态IP地址配置,如何才能永久为CentOS或RHEL 7上的网络接口分配静态IP地址? 如果你想要为CentOS 7中的某个网络接 ...

  8. CentOS 7配置静态IP地址的两种方法 来自:互联网

    CentOS 7配置静态IP地址的两种方法 来自:互联网 时间:2021-01-12 阅读:4 如果你想要为CentOS 7中的某个网络接口设置静态IP地址,有几种不同的方法,这取决于你是否想要使用网 ...

  9. Mac VMware Fusion Centos7 静态ip配置

    一直没用mac装过虚拟机,最近因为一些原因不得不装一个,但是被这个静态ip配置把头都搞痛了(这里吐槽一下百度,我前几页都看了几遍,搜索关键字就是我现在的标题,结果都是一些抄抄抄并且不管用的攻略,最后使 ...

随机推荐

  1. 这些年正Android - 母亲

    记得小时候,在自己写完一篇作文,完成母亲布置的任务后,就会搬走母亲正在使用的大椅子,面朝门前的马路,就这么憧憬的坐着,听着母亲给小孩打针时,小孩哇哇的哭声,努力的幻想着自己以后能做一个顶天立地的男子汉 ...

  2. SQL Server Reporting Services (SSRS): Reporting Services in SQL Server 2012 (codename "Denali") will support XLSX, DOCX formats. Bye bye 65536 rows limit in XLS files ;)

    当SSRS报表的时候,若相应EXCEL是2003以下,在行数超过65536的时候报表会报错 "Microsoft.ReportingServices.ReportProcessing.Han ...

  3. WebViewJavascriptBridge详细使用(转载)

    WebViewJavascriptBridge是支持到iOS6之前的版本的,用于支持native的iOS与javascript交互.如果需要支持到iOS6之前的app,使用它是很不错的.本篇讲讲Web ...

  4. IIS7 IIS8 中多个版本php共存的方法

    原文地址: https://blog.cozof.com/pieces/54.shtml 最近又重回.net,用回IIS.然后用到某个php开源项目,需要低版本的php,之前装的一个php5.5不能用 ...

  5. sellsa

    我看见天空很蓝 就像你在我身边的温暖 生命有太多遗憾 人越成长越觉得孤单 我很想飞 多远都不会累 才明白爱得越深心就会越痛 我只想飞 在我的天空飞 我知道你会在我身边 回忆的画面 记录的语言 爱始终是 ...

  6. Numpy应用100问

    对于从事机器学习的人,python+numpy+scipy+matplotlib是重要的基础:它们基本与matlab相同,而其中最重要的当属numpy:因此,这里列出100个关于numpy函数的问题, ...

  7. redis 基本数据类型

    概述 Redis的键值可以使用物种数据类型:字符串,散列表,列表,集合,有序集合.本文详细介绍这五种数据类型的使用方法.本文命令介绍部分只是列举了基本的命令,至于具体的使用示例,可以参考Redis官方 ...

  8. 自己实现多线程的socket,socketserver源码剖析

    1,IO多路复用 三种多路复用的机制:select.poll.epoll 用的多的两个:select和epoll 简单的说就是:1,select和poll所有平台都支持,epoll只有linux支持2 ...

  9. iOS图片加载到内存中占用内存情况

    我的测试结果: 图片占用内存   图片尺寸           .png文件大小 1MB              512*512          316KB 4MB              10 ...

  10. python3.5------用户的三次验证

    笔者QQ: 360212316 逻辑图 代码 #/usr/bin/python # -*- coding: utf-8 -*- lock = open("black_user_list.tx ...