14.Linux 网络管理 ifconfig nmcli ifup ifdown

14.1 网卡命名管理

# 查看网卡信息

[root@localhost ~]# ifconfig

#早期linux网卡命名方法

1.有线网卡 eth0/eth1 | 2.无线网卡wlan0/wlan1 | 3.本地环回网卡lo

#后期linux网卡命名方法

前两位 + 设备类型 + 设备索引值/哈希值
   前两位 :
            en : Ethernet - 有线
            wl : Wireless - 无线
            lo : Loopback - 本地环回
    设备类型
          o :  On-board - 板载网卡
          s : hotplug Slot - 支持热插拔网卡
         p*s* : PCI / Slot - PCI⽹卡
  那么网卡命名组合有如下:
                         eno+网卡哈希值      #哈希值/索引值   系统自动判断生成 - dmidecode
                         ens+网卡索引值
                         enp[PCI bus id]s[slot id]        #服务器一般没有无线网卡所以没有wl 组合
                  例如: eno16777736      ens33     ens37       enp0s3    enp3s0    wlp*s* wlp3s0

  #调整网卡命名规则方式

*配置⽂件 /etc/sysconfig/grub
[root@localhost ~]# more /etc/sysconfig/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="rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet"
GRUB_DISABLE_RECOVERY="true"

#重新生成grub启动加载配置⽂件

#删除规则配置文件(有则删除)

#重启

14.2 网卡配置⽂件

# linux主机如果网卡能够持续运⾏需要通过配置文件记录网卡相关信息
# 修改完配置文件后-需要重启网络服务 (service network)

#网卡配置文件路径
/etc/sysconfig/network-scripts

#网卡配置文件名称 - ifcfg-[网卡名称]
[root@localhost network-scripts]# more ifcfg-ens33 
TYPE=Ethernet                            #网卡类型
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none       # boot protocol 网卡地址启动类型 dhcp动态获取 / none|static 静态获取
DEFROUTE=yes            # default route | 是否生成默认路由
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33                   #网卡名称
UUID=5ce795b2-d87c-4f47-9cfd-52ae51fcc08d     #网卡唯⼀标示符
DEVICE=ens33              #网卡设备硬件对应名称
ONBOOT=yes               # 该网卡是否开机⾃动启动 | 网络服务重启/启动时 是否加载该配置⽂件
IPADDR=192.168.8.129   #IP地址
PREFIX=24       #前缀⻓度 24 | 255.255.255.0;可以写成NETMASK=255.255.255.0
GATEWAY=192.168.8.2     #网关地址
DNS1=192.168.8.2            # DNS地址

[root@localhost ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.8.129  netmask 255.255.255.0  broadcast 192.168.8.255
        inet6 fe80::eb00:558:16e9:4d72  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:d5:14:0a  txqueuelen 1000  (Ethernet)
       

ens36: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::9031:9e07:1938:7881  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:d5:14:14  txqueuelen 1000  (Ethernet)

[root@localhost network-scripts]# cp ifcfg-ens33 ifcfg-ens36
[root@localhost network-scripts]# vim ifcfg-ens36
TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
NAME=ens36
DEVICE=ens36
ONBOOT=yes
IPADDR=192.168.11.9
PREFIX=24

[root@localhost network-scripts]# systemctl restart network
[root@localhost network-scripts]# ifconfig

ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.8.129  netmask 255.255.255.0  broadcast 192.168.8.255
        inet6 fe80::eb00:558:16e9:4d72  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:d5:14:0a  txqueuelen 1000  (Ethernet)
      

  s36: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.11.9  netmask 255.255.255.0  broadcast 192.168.11.255
        inet6 fe80::20c:29ff:fed5:1414  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:d5:14:14  txqueuelen 1000  (Ethernet)

[root@localhost network-scripts]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.8.2     0.0.0.0         UG    100    0        0 ens33
192.168.8.0     0.0.0.0         255.255.255.0   U     100    0        0 ens33
192.168.11.0    0.0.0.0         255.255.255.0   U     101    0        0 ens36
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0

[root@localhost network-scripts]# vim ifcfg-ens36
TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=no
IPV4_FAILURE_FATAL=no
NAME=ens36
DEVICE=ens36
ONBOOT=yes
IPADDR=192.168.11.9
PREFIX=24

[root@localhost network-scripts]# systemctl restart network.service
[root@localhost network-scripts]# route -n  #查看系统路由表
Kernel IP routing table
Destination     Gateway         Genmask   Flags Metric  Ref   Use  Iface
0.0.0.0         192.168.8.2     0.0.0.0           UG    100      0       0      ens33   #(默认路由)
192.168.8.0     0.0.0.0         255.255.255.0   U     100    0       0      ens33   #(直连路由)
192.168.11.0    0.0.0.0         255.255.255.0   U     101    0      0      ens36    #(直连路由)
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0       0      virbr0

14.3 网络接⼝管理

#1.网络接口查看

ifconfig
ip add show   |  ip add  | ip a 
ip link
ifconfig -a 查看所有接口

[root@localhost network-scripts]# ifconfig ens33
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.8.129  netmask 255.255.255.0  broadcast 192.168.8.255
        inet6 fe80::eb00:558:16e9:4d72  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:d5:14:0a  txqueuelen 1000  (Ethernet)
        RX packets 1536  bytes 130045 (126.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 855  bytes 143359 (139.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens33:网卡硬件名称
flags : 网卡标志 - 包含网卡⼀系列状态 <>
   UP : 管理状态UP - 管理员未将网卡关闭 | (administrator) State
   BROADCAST : 该接口支持广播消息    #还有一个“UNICAST”  单播,所有都支持所以不列出来
   MULTICAST : 该接口支持组播消息
   RUNNING : 网卡线路正常 (网线/光纤/虚拟链接)
   mtu(mrt) 1500 : 接口最大传输单元 - 字节
                          t: transit 发送
                          r: receive 接收
    inet IPv4地址 / netmask 子网掩码 /broadcast广播地址
    inet6 IPv6相关信息
    ether :MAC地址
    txqueuelen:数据发送缓冲区长度
    packets  包数量   
    bytes : 字节数
    errors : 错误包总数
    dropped : 丢弃包 - 内存不足导致数据丢弃
    overruns - 网卡缓冲区溢出导致数据错误-无法处理
    frame - 数据帧CRC/FCS序列值校验失败 - 物理信号不稳定导致的传输问题
    carrier - 物理设备数据载波频率紊乱-导致数据错误
    collisions - 物理线路CSMA/CD监听到数据冲突

[root@localhost network-scripts]# ip add show dev ens33
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:d5:14:0a brd ff:ff:ff:ff:ff:ff
    inet 192.168.8.129/24 brd 192.168.8.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::eb00:558:16e9:4d72/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

LOWER_UP (网卡线路正常) / no-carrier (网卡线路不正常)  相当于ifconfig  running
state (管理员设置关闭 or 网络线路异常) down

#2.网络接口配置文件卸载/加载 - (网卡和配置文件解除关联)

ifup / ifdown

[root@localhost network-scripts]# ifdown ens33     # 网络接口配置文件卸载
成功断开设备 "ens33"。

[root@localhost network-scripts]# ifup ens33       # 网络接口配置文件加载
连接已成功激活(D-Bus 活动路:/org/freedesktop/NetworkManager/ActiveConnection/16)

#3网络接口开启/关闭

[root@localhost ~]# ifconfig ens33 down     # 网络接口关闭
[root@localhost network-scripts]# ifconfig ens33
ens33: flags=4098<BROADCAST,MULTICAST>  mtu 1500
        ether 00:0c:29:d5:14:0a  txqueuelen 1000  (Ethernet)

[root@localhost network-scripts]# ifconfig  ens33 up     # 网络接口开启
[root@localhost network-scripts]# ifconfig ens33
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.8.129  netmask 255.255.255.0  broadcast 192.168.8.255
        inet6 fe80::eb00:558:16e9:4d72  prefixlen 64  scopeid 0x20<link>

[root@localhost network-scripts]# ip link set ens33 down    # 网络接口关闭
[root@localhost network-scripts]# ip link set ens33 up        # 网络接口开启

#4.查看网卡硬件详细信息

ethtool

[root@localhost network-scripts]# ethtool ens33
Settings for ens33:
    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: d
    Wake-on: d
    Current message level: 0x00000007 (7)
                   drv probe link
    Link detected: yes

14.4 网络服务管理

#1.网络服务

network
NetworkManager.service

centos6 (包括更早期)      network
centos7                           network / NetworkManager.service
centos8 (包括之后)    NetworkManager.service

#2.二者区别

NetworkManager.service ⽀持多种网络/管理办法
        GUI(图形化管理界面) 
       *nmcli (NetworkManager Command Line Interface)   #重点
        nmtui   (NetworkManager Terminal User Interface)   #伪图形终端
NetworkManager.service 支持管理更多类型网络
       有线网络  //  无线网络 / VPN网络  //  桥接网络 / etc...
NetworkManager.service 更加灵活管理网卡与配置文件,真正做到解耦合

#3.建议使用方式

network / NetworkManager.service 关闭掉其中⼀个服务 (network)

[root@centos7 network-scripts]# systemctl stop network && systemctl disable network && systemctl mask network
network.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig network off
Created symlink from /etc/systemd/system/network.service to /dev/null.

14.5 nmcli网络管理

nmcli  -  NetworkManager.service网络管理服务中的网络管理⼯具之一

#1.查看网卡硬件状态

[root@localhost network-scripts]# nmcli device status
DEVICE      TYPE    STATE   CONNECTION 
virbr0      bridge        已连接  virbr0     
ens33       ethernet   已断开  --         
ens36       ethernet   已断开  --         
lo          loopback    未托管  --         
virbr0-nic  tun         未托管  --  

DEVICE : 网卡名称
TYPE : 网卡类型
     ethernet     普通有线网卡
     loopback   本地回环接口
     bridge       虚拟网桥/虚拟交换机
     tun            虚拟网卡
STATE : 网卡状态
    connected  已经连接到配置文件  #已连接
    disconnected 未连接到配置文件   #已断开
    unmanaged - 未受NetworkManager管理 (添加连接信息进⾏管理)   #未托管
CONNECTION : 当前网卡加载到连接信息 ,网卡配置⽂件

#2.查看网卡配置文件   connect 信息

[root@localhost network-scripts]# nmcli connection show
NAME        UUID                                                        TYPE      DEVICE 
virbr0      251ee2f9-04e4-478b-9463-babe475742ad  bridge    virbr0 
ens33       5ce795b2-d87c-4f47-9cfd-52ae51fcc08d  ethernet   --     
ens36       418da202-9a8c-b73c-e8a1-397e00f3c6b2  ethernet   --     
有线连接 1  50c3c031-f4cc-3336-8fa0-9d3d2131dfd3  ethernet   --  

NAME - 配置文件信息
UUID - 网卡connection配置文件的唯⼀标识符   #系统随机生成的
TYPE - 网卡类型
DEVICE - 设备名称

#3.网络配置文件关联

[root@localhost network-scripts]# nmcli connection up ens33
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/21)

[root@localhost ~]# nmcli device connect  ens36       #和上面一样,两种方法都可以,可以文件关联设备也可以设备关联文件
成功用 "ens36418da202-9a8c-b73c-e8a1-397e00f3c6b2" 激活了设备 ""。

#4.网络配置文件卸载

[root@localhost network-scripts]# nmcli connection  down ens33
成功停用连接 "ens33"(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/24)
[root@localhost network-scripts]# nmcli device connect ens33
成功用 "ens335ce795b2-d87c-4f47-9cfd-52ae51fcc08d" 激活了设备 ""。

[root@localhost ~]# nmcli device disconnect ens36
成功断开设备 "ens36"。
[root@localhost ~]# nmcli connection up ens36
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/27)

[root@localhost ~]# nmcli device status   #查看网卡
DEVICE      TYPE      STATE   CONNECTION 
ens33       ethernet  已连接  ens33      
ens36       ethernet  已连接  ens36      
virbr0      bridge    已连接  virbr0     
lo          loopback  未托管  --         
virbr0-nic  tun       未托管  --         
[root@localhost ~]# nmcli connection staus
错误:不能理解参数 "staus"。试下换成传递 --help 参数。
[root@localhost ~]# nmcli connection show   #查看connection(连接)信息,连接信息记录的是配置文件
NAME        UUID                                  TYPE      DEVICE 
ens33       5ce795b2-d87c-4f47-9cfd-52ae51fcc08d  ethernet  ens33  
ens36       418da202-9a8c-b73c-e8a1-397e00f3c6b2  ethernet  ens36  
virbr0      251ee2f9-04e4-478b-9463-babe475742ad  bridge    virbr0 
有线连接 1  50c3c031-f4cc-3336-8fa0-9d3d2131dfd3  ethernet  --  

#5.网络connection配置文件添加/替换(网络配置文件关联)

 

 [root@localhost network-scripts]#  nmcli connection add con-name satic-ip-ens36 autoconnect yes type  ethernet  ifname ens36 ip4 192.168.11.19/24
连接 "satic-ip-ens36" (06a94095-94c6-45b1-82a3-6baed9124ec9) 已成功添加。
[root@localhost network-scripts]# nmcli connection show
NAME            UUID                                  TYPE      DEVICE 
ens33           5ce795b2-d87c-4f47-9cfd-52ae51fcc08d  ethernet  ens33  
ens36           418da202-9a8c-b73c-e8a1-397e00f3c6b2  ethernet  ens36  
virbr0          251ee2f9-04e4-478b-9463-babe475742ad  bridge    virbr0 
satic-ip-ens36  06a94095-94c6-45b1-82a3-6baed9124ec9  ethernet  --     
有线连接 1      50c3c031-f4cc-3336-8fa0-9d3d2131dfd3  ethernet  --  
[root@localhost network-scripts]# nmcli connection up satic-ip-ens36 
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/29)
[root@localhost network-scripts]# nmcli connection show
NAME            UUID                                                         TYPE         DEVICE 
ens33           5ce795b2-d87c-4f47-9cfd-52ae51fcc08d  ethernet       ens33  
satic-ip-ens36  06a94095-94c6-45b1-82a3-6baed9124ec9  ethernet  ens36  
virbr0          251ee2f9-04e4-478b-9463-babe475742ad   bridge        virbr0 
ens36           418da202-9a8c-b73c-e8a1-397e00f3c6b2  ethernet     --     
有线连接 1      50c3c031-f4cc-3336-8fa0-9d3d2131dfd3  ethernet     -- 
[root@localhost network-scripts]# ifconfig ens36   
ens36: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.11.19  netmask 255.255.255.0  broadcast 192.168.11.255   #原ip地址是11.9

#6.网络网卡详细信息查看

[root@localhost network-scripts]# nmcli device show
[root@localhost network-scripts]# nmcli device show ens36
GENERAL.DEVICE:                         ens36
GENERAL.TYPE:                           ethernet
GENERAL.HWADDR:                         00:0C:29:D5:14:14
GENERAL.MTU:                            1500
GENERAL.STATE:                          30(已断开)    # 100(已连接),20接口down
GENERAL.CONNECTION:                     --
GENERAL.CON-PATH:                       --
WIRED-PROPERTIES.CARRIER:               开
[root@localhost network-scripts]# nmcli device show ens33
GENERAL.DEVICE:                         ens33
GENERAL.TYPE:                           ethernet
GENERAL.HWADDR:                         00:0C:29:D5:14:0A
GENERAL.MTU:                            1500
GENERAL.STATE:                          100(已连接)
GENERAL.CONNECTION:                     ens33

#7.网络接口开启/关闭

100 (connected)
30 (disconnected)
20 (unavailable) 
ip link set eth0 down    #20,接口关闭
ifconfig eth0 down       #20,接口关闭

nmcli connection down 
nmcli device disconnect
ifdown

#8.删除connect (直接使用nmcli方式)

nmcli connection delete [connection - name]

[root@centos7 network-scripts]# rm -rf ifcfg-ens33  #不建议使用这种方式
[root@centos7 network-scripts]# rm -rf ifcfg-ens36

[root@localhost network-scripts]# nmcli connection add con-name test36 autoconnect  yes type ethernet ifname ens36 ip4 192.168.11.119/24          #重新创建 配置文件
连接 "test36" (fea870fd-c98d-43e9-9990-63749c25ffda) 已成功添加。
[root@localhost network-scripts]# nmcli connection show
NAME            UUID                                  TYPE      DEVICE 
ens33           5ce795b2-d87c-4f47-9cfd-52ae51fcc08d  ethernet  ens33  
satic-ip-ens36  06a94095-94c6-45b1-82a3-6baed9124ec9  ethernet  ens36  
virbr0          251ee2f9-04e4-478b-9463-babe475742ad  bridge    virbr0 
ens36           418da202-9a8c-b73c-e8a1-397e00f3c6b2  ethernet  --     
test36          fea870fd-c98d-43e9-9990-63749c25ffda  ethernet  --         #文件创建成功
有线连接 1      50c3c031-f4cc-3336-8fa0-9d3d2131dfd3  ethernet  --     
[root@localhost network-scripts]# nmcli connection 
add      delete   edit     help     load     monitor  show     
clone    down     export   import   modify   reload   up  
    
[root@localhost network-scripts]# nmcli connection up test36        #配置文件关联
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/32)
[root@localhost network-scripts]# nmcli connection show     
NAME            UUID                                  TYPE      DEVICE 
ens33           5ce795b2-d87c-4f47-9cfd-52ae51fcc08d  ethernet  ens33  
test36          fea870fd-c98d-43e9-9990-63749c25ffda  ethernet  ens36     #关联成功
virbr0          251ee2f9-04e4-478b-9463-babe475742ad  bridge    virbr0 
ens36           418da202-9a8c-b73c-e8a1-397e00f3c6b2  ethernet  --     
satic-ip-ens36  06a94095-94c6-45b1-82a3-6baed9124ec9  ethernet  --     
有线连接 1      50c3c031-f4cc-3336-8fa0-9d3d2131dfd3  ethernet  --     
[root@localhost network-scripts]# nmcli connection  delete test36     #删除connect
成功删除连接 "test36" (fea870fd-c98d-43e9-9990-63749c25ffda)。
[root@localhost network-scripts]# nmcli connection show   #再次查看,删除成功
NAME            UUID                                  TYPE      DEVICE 
ens33           5ce795b2-d87c-4f47-9cfd-52ae51fcc08d  ethernet  ens33  
satic-ip-ens36  06a94095-94c6-45b1-82a3-6baed9124ec9  ethernet  ens36  
virbr0          251ee2f9-04e4-478b-9463-babe475742ad  bridge    virbr0 
ens36           418da202-9a8c-b73c-e8a1-397e00f3c6b2  ethernet  --     
有线连接 1      50c3c031-f4cc-3336-8fa0-9d3d2131dfd3  ethernet  -- 

#9.修改connection

[root@localhost network-scripts]# nmcli connection modify satic-ip-ens36 ipv4.addresses 192.168.11.119/24    #修改connection配置文件的 IP地址
[root@localhost network-scripts]# ifconfig ens36   #IP地址未发生改变
ens36: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.11.19  netmask 255.255.255.0  broadcast 192.168.11.255

[root@localhost network-scripts]# nmcli connection down satic-ip-ens36 && nmcli connection up satic-ip-ens36      #修改完毕后 - 重新关联配置⽂件
成功停用连接 "satic-ip-ens36"(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/33)

连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/35)
[root@localhost network-scripts]# ifconfig ens36   #重新查看,IP地址修改成功
ens36: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.11.119  netmask 255.255.255.0  broadcast 192.168.11.255

#10.设置网卡自动链接

nmcli connection set con-name static-ip-eth0 autoconnect yes/no


14.6 网卡DNS 管理

[root@localhost network-scripts]# more /etc/resolv.conf          #查看dns文件 
# Generated by NetworkManager   
nameserver 192.168.8.2

[root@localhost network-scripts]# nmcli connection modify ens33 ipv4.dns 114.114.114.114 #修改
[root@localhost network-scripts]# more /etc/resolv.conf                                 
# Generated by NetworkManager
nameserver 192.168.8.2
[root@localhost network-scripts]# nmcli connection down ens33 && nmcli connection up ens33
成功停用连接 "ens33"(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/38)
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/39)
[root@localhost network-scripts]# more /etc/resolv.conf                                
 # Generated by NetworkManager
nameserver 114.114.114.114

[root@localhost network-scripts]# nmcli connection modify ens33 +ipv4.dns 8.8.8.8  #新增DNS
[root@localhost network-scripts]# nmcli connection down ens33 && nmcli connection up ens33
成功停用连接 "ens33"(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/39)
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/40)
[root@localhost network-scripts]# more /etc/resolv.conf                                  
# Generated by NetworkManager
nameserver 114.114.114.114
nameserver 8.8.8.8

[root@localhost network-scripts]# nmcli connection modify ens33 -ipv4.dns 8.8.8.8 #删除一个dns
[root@localhost network-scripts]# more /etc/resolv.conf                          
# Generated by NetworkManager
nameserver 114.114.114.114
nameserver 8.8.8.8
[root@localhost network-scripts]# nmcli connection down ens33 && nmcli connection up ens33
成功停用连接 "ens33"(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/40)
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/41)
[root@localhost network-scripts]# more /etc/resolv.conf                                  
# Generated by NetworkManager
nameserver 114.114.114.114

14.7 网卡DHCP管理

[root@localhost network-scripts]# nmcli connection  add con-name dhcp-ens36 autoconnect yes type ethernet ifname ens36 ipv4.   #按tab键
ipv4.addresses           ipv4.dns                 ipv4.may-fail
ipv4.dad-timeout         ipv4.dns-options         ipv4.method
ipv4.dhcp-client-id      ipv4.dns-priority        ipv4.never-default
ipv4.dhcp-fqdn           ipv4.dns-search          ipv4.route-metric
ipv4.dhcp-hostname       ipv4.gateway             ipv4.routes
ipv4.dhcp-send-hostname  ipv4.ignore-auto-dns     ipv4.route-table
ipv4.dhcp-timeout        ipv4.ignore-auto-routes  ipv4.routing-rules
[root@localhost network-scripts]# nmcli connection  add con-name dhcp-ens36 autoconnect yes type ethernet ifname ens36 ipv4.method auto
连接 "dhcp-ens36" (24c4cd02-c719-428c-bf49-3286677189e2) 已成功添加。
[root@localhost network-scripts]# ls
ifcfg-dhcp-ens36      ifdown-ipv6      ifup-aliases  ifup-ppp
ifcfg-ens33           ifdown-isdn      ifup-bnep     ifup-routes
ifcfg-ens36           ifdown-post      ifup-eth      ifup-sit
ifcfg-lo              ifdown-ppp       ifup-ib       ifup-Team
ifcfg-satic-ip-ens36  ifdown-routes    ifup-ippp     ifup-TeamPort
[root@localhost network-scripts]# more ifcfg-dhcp-ens36 
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=dhcp-ens36
UUID=24c4cd02-c719-428c-bf49-3286677189e2
DEVICE=ens36
ONBOOT=yes
[root@localhost network-scripts]# nmcli connection up dhcp-ens36 
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/46)
[root@localhost network-scripts]# ip add show
3: ens36: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:d5:14:14 brd ff:ff:ff:ff:ff:ff
    inet 192.168.11.128/24 brd 192.168.11.255 scope global noprefixroute dynamic ens36
[root@localhost network-scripts]# more /etc/resolv.conf
# Generated by NetworkManager
search localdomain
nameserver 114.114.114.114
nameserver 192.168.11.1
[root@localhost network-scripts]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.8.2     0.0.0.0         UG    104    0        0 ens33
192.168.8.0     0.0.0.0         255.255.255.0   U     104    0        0 ens33
192.168.11.0    0.0.0.0         255.255.255.0   U     105    0        0 ens36
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0

[root@localhost network-scripts]# nmcli connection up satic-ip-ens36 
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/47)
[root@localhost network-scripts]# ifconfig ens36
ens36: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.11.119  netmask 255.255.255.0  broadcast 192.168.11.255

14.8 主机名管理

#1.查看主机名称

[root@localhost ~]# hostname
localhost.localdomain
[root@localhost ~]# nmcli general hostname
localhost.localdomain

#2.主机名称配置⽂件

[root@centos7 network-scripts]# more /etc/hostname

#3.修改主机名称

[root@localhost ~]# hostnamectl set-hostname centos7-clh

[root@localhost ~]# nmcli general hostname centos7-clh

#4.重启主机名称服务-退出重新登录

[root@localhost ~]# systemctl restart systemd-hostnamed.service 

14.9 网卡图形化管理

GUI - 依赖GNONE/KDE图形化界⾯
nmtui - 不依赖GNONE/KDE图形化界⾯

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值