在RHEL7中默认使用NetworkManager 守护进程来监控和管理网络设置。nmcli是命令行的管理NetworkManager的工具,会自动把配置写到/etc/sysconfig/network-scripts/目录下面。

nmcli是一个很方便的配置网络的工具

比如如下

[root@rhel7 ~]# nmcli con show

NAME         UUID                                  TYPE            DEVICE
System eth0  5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03  802-3-ethernet  eth0  
[root@rhel7 ~]# nmcli con edit "System eth0"
nmcli> set ipv4.addresses 192.168.0.100/24 192.168.0.254
nmcli> save
Connection 'System eth0' (5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03) successfully updated.
nmcli> activate eth0
Monitoring connection activation (press any key to continue)
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/1)

nmcli> quit

好了,上面你就把IP地址配置好了,并且已经使用activate激活,已经可以用了,并且是自动写到配置文件里面,重启也生效的

你如果想修改现有的ip的话

[root@rhel7 ~]# nmcli con modify "System eth0" ipv4.addresses 192.168.0.200/24

[root@rhel7 ~]# nmcli con up "System eth0"

如上两条命令就可以了

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------

上面是命令演示下面说一下原理,在RHEL7中对网络的配置,不是像原来是基于网卡的。

在rhel7中是基于会话(connection)的,一个网卡可以有多个会话,但是同时只允许一个会话处于激活(active)状态。

基于会话有什么好处呢?

比如公司使用的是DHCP分配的IP来连接网络,家里使用的是静态的IP地址。

这时我就可以创建两个会话,一个使用DHCP联网,另一个配置静态ip地址,在公司激活(active)DHCP,在家里激活静态。

这样就省去了,频繁修改ip的麻烦。

下面为创建并使用多个会话的演示

1.创建一个会话,名字叫做“default”,它通过DHCP获取IP,自动连接网络,网卡名为eno16777736

[root@rhel7 ~]# nmcli connection add con-name default type ethernet ifname eno16777736

connection  ---》会话,可以简写为con

add ---》添加

con-name    ----》会话名自己随便定义

type ethernet ---》类型以太网卡

ifname   ----》接口名,也就是网卡名

2.创建另一个会话叫做“static”并且指定它的ip和网关。但是不能自动连接网络。

[root@rhel7 ~]# nmcli connection add con-name static ifname eno16777736 autoconnect no type ethernet ip4 192.168.0.111/24 gw4 192.168.0.254

3.默认情况下,系统启动之后会自动使用DHCP连接,但是我们可以手动改为静态ip的会话。

[root@rhel7 ~]# nmcli connection up static

4.重新改为DHCP获取IP

[root@rhel7 ~]# nmcli connection up default

5.查当前有什么会话

[root@rhel7 ~]# nmcli connection show

6.详细的查看会话的配置信息,比如查看static

[root@rhel7 ~]# nmcli connection show “static”

7.查看当前活动的会话

[root@rhel7 ~]# nmcli connection show --active

------------------------------------------------------------------------------------------------------------------------------------------------------

修改现存的会话

1.关闭会话的自动连接(autoconnect)。

[root@rhel7 ~]# nmcli con mod "static" connection.autoconnect no

2.指定一个DNS服务器地址

[root@rhel7 ~]# nmcli con mod "static" ipv4.dns 8.8.8.8

3.有一些配置参数,是可以添加和删除的,比如使用+ 或 - 号在参数前面。比如添加第二个DNS服务器地址

[root@rhel7 ~]# nmcli con mod "static" +ipv4.dns 8.8.4.4

4.更换静态IP地址和默认网关。

[root@rhel7 ~]# nmcli con mod "static" ipv4.addresses  “192.168.0.120/24   192.168.0.1”

5.添加第二个ip

[root@rhel7 ~]# nmcli con mod "static" +ipv4.addresses  192.168.0.130/24      

注:nmcli con mod修改的配置,会自动保存成配置文件,并且重启后依然有效,但是如果配置更改了,你需要从新激活一下,使新配置生效。

[root@rhel7 ~]# nmcli con up "static"

补充:在rhel7中查看ip地址等信息可以使用

[root@rhel7 ~]# ip addr    ----》可以简写为 ip a

查看自己的路由可以使用

[root@rhel7 ~]# ip route

via:https://www.rhel.cc/2014/11/82/

RHEL7网络管理之nmcli的更多相关文章

  1. RHEL7网络管理NetworkManager和nmcli指令

    1.NetworkManager简介 在 Red Hat Enterprise Linux 7 中,NetworkManager 提供的默认联网服务是一个动态网络控制和配置守护 进程,它尝试在其可用时 ...

  2. CentOS7 网络管理工具nmcli

    今天帮别人调试虚拟机的网络问题(CentOS 7系统),习惯性直接改/etc/sysconfig/network-scripts/ifcfg-xxx配置文件,但是不知道为什么重启network后静态i ...

  3. rhel7网络管理

    实验-禁用网卡命名规则: 在GRUB_CMDLINE_Linux=“rd.lvm.lv=rhel/root  vconsole.keymap=us vconsole.font=latarcyheb-s ...

  4. 【RHEL7/CentOS7基本配置】

    目录 @ 相比于6.x的版本,Rhel7/CentOS7增加或改进了以下7大特性. 1.身份管理 kerberos的跨平台信任机制:kerberos将完全兼容微软活动目录,实现完全使用活动目录进行认证 ...

  5. centos7 U盘安装及Raid划分的完整流程

    目录 一.Centos7的新特性: 二.安装方法与准备工作(U盘镜像) 1. 安装方法介绍 2. Centos iso 常用镜像下载地址: 3. UltraISO制作U盘系统镜像 3.1 准备工作: ...

  6. 使用bind部署DNS主从服务器

    说明:这里是Linux服务综合搭建文章的一部分,本文可以作为单独搭建主从DNS服务器的参考. 注意:这里所有的标题都是根据主要的文章(Linux基础服务搭建综合)的顺序来做的. 如果需要查看相关软件版 ...

  7. Configure a VLAN on top of a team with NetworkManager (nmcli) in RHEL7

    SOLUTION VERIFIED September 13 2016 KB1248793 Environment Red Hat Enterprise Linux 7 NetworkManager ...

  8. Nmcli 网络管理命令行工具基础

    介绍 在本教程中,我们会在CentOS / RHEL 7中讨论网络管理命令行工具NetworkManager command line tool,也叫nmcli.那些使用ifconfig的用户应该在C ...

  9. Linux nmcli 网络管理

    Linux nmcli 网络管理 RHEL 和 CentOS 系统默认使用 NetworkManager 来提供网络服务,这是一种动态管理网络配置的守护进程,能够让网络设备保持连接状态.可以使用 nm ...

随机推荐

  1. <script>标签应该放到</body>标签之前

    著作权归作者所有. 商业转载请联系作者获得授权,非商业转载请注明出处. 作者:贺师俊 链接:http://www.zhihu.com/question/20027966/answer/13727164 ...

  2. There is already an open DataReader associated with this Command which must be closed first." exception in Entity Framework

    Fixing the "There is already an open DataReader associated with this Command which must be clos ...

  3. jquery选择器之内容选择器

    HTML示例代码 <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...

  4. Type Project has no default.properties file! Edit the project properties to set one.

    Description Resource Path Location Type Project has no default.properties file! Edit the project pro ...

  5. Internetware网构软件(摘抄)

    The Internet provides a global open infrastructure for exchanging and sharing of various resources f ...

  6. linux下的vim使用教程

    命令历史 以:和/开头的命令都有历史纪录,可以首先键入:或/然后按上下箭头来选择某个历史命令. 启动vim 在命令行窗口中输入以下命令即可 vim 直接启动vim vim filename 打开vim ...

  7. android.view.WindowLeaked

    08-30 13:17:05.645 25543-25543/com.tongyan.nanjing.subway E/WindowManager: android.view.WindowLeaked ...

  8. [IIS]IIS扫盲(六)

    一:聊天室  聊天室的种类有很多,免费的聊天室也有很多,这些聊天室的ASP源码从网上都可以下载得到,我们就以毒爱聊天室为版本来教大家做.好,大家先下载毒爱聊天室,当然,本站软件下载里就有下载,下载的是 ...

  9. (String) 205.Isomorphic Strings

    Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...

  10. 使用Maven编译项目时提示程序包javax.servlet.http不存在

    将apache-tomcat-8.0.23\lib下的servlet-api.jar拷贝到C:\Program Files\Java\jdk1.8.0_31\jre\lib\ext下即可