CentOS 7网络配置工具

       CentOS 7网络配置工具

                       作者:尹正杰

版权声明:原创作品,谢绝转载!否则将追究法律责任。

 

 

 

一.网卡命名机制

CentOS 6之前,网络接口使用连续号码命名:eth0、eth1等,当增加或删除网卡时,名称可能会发生变化

CentOS 7使用基于硬件,设备拓扑和设置类型命名,systemd对网络设备的命名方式规则如下:
  (1)如果Firmware或BIOS为主板上集成的设备提供的索引信息可用,且可预测则根据此索引进行命名,例如eno1
  (2)如果Firmware或BIOS为PCI-E扩展槽所提供的索引信息可用,且可预测,则根据此索引进行命名,例如ens1
  (3)如果硬件接口的物理位置信息可用,则根据此信息进行命名,例如enp2s0
  (4)如果用户显式启动,也可根据MAC地址进行命名,例如enx2387a1dc56
  (5)上述均不可用时,则使用传统命名机制,例如:eth0,eth1

为什么CentOS 6和CentOS 7之间网卡命名会有如此大的变化呢?
  因为早期有客户反应为服务器扩展物理网卡时出现了配置文件与服务器网卡不对应的情况。如,原来服务器只有一块网卡,运维人员为其定义了一个配置文件"ifcf-eth0",当添加第二块物理网卡时,发现重启操作后,之前定义的"ifcf-eth0"配置文件竟然识别了新的物理网卡的显现!由此,对网卡的命名推出了以上一系列措施,不过看上面的策略看起来还是不错的。
  由于生成环境中我们很少碰到频繁更换物理网卡的现象,我们可以采用传统式命名,为了运维自动化打好基础,首先得标准化(我们先从网卡命名规则统一开始)。

1>.基于BIOS支持启用biosdevname(dell公司研发)软件

Dell服务器的内置网卡命名规则:
  em1,em2 Dell外接的pci网卡命名规则:
  pYpX Y:slot ,X:port

2>.名称组成格式

en: 
  Ethernet 有线局域网 wl:
  wlan 无线局域网 ww:
  wwan无线广域网

3>.名称类型

o<index>: 
  集成设备的设备索引号
s<slot>: 
  扩展槽的索引号 x
<MAC>:
  基于MAC地址的命名 p
<bus>s<slot>:
  基于硬件接口的物理位置信息如:enp2s1

4>.采用传统命名方式

具体步骤如下:
  (1)编辑/etc/default/grub配置文件(或:修改/boot/grub2/grub.cfg)   GRUB_CMDLINE_LINUX="... rhgb quiet net.ifnames=0"   (2)为grub2生成其配置文件   grub2-mkconfig -o /etc/grub2.cfg(该文件是一个软连接)
  (
3)重启系统

  (4)别忘记修改网卡的配置文件哟~
[root@node101.yinzhengjie.org.cn ~]# cat /etc/default/grub 
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet"
GRUB_DISABLE_RECOVERY="true"
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# vim /etc/default/grub 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# cat /etc/default/grub 
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet net.ifnames=0"
GRUB_DISABLE_RECOVERY="true"
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# vim /etc/default/grub
[root@node101.yinzhengjie.org.cn ~]# cat /boot/grub2/grub.cfg   
#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub2-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#

### BEGIN /etc/grub.d/00_header ###
set pager=1

if [ -s $prefix/grubenv ]; then
  load_env
fi
if [ "${next_entry}" ] ; then
   set default="${next_entry}"
   set next_entry=
   save_env next_entry
   set boot_once=true
else
   set default="${saved_entry}"
fi

if [ x"${feature_menuentry_id}" = xy ]; then
  menuentry_id_option="--id"
else
  menuentry_id_option=""
fi

export menuentry_id_option

if [ "${prev_saved_entry}" ]; then
  set saved_entry="${prev_saved_entry}"
  save_env saved_entry
  set prev_saved_entry=
  save_env prev_saved_entry
  set boot_once=true
fi

function savedefault {
  if [ -z "${boot_once}" ]; then
    saved_entry="${chosen}"
    save_env saved_entry
  fi
}

function load_video {
  if [ x$feature_all_video_module = xy ]; then
    insmod all_video
  else
    insmod efi_gop
    insmod efi_uga
    insmod ieee1275_fb
    insmod vbe
    insmod vga
    insmod video_bochs
    insmod video_cirrus
  fi
}

terminal_output console
if [ x$feature_timeout_style = xy ] ; then
  set timeout_style=menu
  set timeout=5
# Fallback normal timeout code in case the timeout_style feature is
# unavailable.
else
  set timeout=5
fi
### END /etc/grub.d/00_header ###

### BEGIN /etc/grub.d/00_tuned ###
set tuned_params=""
set tuned_initrd=""
### END /etc/grub.d/00_tuned ###

### BEGIN /etc/grub.d/01_users ###
if [ -f ${prefix}/user.cfg ]; then
  source ${prefix}/user.cfg
  if [ -n "${GRUB2_PASSWORD}" ]; then
    set superusers="root"
    export superusers
    password_pbkdf2 root ${GRUB2_PASSWORD}
  fi
fi
### END /etc/grub.d/01_users ###

### BEGIN /etc/grub.d/10_linux ###
menuentry 'CentOS Linux (3.10.0-957.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menue
ntry_id_option 'gnulinux-3.10.0-957.el7.x86_64-advanced-7e5d6996-5762-4909-8717-6dd8d6d30a0e' {    load_video
    set gfxpayload=keep
    insmod gzio
    insmod part_msdos
    insmod xfs
    set root='hd0,msdos1'
    if [ x$feature_platform_search_hint = xy ]; then
      search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd
0,msdos1'  343e9f9c-8324-4918-a10d-541627af8e04    else
      search --no-floppy --fs-uuid --set=root 343e9f9c-8324-4918-a10d-541627af8e04
    fi
    linux16 /vmlinuz-3.10.0-957.el7.x86_64 root=/dev/mapper/centos-root ro crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/
swap rhgb quiet LANG=en_US.UTF-8      #温馨提示,其实咱们也可以直接修改这里,在这后面直接添加"net.ifnames=0"即可。
    initrd16 /initramfs-3.10.0-957.el7.x86_64.img
}
menuentry 'CentOS Linux (0-rescue-9ccdf621e5984f3b8626614f6fa15a48) 7 (Core)' --class centos --class gnu-linux --class gnu --class os -
-unrestricted $menuentry_id_option 'gnulinux-0-rescue-9ccdf621e5984f3b8626614f6fa15a48-advanced-7e5d6996-5762-4909-8717-6dd8d6d30a0e' {    load_video
    insmod gzio
    insmod part_msdos
    insmod xfs
    set root='hd0,msdos1'
    if [ x$feature_platform_search_hint = xy ]; then
      search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd
0,msdos1'  343e9f9c-8324-4918-a10d-541627af8e04    else
      search --no-floppy --fs-uuid --set=root 343e9f9c-8324-4918-a10d-541627af8e04
    fi
    linux16 /vmlinuz-0-rescue-9ccdf621e5984f3b8626614f6fa15a48 root=/dev/mapper/centos-root ro crashkernel=auto rd.lvm.lv=centos/ro
ot rd.lvm.lv=centos/swap rhgb quiet    
    initrd16 /initramfs-0-rescue-9ccdf621e5984f3b8626614f6fa15a48.img
}

### END /etc/grub.d/10_linux ###

### BEGIN /etc/grub.d/20_linux_xen ###
### END /etc/grub.d/20_linux_xen ###

### BEGIN /etc/grub.d/20_ppc_terminfo ###
### END /etc/grub.d/20_ppc_terminfo ###

### BEGIN /etc/grub.d/30_os-prober ###
### END /etc/grub.d/30_os-prober ###

### BEGIN /etc/grub.d/40_custom ###
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
### END /etc/grub.d/40_custom ###

### BEGIN /etc/grub.d/41_custom ###
if [ -f  ${config_directory}/custom.cfg ]; then
  source ${config_directory}/custom.cfg
elif [ -z "${config_directory}" -a -f  $prefix/custom.cfg ]; then
  source $prefix/custom.cfg;
fi
### END /etc/grub.d/41_custom ###
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# cat /boot/grub2/grub.cfg   #其实也可以直接修改该文件,但不推荐,建议修改"/etc/default/grub"(该文件会参考"/etc/defaullt/grub"做响应的调整,该文件的注释有说明)
[root@node101.yinzhengjie.org.cn ~]# ll /etc/grub2.cfg
lrwxrwxrwx. 1 root root 22 Jul  8 16:23 /etc/grub2.cfg -> ../boot/grub2/grub.cfg
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# grub2-mkconfig -o /etc/grub2.cfg    #为grub2生成其配置文件
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-957.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-957.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-9ccdf621e5984f3b8626614f6fa15a48
Found initrd image: /boot/initramfs-0-rescue-9ccdf621e5984f3b8626614f6fa15a48.img
done
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# grub2-mkconfig -o /etc/grub2.cfg    #为grub2生成其配置文件

 

二.CentOS 7网络配置工具-nmcli命令

1>.CentOS 7网络配置工具概述

图形工具:nm-connection-editor

字符配置tui工具:nmtui

命令行工具:nmcli

2>.nmcli支持命令补全(最小化安装需要安装额外的包)

[root@node104.yinzhengjie.org.cn ~]# yum -y install bash-completion.noarch
Loaded plugins: fastestmirror
Determining fastest mirrors
 * base: mirror.jdcloud.com
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirrors.tuna.tsinghua.edu.cn
base                                                                                                                      | 3.6 kB  00:00:00     
extras                                                                                                                    | 2.9 kB  00:00:00     
updates                                                                                                                   | 2.9 kB  00:00:00     
(1/4): base/7/x86_64/group_gz                                                                                             | 165 kB  00:00:05     
(2/4): extras/7/x86_64/primary_db                                                                                         | 153 kB  00:00:06     
(3/4): base/7/x86_64/primary_db                                                                                           | 6.0 MB  00:00:07     
(4/4): updates/7/x86_64/primary_db                                                                                        | 4.2 MB  00:00:09     
Resolving Dependencies
--> Running transaction check
---> Package bash-completion.noarch 1:2.1-6.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=================================================================================================================================================
 Package                                 Arch                           Version                               Repository                    Size
=================================================================================================================================================
Installing:
 bash-completion                         noarch                         1:2.1-6.el7                           base                          85 k

Transaction Summary
=================================================================================================================================================
Install  1 Package

Total download size: 85 k
Installed size: 259 k
Downloading packages:
bash-completion-2.1-6.el7.noarch.rpm                                                                                      |  85 kB  00:00:05     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 1:bash-completion-2.1-6.el7.noarch                                                                                            1/1 
  Verifying  : 1:bash-completion-2.1-6.el7.noarch                                                                                            1/1 

Installed:
  bash-completion.noarch 1:2.1-6.el7                                                                                                             

Complete!
[root@node104.yinzhengjie.org.cn ~]#
[root@node104.yinzhengjie.org.cn ~]# yum -y install bash-completion.noarch   

3>.查看网卡的状态(如当前主机的接口是否正常)

[root@node101.yinzhengjie.org.cn ~]# nmcli device
DEVICE  TYPE      STATE      CONNECTION         
eth0    ethernet  connected  Wired connection 1 
eth1    ethernet  connected  System eth1        
lo      loopback  unmanaged  --                 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# nmcli device

3>.显示所有(包括不活动)连接

[root@node101.yinzhengjie.org.cn ~]# nmcli connection show
NAME                UUID                                  TYPE      DEVICE 
System eth1         9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04  ethernet  eth1   
Wired connection 1  80a31b55-2247-3880-8aae-5154a3b47040  ethernet  eth0   
System enp0s3       3c36b8c2-334b-57c7-91b6-4401f3489c69  ethernet  --     
System enp0s8       00cb8299-feb9-55b6-a378-3fdc720e0bc6  ethernet  --     
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# nmcli connection
NAME                UUID                                  TYPE      DEVICE 
System eth1         9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04  ethernet  eth1   
Wired connection 1  80a31b55-2247-3880-8aae-5154a3b47040  ethernet  eth0   
System enp0s3       3c36b8c2-334b-57c7-91b6-4401f3489c69  ethernet  --     
System enp0s8       00cb8299-feb9-55b6-a378-3fdc720e0bc6  ethernet  --     
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ll /etc/sysconfig/network-scripts/ifcfg-*
-rw-r--r--. 1 root root  54 Jul  8 18:36 /etc/sysconfig/network-scripts/ifcfg-enp0s3
-rw-r--r--. 1 root root 137 Jul  8 18:37 /etc/sysconfig/network-scripts/ifcfg-enp0s8
-rw-r--r--  1 root root 135 Nov 18 06:28 /etc/sysconfig/network-scripts/ifcfg-eth1
-rw-r--r--. 1 root root 254 Aug 24  2018 /etc/sysconfig/network-scripts/ifcfg-lo
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# nmcli connection show

4>.显示所有活动连接

[root@node101.yinzhengjie.org.cn ~]# nmcli connection show 
NAME                UUID                                  TYPE      DEVICE 
System eth1         9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04  ethernet  eth1   
Wired connection 1  80a31b55-2247-3880-8aae-5154a3b47040  ethernet  eth0   
System enp0s3       3c36b8c2-334b-57c7-91b6-4401f3489c69  ethernet  --     
System enp0s8       00cb8299-feb9-55b6-a378-3fdc720e0bc6  ethernet  --     
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# nmcli connection show --active
NAME                UUID                                  TYPE      DEVICE 
System eth1         9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04  ethernet  eth1   
Wired connection 1  80a31b55-2247-3880-8aae-5154a3b47040  ethernet  eth0   
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# nmcli connection show --active

5>.显示网络连接配置

[root@node101.yinzhengjie.org.cn ~]# nmcli connection show 
NAME                UUID                                  TYPE      DEVICE 
System eth1         9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04  ethernet  eth1   
Wired connection 1  80a31b55-2247-3880-8aae-5154a3b47040  ethernet  eth0   
System enp0s3       3c36b8c2-334b-57c7-91b6-4401f3489c69  ethernet  --     
System enp0s8       00cb8299-feb9-55b6-a378-3fdc720e0bc6  ethernet  --     
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# nmcli connection show System\ eth1 
connection.id:                          System eth1
connection.uuid:                        9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04
connection.stable-id:                   --
connection.type:                        802-3-ethernet
connection.interface-name:              eth1
connection.autoconnect:                 yes
connection.autoconnect-priority:        0
connection.autoconnect-retries:         -1 (default)
connection.auth-retries:                -1
connection.timestamp:                   1574031514
connection.read-only:                   no
connection.permissions:                 --
connection.zone:                        --
connection.master:                      --
connection.slave-type:                  --
connection.autoconnect-slaves:          -1 (default)
connection.secondaries:                 --
connection.gateway-ping-timeout:        0
connection.metered:                     unknown
connection.lldp:                        default
connection.mdns:                        -1 (default)
802-3-ethernet.port:                    --
802-3-ethernet.speed:                   0
802-3-ethernet.duplex:                  --
802-3-ethernet.auto-negotiate:          no
802-3-ethernet.mac-address:             --
802-3-ethernet.cloned-mac-address:      --
802-3-ethernet.generate-mac-address-mask:--
802-3-ethernet.mac-address-blacklist:   --
802-3-ethernet.mtu:                     auto
802-3-ethernet.s390-subchannels:        --
802-3-ethernet.s390-nettype:            --
802-3-ethernet.s390-options:            --
802-3-ethernet.wake-on-lan:             default
802-3-ethernet.wake-on-lan-password:    --
ipv4.method:                            manual
ipv4.dns:                               172.30.1.254
ipv4.dns-search:                        --
ipv4.dns-options:                       ""
ipv4.dns-priority:                      0
ipv4.addresses:                         172.30.1.101/24
ipv4.gateway:                           172.30.1.254
ipv4.routes:                            --
ipv4.route-metric:                      -1
ipv4.route-table:                       0 (unspec)
ipv4.ignore-auto-routes:                no
ipv4.ignore-auto-dns:                   no
ipv4.dhcp-client-id:                    --
ipv4.dhcp-timeout:                      0 (default)
ipv4.dhcp-send-hostname:                yes
ipv4.dhcp-hostname:                     --
ipv4.dhcp-fqdn:                         --
ipv4.never-default:                     no
ipv4.may-fail:                          yes
ipv4.dad-timeout:                       -1 (default)
ipv6.method:                            ignore
ipv6.dns:                               --
ipv6.dns-search:                        --
ipv6.dns-options:                       ""
ipv6.dns-priority:                      0
ipv6.addresses:                         --
ipv6.gateway:                           --
ipv6.routes:                            --
ipv6.route-metric:                      -1
ipv6.route-table:                       0 (unspec)
ipv6.ignore-auto-routes:                no
ipv6.ignore-auto-dns:                   no
ipv6.never-default:                     no
ipv6.may-fail:                          yes
ipv6.ip6-privacy:                       -1 (unknown)
ipv6.addr-gen-mode:                     stable-privacy
ipv6.dhcp-duid:                         --
ipv6.dhcp-send-hostname:                yes
ipv6.dhcp-hostname:                     --
ipv6.token:                             --
proxy.method:                           none
proxy.browser-only:                     no
proxy.pac-url:                          --
ipv6.dhcp-duid:                         --
ipv6.dhcp-send-hostname:                yes
ipv6.dhcp-hostname:                     --
ipv6.token:                             --
proxy.method:                           none
proxy.browser-only:                     no
proxy.pac-url:                          --
proxy.pac-script:                       --
GENERAL.NAME:                           System eth1
GENERAL.UUID:                           9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04
GENERAL.DEVICES:                        eth1
GENERAL.STATE:                          activated
GENERAL.DEFAULT:                        no
GENERAL.DEFAULT6:                       no
GENERAL.SPEC-OBJECT:                    --
GENERAL.VPN:                            no
GENERAL.DBUS-PATH:                      /org/freedesktop/NetworkManager/ActiveConnection/2
GENERAL.CON-PATH:                       /org/freedesktop/NetworkManager/Settings/2
GENERAL.ZONE:                           --
GENERAL.MASTER-PATH:                    --
IP4.ADDRESS[1]:                         172.30.1.101/24
IP4.GATEWAY:                            172.30.1.254
IP4.ROUTE[1]:                           dst = 172.30.1.0/24, nh = 0.0.0.0, mt = 101
IP4.ROUTE[2]:                           dst = 0.0.0.0/0, nh = 172.30.1.254, mt = 101
IP4.DNS[1]:                             172.30.1.254
IP6.GATEWAY:                            --
[root@node101.yinzhengjie.org.cn ~]# nmcli connection show System\ eth1   #推荐使用tab自动补齐

6>.显示设备状态

[root@node101.yinzhengjie.org.cn ~]# nmcli device status
DEVICE  TYPE      STATE      CONNECTION         
eth0    ethernet  connected  Wired connection 1 
eth1    ethernet  connected  System eth1        
lo      loopback  unmanaged  --                 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# nmcli dev status
DEVICE  TYPE      STATE      CONNECTION         
eth0    ethernet  connected  Wired connection 1 
eth1    ethernet  connected  System eth1        
lo      loopback  unmanaged  --                 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# nmcli device status

7>.显示网络接口属性

[root@node101.yinzhengjie.org.cn ~]# nmcli device show eth1 
GENERAL.DEVICE:                         eth1
GENERAL.TYPE:                           ethernet
GENERAL.HWADDR:                         08:00:27:C1:C7:46
GENERAL.MTU:                            1500
GENERAL.STATE:                          100 (connected)
GENERAL.CONNECTION:                     System eth1
GENERAL.CON-PATH:                       /org/freedesktop/NetworkManager/ActiveConnection/2
WIRED-PROPERTIES.CARRIER:               on
IP4.ADDRESS[1]:                         172.30.1.101/24
IP4.GATEWAY:                            172.30.1.254
IP4.ROUTE[1]:                           dst = 172.30.1.0/24, nh = 0.0.0.0, mt = 101
IP4.ROUTE[2]:                           dst = 0.0.0.0/0, nh = 172.30.1.254, mt = 101
IP4.DNS[1]:                             172.30.1.254
IP6.GATEWAY:                            --
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# nmcli device show eth1

8>.创建新连接default的配置文件,IP自动通过dhcp获取

[root@node101.yinzhengjie.org.cn ~]# nmcli connection show
NAME                UUID                                  TYPE      DEVICE 
System eth1         9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04  ethernet  eth1   
Wired connection 1  80a31b55-2247-3880-8aae-5154a3b47040  ethernet  eth0   
System enp0s3       3c36b8c2-334b-57c7-91b6-4401f3489c69  ethernet  --     
System enp0s8       00cb8299-feb9-55b6-a378-3fdc720e0bc6  ethernet  --     
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# nmcli connection add con-name default type ethernet ifname eth2
Connection 'default' (ccf4df33-797b-4ab3-8cf0-cc2f39691040) successfully added.
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# nmcli connection show
NAME                UUID                                  TYPE      DEVICE 
System eth1         9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04  ethernet  eth1   
Wired connection 1  80a31b55-2247-3880-8aae-5154a3b47040  ethernet  eth0   
default             ccf4df33-797b-4ab3-8cf0-cc2f39691040  ethernet  --     
System enp0s3       3c36b8c2-334b-57c7-91b6-4401f3489c69  ethernet  --     
System enp0s8       00cb8299-feb9-55b6-a378-3fdc720e0bc6  ethernet  --     
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ll /etc/sysconfig/network-scripts/ifcfg-*
-rw-r--r--  1 root root 281 Nov 18 07:06 /etc/sysconfig/network-scripts/ifcfg-default
-rw-r--r--. 1 root root  54 Jul  8 18:36 /etc/sysconfig/network-scripts/ifcfg-enp0s3
-rw-r--r--. 1 root root 137 Jul  8 18:37 /etc/sysconfig/network-scripts/ifcfg-enp0s8
-rw-r--r--  1 root root 135 Nov 18 06:28 /etc/sysconfig/network-scripts/ifcfg-eth1
-rw-r--r--. 1 root root 254 Aug 24  2018 /etc/sysconfig/network-scripts/ifcfg-lo
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# cat /etc/sysconfig/network-scripts/ifcfg-default 
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=default
UUID=ccf4df33-797b-4ab3-8cf0-cc2f39691040
DEVICE=eth2
ONBOOT=yes
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# nmcli connection add con-name default type ethernet ifname eth2

9>.删除连接default的配置文件

[root@node101.yinzhengjie.org.cn ~]# ll /etc/sysconfig/network-scripts/ifcfg-*
-rw-r--r--  1 root root 281 Nov 18 07:06 /etc/sysconfig/network-scripts/ifcfg-default
-rw-r--r--. 1 root root  54 Jul  8 18:36 /etc/sysconfig/network-scripts/ifcfg-enp0s3
-rw-r--r--. 1 root root 137 Jul  8 18:37 /etc/sysconfig/network-scripts/ifcfg-enp0s8
-rw-r--r--  1 root root 135 Nov 18 06:28 /etc/sysconfig/network-scripts/ifcfg-eth1
-rw-r--r--. 1 root root 254 Aug 24  2018 /etc/sysconfig/network-scripts/ifcfg-lo
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]#  nmcli connection show
NAME                UUID                                  TYPE      DEVICE 
System eth1         9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04  ethernet  eth1   
Wired connection 1  80a31b55-2247-3880-8aae-5154a3b47040  ethernet  eth0   
default             ccf4df33-797b-4ab3-8cf0-cc2f39691040  ethernet  --     
System enp0s3       3c36b8c2-334b-57c7-91b6-4401f3489c69  ethernet  --     
System enp0s8       00cb8299-feb9-55b6-a378-3fdc720e0bc6  ethernet  --     
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]#  nmcli connection delete default 
Connection 'default' (ccf4df33-797b-4ab3-8cf0-cc2f39691040) successfully deleted.
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ll /etc/sysconfig/network-scripts/ifcfg-*
-rw-r--r--. 1 root root  54 Jul  8 18:36 /etc/sysconfig/network-scripts/ifcfg-enp0s3
-rw-r--r--. 1 root root 137 Jul  8 18:37 /etc/sysconfig/network-scripts/ifcfg-enp0s8
-rw-r--r--  1 root root 135 Nov 18 06:28 /etc/sysconfig/network-scripts/ifcfg-eth1
-rw-r--r--. 1 root root 254 Aug 24  2018 /etc/sysconfig/network-scripts/ifcfg-lo
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# nmcli connection show
NAME                UUID                                  TYPE      DEVICE 
System eth1         9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04  ethernet  eth1   
Wired connection 1  80a31b55-2247-3880-8aae-5154a3b47040  ethernet  eth0   
System enp0s3       3c36b8c2-334b-57c7-91b6-4401f3489c69  ethernet  --     
System enp0s8       00cb8299-feb9-55b6-a378-3fdc720e0bc6  ethernet  --     
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# nmcli connection delete default

10>.创建新连接static的配置文件 ,指定静态IP,不自动连接

[root@node101.yinzhengjie.org.cn ~]# nmcli connection show
NAME                UUID                                  TYPE      DEVICE 
System eth1         9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04  ethernet  eth1   
Wired connection 1  80a31b55-2247-3880-8aae-5154a3b47040  ethernet  eth0   
System enp0s3       3c36b8c2-334b-57c7-91b6-4401f3489c69  ethernet  --     
System enp0s8       00cb8299-feb9-55b6-a378-3fdc720e0bc6  ethernet  --     
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# nmcli connection add con-name static ifname eth2 autoconnect no type ethernet ipv4.addresses 172.30.1.100/24 ipv4.gateway 172.30.1.254
Connection 'static' (c004fcc2-0473-4e0d-a132-8e28b2582fad) successfully added.
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# nmcli connection show
NAME                UUID                                  TYPE      DEVICE 
System eth1         9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04  ethernet  eth1   
Wired connection 1  80a31b55-2247-3880-8aae-5154a3b47040  ethernet  eth0   
static              c004fcc2-0473-4e0d-a132-8e28b2582fad  ethernet  --     
System enp0s3       3c36b8c2-334b-57c7-91b6-4401f3489c69  ethernet  --     
System enp0s8       00cb8299-feb9-55b6-a378-3fdc720e0bc6  ethernet  --     
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ll /etc/sysconfig/network-scripts/ifcfg-*
-rw-r--r--. 1 root root  54 Jul  8 18:36 /etc/sysconfig/network-scripts/ifcfg-enp0s3
-rw-r--r--. 1 root root 137 Jul  8 18:37 /etc/sysconfig/network-scripts/ifcfg-enp0s8
-rw-r--r--  1 root root 135 Nov 18 06:28 /etc/sysconfig/network-scripts/ifcfg-eth1
-rw-r--r--. 1 root root 254 Aug 24  2018 /etc/sysconfig/network-scripts/ifcfg-lo
-rw-r--r--  1 root root 330 Nov 18 07:11 /etc/sysconfig/network-scripts/ifcfg-static
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# cat /etc/sysconfig/network-scripts/ifcfg-static 
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp
IPADDR=172.30.1.100
PREFIX=24
GATEWAY=172.30.1.254
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=static
UUID=c004fcc2-0473-4e0d-a132-8e28b2582fad
DEVICE=eth2
ONBOOT=no
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# nmcli connection add con-name static ifname eth2 autoconnect no type ethernet ipv4.addresses 172.30.1.100/24 ipv4.gateway 172.30.1.254

11>.禁用连接配置

[root@node101.yinzhengjie.org.cn ~]# nmcli connection show
NAME                UUID                                  TYPE      DEVICE 
System eth1         9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04  ethernet  eth1   
Wired connection 1  80a31b55-2247-3880-8aae-5154a3b47040  ethernet  eth0   
static              c004fcc2-0473-4e0d-a132-8e28b2582fad  ethernet  --     
System enp0s3       3c36b8c2-334b-57c7-91b6-4401f3489c69  ethernet  --     
System enp0s8       00cb8299-feb9-55b6-a378-3fdc720e0bc6  ethernet  --     
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# nmcli connection down Wired\ connection\ 1 
Connection 'Wired connection 1' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/1)
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# nmcli connection show
NAME                UUID                                  TYPE      DEVICE 
System eth1         9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04  ethernet  eth1   
static              c004fcc2-0473-4e0d-a132-8e28b2582fad  ethernet  --     
System enp0s3       3c36b8c2-334b-57c7-91b6-4401f3489c69  ethernet  --     
System enp0s8       00cb8299-feb9-55b6-a378-3fdc720e0bc6  ethernet  --     
Wired connection 1  80a31b55-2247-3880-8aae-5154a3b47040  ethernet  --     
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# nmcli connection down Wired\ connection\ 1

12>.启用连接配置(前提是该配置文件绑定的设备的确存在,否则会报错设备不存在哟~)

[root@node101.yinzhengjie.org.cn ~]# nmcli connection show
NAME                UUID                                  TYPE      DEVICE 
System eth1         9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04  ethernet  eth1   
static              c004fcc2-0473-4e0d-a132-8e28b2582fad  ethernet  --     
System enp0s3       3c36b8c2-334b-57c7-91b6-4401f3489c69  ethernet  --     
System enp0s8       00cb8299-feb9-55b6-a378-3fdc720e0bc6  ethernet  --     
Wired connection 1  80a31b55-2247-3880-8aae-5154a3b47040  ethernet  --     
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# nmcli connection up Wired\ connection\ 1 
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/3)
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# nmcli connection show
NAME                UUID                                  TYPE      DEVICE 
System eth1         9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04  ethernet  eth1   
Wired connection 1  80a31b55-2247-3880-8aae-5154a3b47040  ethernet  eth0   
static              c004fcc2-0473-4e0d-a132-8e28b2582fad  ethernet  --     
System enp0s3       3c36b8c2-334b-57c7-91b6-4401f3489c69  ethernet  --     
System enp0s8       00cb8299-feb9-55b6-a378-3fdc720e0bc6  ethernet  --     
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# nmcli connection up Wired\ connection\ 1

13>.查看帮助

[root@node101.yinzhengjie.org.cn ~]# nmcli connection add help 
Usage: nmcli connection add { ARGUMENTS | help }

ARGUMENTS := COMMON_OPTIONS TYPE_SPECIFIC_OPTIONS SLAVE_OPTIONS IP_OPTIONS [-- ([+|-]<setting>.<property> <value>)+]

  COMMON_OPTIONS:
                  type <type>
                  ifname <interface name> | "*"
                  [con-name <connection name>]
                  [autoconnect yes|no]
                  [save yes|no]
                  [master <master (ifname, or connection UUID or name)>]
                  [slave-type <master connection type>]

  TYPE_SPECIFIC_OPTIONS:
    ethernet:     [mac <MAC address>]
                  [cloned-mac <cloned MAC address>]
                  [mtu <MTU>]

    wifi:         ssid <SSID>
                  [mac <MAC address>]
                  [cloned-mac <cloned MAC address>]
                  [mtu <MTU>]
                  [mode infrastructure|ap|adhoc]

    wimax:        [mac <MAC address>]
                  [nsp <NSP>]

    pppoe:        username <PPPoE username>
                  [password <PPPoE password>]
                  [service <PPPoE service name>]
                  [mtu <MTU>]
                  [mac <MAC address>]

    gsm:          apn <APN>
                  [user <username>]
                  [password <password>]

    cdma:         [user <username>]
                  [password <password>]

    infiniband:   [mac <MAC address>]
                  [mtu <MTU>]
                  [transport-mode datagram | connected]
                  [parent <ifname>]
                  [p-key <IPoIB P_Key>]

    bluetooth:    [addr <bluetooth address>]
                  [bt-type panu|nap|dun-gsm|dun-cdma]

    vlan:         dev <parent device (connection UUID, ifname, or MAC)>
                  id <VLAN ID>
                  [flags <VLAN flags>]
                  [ingress <ingress priority mapping>]
                  [egress <egress priority mapping>]
                  [mtu <MTU>]

    bond:         [mode balance-rr (0) | active-backup (1) | balance-xor (2) | broadcast (3) |
                        802.3ad    (4) | balance-tlb   (5) | balance-alb (6)]
                  [primary <ifname>]
                  [miimon <num>]
                  [downdelay <num>]
                  [updelay <num>]
                  [arp-interval <num>]
                  [arp-ip-target <num>]
                  [lacp-rate slow (0) | fast (1)]

    bond-slave:   master <master (ifname, or connection UUID or name)>

    team:         [config <file>|<raw JSON data>]

    team-slave:   master <master (ifname, or connection UUID or name)>
                  [config <file>|<raw JSON data>]

    bridge:       [stp yes|no]
                  [priority <num>]
                  [forward-delay <2-30>]
                  [hello-time <1-10>]
                  [max-age <6-40>]
                  [ageing-time <0-1000000>]
                  [multicast-snooping yes|no]
                  [mac <MAC address>]

    bridge-slave: master <master (ifname, or connection UUID or name)>
                  [priority <0-63>]
                  [path-cost <1-65535>]
                  [hairpin yes|no]

    vpn:          vpn-type vpnc|openvpn|pptp|openconnect|openswan|libreswan|ssh|l2tp|iodine|...
                  [user <username>]

    olpc-mesh:    ssid <SSID>
                  [channel <1-13>]
                  [dhcp-anycast <MAC address>]

    adsl:         username <username>
                  protocol pppoa|pppoe|ipoatm
                  [password <password>]
                  [encapsulation vcmux|llc]

    tun:          mode tun|tap
                  [owner <UID>]
                  [group <GID>]
                  [pi yes|no]
                  [vnet-hdr yes|no]
                  [multi-queue yes|no]

    ip-tunnel:    mode ipip|gre|sit|isatap|vti|ip6ip6|ipip6|ip6gre|vti6
                  remote <remote endpoint IP>
                  [local <local endpoint IP>]
                  [dev <parent device (ifname or connection UUID)>]

    macsec:       dev <parent device (connection UUID, ifname, or MAC)>
                  mode <psk|eap>
                  [cak <key> ckn <key>]
                  [encrypt yes|no]
                  [port 1-65534]


    macvlan:      dev <parent device (connection UUID, ifname, or MAC)>
                  mode vepa|bridge|private|passthru|source
                  [tap yes|no]

    vxlan:        id <VXLAN ID>
                  remote <IP of multicast group or remote address>
                  [local <source IP>]
                  [dev <parent device (ifname or connection UUID)>]
                  [source-port-min <0-65535>]
                  [source-port-max <0-65535>]
                  [destination-port <0-65535>]

    dummy:         

  SLAVE_OPTIONS:
    bridge:       [priority <0-63>]
                  [path-cost <1-65535>]
                  [hairpin yes|no]

    team:         [config <file>|<raw JSON data>]

  IP_OPTIONS:
                  [ip4 <IPv4 address>] [gw4 <IPv4 gateway>]
                  [ip6 <IPv6 address>] [gw6 <IPv6 gateway>]

[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# nmcli connection add help

14>.修改连接设置

[root@node101.yinzhengjie.org.cn ~]# nmcli connection show
NAME                UUID                                  TYPE      DEVICE 
System eth1         9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04  ethernet  eth1   
Wired connection 1  80a31b55-2247-3880-8aae-5154a3b47040  ethernet  eth0   
static              c004fcc2-0473-4e0d-a132-8e28b2582fad  ethernet  --     
System enp0s3       3c36b8c2-334b-57c7-91b6-4401f3489c69  ethernet  --     
System enp0s8       00cb8299-feb9-55b6-a378-3fdc720e0bc6  ethernet  --     
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# cat /etc/sysconfig/network-scripts/ifcfg-static 
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp
IPADDR=172.30.1.100
PREFIX=24
GATEWAY=172.30.1.254
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=static
UUID=c004fcc2-0473-4e0d-a132-8e28b2582fad
DEVICE=eth2
ONBOOT=no
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# nmcli connection modify static connection.autoconnect no
[root@node101.yinzhengjie.org.cn ~]# nmcli connection modify static ipv4.dns 219.141.136.10
[root@node101.yinzhengjie.org.cn ~]# nmcli connection modify static +ipv4.dns 219.141.140.10
[root@node101.yinzhengjie.org.cn ~]# nmcli connection modify static +ipv4.dns 114.114.114.114
[root@node101.yinzhengjie.org.cn ~]# nmcli connection modify static +ipv4.dns 8.8.8.8
[root@node101.yinzhengjie.org.cn ~]# nmcli connection modify static -ipv4.dns 8.8.8.8
[root@node101.yinzhengjie.org.cn ~]# nmcli connection modify static ipv4.addresses "172.30.1.200"
[root@node101.yinzhengjie.org.cn ~]# nmcli connection modify static +ipv4.addresses 1.1.1.1/16
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# cat /etc/sysconfig/network-scripts/ifcfg-static 
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp
IPADDR=172.30.1.200
PREFIX=32
GATEWAY=172.30.1.254
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=static
UUID=c004fcc2-0473-4e0d-a132-8e28b2582fad
DEVICE=eth2
ONBOOT=no
DNS1=219.141.136.10
DNS2=219.141.140.10
DNS3=114.114.114.114
IPADDR1=1.1.1.1
PREFIX1=16
[root@node101.yinzhengjie.org.cn ~]# 

15>.DNS设置,存放在/etc/resolv.conf文件中

[root@node101.yinzhengjie.org.cn ~]# cat /etc/sysconfig/network-scripts/ifcfg-static 
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp
IPADDR=172.30.1.200
PREFIX=32
GATEWAY=172.30.1.254
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=static
UUID=c004fcc2-0473-4e0d-a132-8e28b2582fad
DEVICE=eth2
ONBOOT=no
DNS1=219.141.136.10
DNS2=219.141.140.10
DNS3=114.114.114.114
IPADDR1=1.1.1.1
PREFIX1=16
[root@node101.yinzhengjie.org.cn ~]#  
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# nmcli connection modify static ipv4.ignore-auto-dns yes
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# cat /etc/sysconfig/network-scripts/ifcfg-static 
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp
IPADDR=172.30.1.200
PREFIX=32
GATEWAY=172.30.1.254
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=static
UUID=c004fcc2-0473-4e0d-a132-8e28b2582fad
DEVICE=eth2
ONBOOT=no
DNS1=219.141.136.10
DNS2=219.141.140.10
DNS3=114.114.114.114
IPADDR1=1.1.1.1
PREFIX1=16
PEERDNS=no
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# nmcli connection modify static ipv4.ignore-auto-dns yes

16>.修改连接配置后,需要重新加载配置

nmcli con reload
nmcli con down “system eth0” #可被自动激活
nmcli con up “system eth0”
nmcli dev dis eth0       #禁用网卡,访止被自动激活

17>.图形工具

nm-connection-editor    #图形操作工具,需要安装Linux桌面版本

18>.字符工具

nmtui            #和Linux的setup用法类似。
nmtui-connect
nmtui-edit
nmtui-hostname

19>.nmcli实现bonding

添加bonding接口
  nmcli con add type bond con-name mybond0 ifname mybond0 mode active-backup

添加从属接口
  nmcli con add type bond-slave ifname ens7 master mybond0
  nmcli con add type bond-slave ifname ens3 master mybond0
  注:如无为从属接口提供连接名,则该名称是接口名称加类型构成

要启动绑定,则必须首先启动从属接口
  nmcli con up bond-slave-eth0
  nmcli con up bond-slave-eth1

启动绑定
  nmcli con up mybond0

20>.修改连接配置文件的名字

[root@node101.yinzhengjie.org.cn ~]# nmcli connection show
NAME                UUID                                  TYPE      DEVICE 
System eth1         9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04  ethernet  eth1   
static              c004fcc2-0473-4e0d-a132-8e28b2582fad  ethernet  --     
System enp0s3       3c36b8c2-334b-57c7-91b6-4401f3489c69  ethernet  --     
System enp0s8       00cb8299-feb9-55b6-a378-3fdc720e0bc6  ethernet  --     
Wired connection 1  80a31b55-2247-3880-8aae-5154a3b47040  ethernet  --     
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# nmcli connection modify Wired\ connection\ 1 connection.id eth0
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# nmcli connection show
NAME           UUID                                  TYPE      DEVICE 
System eth1    9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04  ethernet  eth1   
eth0           80a31b55-2247-3880-8aae-5154a3b47040  ethernet  --     
static         c004fcc2-0473-4e0d-a132-8e28b2582fad  ethernet  --     
System enp0s3  3c36b8c2-334b-57c7-91b6-4401f3489c69  ethernet  --     
System enp0s8  00cb8299-feb9-55b6-a378-3fdc720e0bc6  ethernet  --     
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ll /etc/sysconfig/network-scripts/ifcfg-*
-rw-r--r--. 1 root root  54 Jul  8 18:36 /etc/sysconfig/network-scripts/ifcfg-enp0s3
-rw-r--r--. 1 root root 137 Jul  8 18:37 /etc/sysconfig/network-scripts/ifcfg-enp0s8
-rw-r--r--  1 root root 317 Nov 18 07:37 /etc/sysconfig/network-scripts/ifcfg-eth0
-rw-r--r--  1 root root 135 Nov 18 06:28 /etc/sysconfig/network-scripts/ifcfg-eth1
-rw-r--r--. 1 root root 254 Aug 24  2018 /etc/sysconfig/network-scripts/ifcfg-lo
-rw-r--r--  1 root root 429 Nov 18 07:28 /etc/sysconfig/network-scripts/ifcfg-static
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# nmcli connection modify Wired\ connection\ 1 connection.id eth0

 

三.网络组Network Teaming

1>.网络组概述

网络组:是将多个网卡聚合在一起方法,从而实现冗错和提高吞吐量

网络组不同于旧版中bonding技术,提供更好的性能和扩展性

网络组由内核驱动和teamd守护进程实现.

多种方式runner
    broadcast
    roundrobin
    activebackup
    loadbalance
    lacp (implements the 802.3ad Link Aggregation Control Protocol)

启动网络组接口不会自动启动网络组中的port接口

启动网络组接口中的port接口总会自动启动网络组接口

禁用网络组接口会自动禁用网络组中的port接口

没有port接口的网络组接口可以启动静态IP连接

启用DHCP连接时,没有port接口的网络组会等待port接口的加入

2>.创建网络组接口 

nmcli con add type team con-name CNAME ifname INAME [config JSON]
  CNAME 连接名,INAME 接口名
  JSON 指定runner方式
  格式:'{"runner": {"name": "METHOD"}}'
  METHOD 可以是broadcast, roundrobin,activebackup, loadbalance, lacp

3>.创建port接口:

nmcli con add type team-slave con-name CNAME ifname INAME master TEAM
  CNAME 连接名
  INAME 网络接口名
  TEAM 网络组接口名
  连接名若不指定,默认为team-slave-IFACE
    nmcli dev dis INAME
    nmcli con up CNAME
    INAME 设备名 CNAME 网络组接口名或port接口   

4>.网络组示例

nmcli con add type team con-name team0 ifname team0 config ‘{“runner”: {“name”: “loadbalance”}}‘ ipv4.addresses 192.168.1.100/24 ipv4.method manual

nmcli con add con
-name team0-eth1 type team-slave ifname eth1 master team0
nmcli con add con
-name team0-eth2 type team-slave ifname eth2 master team0
nmcli con up team0
nmcli con up team0
-eth1
nmcli con up team0
-eth2
teamdctl team0 state
nmcli dev dis eth1

5>.实验:创建网络组

ip link

nmcli con add type team con
-name team0 ifname team0 config '{"runner": {"name": "activebackup"}}'
nmcli con mod team0 ipv4.addresses
'192.168.0.100/24'
nmcli con mod team0 ipv4.method manual
nmcli con add con
-name team0-port1 type team-slave ifname eth1 master team0
nmcli con add con
-name team0-port2 type team-slave ifname eth2 master team0
teamdctl team0 state

ping -I team0 192.168.0.254
nmcli dev dis eno1
teamdctl team0 state
nmcli con up team0
-port1
nmcli dev dis eno2
teamdctl team0 state
nmcli con up team0
-port2
teamdctl team0 state

6>.管理网络组配置文件

/etc/sysconfig/network-scripts/ifcfg-team0
    DEVICE=team0
    DEVICETYPE=Team
    TEAM_CONFIG="{\"runner\": {\"name\": \"broadcast\"}}"
    BOOTPROTO=none
    IPADDR0=172.25.5.100
    PREFIX0=24
    NAME=team0
    ONBOOT=yes

/etc/sysconfig/network-scripts/ifcfg-team0-eth1
    DEVICE=eth1
    DEVICETYPE=TeamPort
    TEAM_MASTER=team0
    NAME=team0-eth1
    ONBOOT=yes

7>.删除网络组

nmcli connection down team0

teamdctl team0 state

nmcli connection show
nmcli connectioni delete team0
-eth0
nmcli connectioni delete team0
-eth1
nmcli connection show

 

四.ethtool工具

[root@node101.yinzhengjie.org.cn ~]# ethtool eth1 
Settings for eth1:
    Supported ports: [ TP ]
    Supported link modes:   10baseT/Half 10baseT/Full 
                            100baseT/Half 100baseT/Full 
                            1000baseT/Full 
    Supported pause frame use: No
    Supports auto-negotiation: Yes
    Supported FEC modes: Not reported
    Advertised link modes:  10baseT/Half 10baseT/Full 
                            100baseT/Half 100baseT/Full 
                            1000baseT/Full 
    Advertised pause frame use: No
    Advertised auto-negotiation: Yes
    Advertised FEC modes: Not reported
    Speed: 1000Mb/s
    Duplex: Full
    Port: Twisted Pair
    PHYAD: 0
    Transceiver: internal
    Auto-negotiation: on
    MDI-X: off (auto)
    Supports Wake-on: umbg
    Wake-on: d
    Current message level: 0x00000007 (7)
                   drv probe link
    Link detected: yes
[root@node101.yinzhengjie.org.cn ~]# 

 

五.mii-tools工具

[root@node101.yinzhengjie.org.cn ~]# mii-tool eth1
eth1: no autonegotiation, 1000baseT-FD flow-control, link ok
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# mii-tool eth1 -v
eth1: no autonegotiation, 1000baseT-FD flow-control, link ok
  product info: Yukon 88E1011 rev 4
  basic mode:   autonegotiation enabled
  basic status: autonegotiation complete, link ok
  capabilities: 1000baseT-FD 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD
  advertising:  1000baseT-FD 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD flow-control
  link partner: 1000baseT-HD 1000baseT-FD 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 

 

六.测试网络工具

在命令行下测试网络的连通性
    显示主机名
        hostname
    测试网络连通性
        ping
    显示正确的路由表
        ip route

跟踪路由
    traceroute
    tracepath
    mtr

确定名称服务器使用
    nslookup
    host
    dig    

 

七.网络客户端工具

ftp,lftp:子命令:get、mget、ls、help
    lftp [-p port] [-u user[,password]] SERVER

lftpget URL

wget [option]... [URL]...
    -q 静默模式
    -c 断点续传
    -P /path 保存在指定目录
    -O filename 保存为指定文件名,filename 为 – 时,发送至标准输出
    --limit-rate= 指定传输速率,单位K,M等

links URL
    --dump
    --source

 

posted @ 2019-11-17 22:08  尹正杰  阅读(2252)  评论(0编辑  收藏  举报