您的位置:首页 > 博客中心 > 网络系统 >

Linux——Centos8.2如何重启网卡服务

时间:2022-04-03 16:13

前言

Centos8已经废弃了network.service,请使用nmcli

内容

[root@localhost ~]# nmcli --help
Usage: nmcli [OPTIONS] OBJECT { COMMAND | help }

OPTIONS
  -a, --ask                                ask for missing parameters
  -c, --colors auto|yes|no                 whether to use colors in output
  -e, --escape yes|no                      escape columns separators in values
  -f, --fields <field,...>|all|common      specify fields to output
  -g, --get-values <field,...>|all|common  shortcut for -m tabular -t -f
  -h, --help                               print this help
  -m, --mode tabular|multiline             output mode
  -o, --overview                           overview mode
  -p, --pretty                             pretty output
  -s, --show-secrets                       allow displaying passwords
  -t, --terse                              terse output
  -v, --version                            show program version
  -w, --wait <seconds>                     set timeout waiting for finishing operations

OBJECT
  g[eneral]       NetworkManager‘s general status and operations
  n[etworking]    overall networking control
  r[adio]         NetworkManager radio switches
  c[onnection]    NetworkManager‘s connections
  d[evice]        devices managed by NetworkManager
  a[gent]         NetworkManager secret agent or polkit agent
  m[onitor]       monitor NetworkManager changes

命令详解

  1. 使用nmcli重新回载网络配置
# nmcli c reload
  1. 打开网卡
# nmcli c up <网卡>
  1. 查看网卡信息
# nmcli con 
NAME   UUID                                  TYPE      DEVICE 
ens33  36a7b552-ab17-4b2d-afd9-de96c6c935eb  ethernet  ens33 
  1. 显示具体的网络接口信息
# nmcli connection show xxx
  1. 显示所有活动连接
# nmcli connection show --active
  1. 删除一个网卡连接
# nmcli connection delete xxx
  1. 给xxx添加一个IP(IPADDR)
# nmcli connection modify xxx ipv4.addresses 192.168.0.51
  1. 给xxx添加一个子网掩码(NETMASK)
# nmcli connection modify xxx ipv4.addresses 192.168.0.51/24
  1. IP获取方式设置成手动(BOOTPROTO=static/none)
# nmcli connection modify xxx ipv4.method manual
  1. 添加一个ipv4
# nmcli connection modify xxx +ipv4.addresses 192.168.0.51/24
  1. 删除一个ipv4
# nmcli connection modify xxx -ipv4.addresses 192.168.0.51/24
  1. 添加DNS
# nmcli connection modify xxx ipv4.dns 114.114.114.114
  1. 删除DNS
# nmcli connection modify xxx -ipv4.dns 114.114.114.114
  1. 添加一个网关(GATEWAY)
# nmcli connection modify xxx ipv4.gateway 192.168.0.1
  1. 网关和DNS一起写入
# nmcli connection modify xxx ipv4.dns 114.114.114.114 ipv4.gateway 192.168.0.1

本类排行

今日推荐

热门手游