CentOS8使用network.service服务管理网络

前言:
在CentOS8中,我们常用的network.service服务就被NetworkManager.service服务代替了,同样的,IP的配置方法也发生了改变,那么如果想使用network.service服务去管理/配置系统网络怎么办呢?下面带你梦回network.service

准备工作:

  • 系统能连上网

一、禁用NetworkManager.service

systemctl stop NetworkManager
systemctl disable NetworkManager

执行结果:

[root@localhost ~]# systemctl stop NetworkManager
[root@localhost ~]# systemctl disable NetworkManager
Removed /etc/systemd/system/multi-user.target.wants/NetworkManager.service.
Removed /etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service.
Removed /etc/systemd/system/network-online.target.wants/NetworkManager-wait-online.service.

到这里,NetworkManager服务就停止工作了,这时候可以先安装network-scripts(也就是network.service)了

二、安装network-scripts

静默安装(-q)

dnf install -y -q network-scripts

安装过程:

[root@localhost ~]# dnf install -y -q network-scripts
警告:/var/cache/dnf/BaseOS-929b586ef1f72f69/packages/network-scripts-10.00.6-1.el8_2.1.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID 8483c65d: NOKEY
导入 GPG 公钥 0x8483C65D:
 Userid: "CentOS (CentOS Official Signing Key) "
 指纹: 99DB 70FA E1D7 CE22 7FB6 4882 05B5 55B3 8483 C65D
 来自: /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
[root@localhost ~]# 

此时,服务安装完成了,接下来开始启用该服务
启用之前再次确保NetworkManager关闭

systemctl stop NetworkManager
systemctl start network
systemctl enable network
systemctl status network

执行结果:

[root@localhost ~]# systemctl stop NetworkManager
[root@localhost ~]# systemctl start network
[root@localhost ~]# systemctl enable network
network.service is not a native service, redirecting to systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable network
[root@localhost ~]# systemctl status network
● network.service - LSB: Bring up/down networking
   Loaded: loaded (/etc/rc.d/init.d/network; generated)
   Active: active (running) since Fri 2020-07-03 12:49:02 EDT; 1min 46s ago
     Docs: man:systemd-sysv-generator(8)
    Tasks: 2 (limit: 11302)
   Memory: 10.2M
   CGroup: /system.slice/network.service
           ├─23350 /sbin/dhclient -1 -q -lf /var/lib/dhclient/dhclient-37ed0dcd-4d32-4c1e-aaa1-6371494d4541-ens33.lease -pf /run/dhclient-ens33.pid ens33
           └─23463 /sbin/dhclient -1 -q -lf /var/lib/dhclient/dhclient-c87fa705-ed9f-4e03-b25a-142389898ff0-ens34.lease -pf /run/dhclient-ens34.pid ens34

7月 03 12:48:58 localhost network[23169]: 正在打开接口 ens34:
7月 03 12:48:58 localhost dhclient[23438]: Created duid "\000\004\305\214\015\204\360\376Az\212\354\216.
7月 03 12:48:58 localhost dhclient[23438]: DHCPDISCOVER on ens34 to 255.255.255.255 port 67 interval 6 (xid=0x986dfb66)
7月 03 12:48:59 localhost dhclient[23438]: DHCPREQUEST on ens34 to 255.255.255.255 port 67 (xid=0x986dfb66)
7月 03 12:48:59 localhost dhclient[23438]: DHCPOFFER from 10.1.1.254
7月 03 12:48:59 localhost dhclient[23438]: DHCPACK from 10.1.1.254 (xid=0x986dfb66)
7月 03 12:49:01 localhost dhclient[23438]: bound to 10.1.1.134 -- renewal in 847 seconds.
7月 03 12:49:01 localhost network[23169]: 正在确定 ens34 的 IP 信息... 完成。
7月 03 12:49:02 localhost network[23169]: [  确定  ]
7月 03 12:49:02 localhost systemd[1]: Started LSB: Bring up/down networking.

此时,network服务已经启动成功了,那么下面就可以对NetworkManager进行卸载了。

三、卸载NetworkManager(可选)

执行卸载命令:

dnf remove -y NetworkManager

执行结果:

[root@localhost ~]# dnf remove -y NetworkManager
依赖关系解决。
==================================================================================================================================================================================================================================================
 软件包                                                                架构                                               版本                                                        仓库                                                   大小
==================================================================================================================================================================================================================================================
移除:
 NetworkManager                                                        x86_64                                             1:1.22.8-4.el8                                              @anaconda                                             8.6 M
移除依赖的软件包:
 NetworkManager-tui                                                    x86_64                                             1:1.22.8-4.el8                                              @anaconda                                             895 k
 cockpit                                                               x86_64                                             211.3-1.el8                                                 @anaconda                                              53 k
清除未被使用的依赖关系:
 NetworkManager-libnm                                                  x86_64                                             1:1.22.8-4.el8                                              @anaconda                                             9.5 M
 NetworkManager-team                                                   x86_64                                             1:1.22.8-4.el8                                              @anaconda                                              52 k
 centos-logos                                                          x86_64                                             80.5-2.el8                                                  @anaconda                                             699 k
 cockpit-bridge                                                        x86_64                                             211.3-1.el8                                                 @anaconda                                             1.0 M
 cockpit-system                                                        noarch                                             211.3-1.el8                                                 @anaconda                                             2.3 M
 cockpit-ws                                                            x86_64                                             211.3-1.el8                                                 @anaconda                                             2.2 M
 glib-networking                                                       x86_64                                             2.56.1-1.1.el8                                              @anaconda                                             519 k
 gsettings-desktop-schemas                                             x86_64                                             3.32.0-4.el8                                                @anaconda                                             4.0 M
 json-glib                                                             x86_64                                             1.4.4-1.el8                                                 @anaconda                                             518 k
 libdaemon                                                             x86_64                                             0.14-15.el8                                                 @anaconda                                              63 k
 libmodman                                                             x86_64                                             2.0.1-17.el8                                                @anaconda                                              68 k
 libndp                                                                x86_64                                             1.7-3.el8                                                   @anaconda                                              79 k
 libnl3-cli                                                            x86_64                                             3.5.0-1.el8                                                 @anaconda                                             819 k
 libproxy                                                              x86_64                                             0.4.15-5.2.el8                                              @anaconda                                             197 k
 libteam                                                               x86_64                                             1.29-1.el8                                                  @anaconda                                             103 k
 network-scripts-team                                                  x86_64                                             1.29-1.el8                                                  @BaseOS                                               6.6 k
 newt                                                                  x86_64                                             0.52.20-11.el8                                              @anaconda                                             212 k
 slang                                                                 x86_64                                             2.3.2-3.el8                                                 @anaconda                                             1.3 M
 teamd                                                                 x86_64                                             1.29-1.el8                                                  @anaconda                                             271 k

事务概要
==================================================================================================================================================================================================================================================
移除  22 软件包

将会释放空间:33 M
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
  准备中  :                                                                                                                                                                                                                                   1/1 
  运行脚本: NetworkManager-tui-1:1.22.8-4.el8.x86_64                                                                                                                                                                                          1/1 
  删除    : NetworkManager-tui-1:1.22.8-4.el8.x86_64                                                                                                                                                                                         1/22 
  删除    : cockpit-211.3-1.el8.x86_64                                                                                                                                                                                                       2/22 
  删除    : cockpit-system-211.3-1.el8.noarch                                                                                                                                                                                                3/22 
  运行脚本: cockpit-ws-211.3-1.el8.x86_64                                                                                                                                                                                                    4/22 
  删除    : cockpit-ws-211.3-1.el8.x86_64                                                                                                                                                                                                    4/22 
  运行脚本: cockpit-ws-211.3-1.el8.x86_64                                                                                                                                                                                                    4/22 
  删除    : cockpit-bridge-211.3-1.el8.x86_64                                                                                                                                                                                                5/22 
  删除    : glib-networking-2.56.1-1.1.el8.x86_64                                                                                                                                                                                            6/22 
  删除    : NetworkManager-team-1:1.22.8-4.el8.x86_64                                                                                                                                                                                        7/22 
  运行脚本: NetworkManager-1:1.22.8-4.el8.x86_64                                                                                                                                                                                             8/22 
  删除    : NetworkManager-1:1.22.8-4.el8.x86_64                                                                                                                                                                                             8/22 
  运行脚本: NetworkManager-1:1.22.8-4.el8.x86_64                                                                                                                                                                                             8/22 
  删除    : teamd-1.29-1.el8.x86_64                                                                                                                                                                                                          9/22 
  运行脚本: teamd-1.29-1.el8.x86_64                                                                                                                                                                                                          9/22 
  删除    : libteam-1.29-1.el8.x86_64                                                                                                                                                                                                       10/22 
  运行脚本: libteam-1.29-1.el8.x86_64                                                                                                                                                                                                       10/22 
  删除    : newt-0.52.20-11.el8.x86_64                                                                                                                                                                                                      11/22 
  删除    : network-scripts-team-1.29-1.el8.x86_64                                                                                                                                                                                          12/22 
  删除    : gsettings-desktop-schemas-3.32.0-4.el8.x86_64                                                                                                                                                                                   13/22 
  删除    : centos-logos-80.5-2.el8.x86_64                                                                                                                                                                                                  14/22 
  运行脚本: centos-logos-80.5-2.el8.x86_64                                                                                                                                                                                                  14/22 
  删除    : libproxy-0.4.15-5.2.el8.x86_64                                                                                                                                                                                                  15/22 
  运行脚本: libproxy-0.4.15-5.2.el8.x86_64                                                                                                                                                                                                  15/22 
  删除    : libmodman-2.0.1-17.el8.x86_64                                                                                                                                                                                                   16/22 
  运行脚本: libmodman-2.0.1-17.el8.x86_64                                                                                                                                                                                                   16/22 
  删除    : slang-2.3.2-3.el8.x86_64                                                                                                                                                                                                        17/22 
  删除    : libnl3-cli-3.5.0-1.el8.x86_64                                                                                                                                                                                                   18/22 
  运行脚本: libnl3-cli-3.5.0-1.el8.x86_64                                                                                                                                                                                                   18/22 
  删除    : libdaemon-0.14-15.el8.x86_64                                                                                                                                                                                                    19/22 
  删除    : NetworkManager-libnm-1:1.22.8-4.el8.x86_64                                                                                                                                                                                      20/22 
  运行脚本: NetworkManager-libnm-1:1.22.8-4.el8.x86_64                                                                                                                                                                                      20/22 
  删除    : libndp-1.7-3.el8.x86_64                                                                                                                                                                                                         21/22 
  运行脚本: libndp-1.7-3.el8.x86_64                                                                                                                                                                                                         21/22 
  删除    : json-glib-1.4.4-1.el8.x86_64                                                                                                                                                                                                    22/22 
  运行脚本: json-glib-1.4.4-1.el8.x86_64                                                                                                                                                                                                    22/22 
  验证    : NetworkManager-1:1.22.8-4.el8.x86_64                                                                                                                                                                                             1/22 
  验证    : NetworkManager-libnm-1:1.22.8-4.el8.x86_64                                                                                                                                                                                       2/22 
  验证    : NetworkManager-team-1:1.22.8-4.el8.x86_64                                                                                                                                                                                        3/22 
  验证    : NetworkManager-tui-1:1.22.8-4.el8.x86_64                                                                                                                                                                                         4/22 
  验证    : centos-logos-80.5-2.el8.x86_64                                                                                                                                                                                                   5/22 
  验证    : cockpit-211.3-1.el8.x86_64                                                                                                                                                                                                       6/22 
  验证    : cockpit-bridge-211.3-1.el8.x86_64                                                                                                                                                                                                7/22 
  验证    : cockpit-system-211.3-1.el8.noarch                                                                                                                                                                                                8/22 
  验证    : cockpit-ws-211.3-1.el8.x86_64                                                                                                                                                                                                    9/22 
  验证    : glib-networking-2.56.1-1.1.el8.x86_64                                                                                                                                                                                           10/22 
  验证    : gsettings-desktop-schemas-3.32.0-4.el8.x86_64                                                                                                                                                                                   11/22 
  验证    : json-glib-1.4.4-1.el8.x86_64                                                                                                                                                                                                    12/22 
  验证    : libdaemon-0.14-15.el8.x86_64                                                                                                                                                                                                    13/22 
  验证    : libmodman-2.0.1-17.el8.x86_64                                                                                                                                                                                                   14/22 
  验证    : libndp-1.7-3.el8.x86_64                                                                                                                                                                                                         15/22 
  验证    : libnl3-cli-3.5.0-1.el8.x86_64                                                                                                                                                                                                   16/22 
  验证    : libproxy-0.4.15-5.2.el8.x86_64                                                                                                                                                                                                  17/22 
  验证    : libteam-1.29-1.el8.x86_64                                                                                                                                                                                                       18/22 
  验证    : network-scripts-team-1.29-1.el8.x86_64                                                                                                                                                                                          19/22 
  验证    : newt-0.52.20-11.el8.x86_64                                                                                                                                                                                                      20/22 
  验证    : slang-2.3.2-3.el8.x86_64                                                                                                                                                                                                        21/22 
  验证    : teamd-1.29-1.el8.x86_64                                                                                                                                                                                                         22/22 

已移除:
  NetworkManager-1:1.22.8-4.el8.x86_64   NetworkManager-libnm-1:1.22.8-4.el8.x86_64 NetworkManager-team-1:1.22.8-4.el8.x86_64 NetworkManager-tui-1:1.22.8-4.el8.x86_64 centos-logos-80.5-2.el8.x86_64                cockpit-211.3-1.el8.x86_64  
  cockpit-bridge-211.3-1.el8.x86_64      cockpit-system-211.3-1.el8.noarch          cockpit-ws-211.3-1.el8.x86_64             glib-networking-2.56.1-1.1.el8.x86_64    gsettings-desktop-schemas-3.32.0-4.el8.x86_64 json-glib-1.4.4-1.el8.x86_64
  libdaemon-0.14-15.el8.x86_64           libmodman-2.0.1-17.el8.x86_64              libndp-1.7-3.el8.x86_64                   libnl3-cli-3.5.0-1.el8.x86_64            libproxy-0.4.15-5.2.el8.x86_64                libteam-1.29-1.el8.x86_64   
  network-scripts-team-1.29-1.el8.x86_64 newt-0.52.20-11.el8.x86_64                 slang-2.3.2-3.el8.x86_64                  teamd-1.29-1.el8.x86_64                 

完毕!
[root@localhost ~]# 

那么到这里,NetworkManager服务就没了,然后我们使用network服务进行管理网络

四、验证network服务管理网络

首先进入我们熟悉的路径:

 cd /etc/sysconfig/network-scripts/
 ls

执行结果如下:

[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# ls
ifcfg-ens33  ifdown       ifdown-ippp  ifdown-post    ifdown-tunnel  ifup-bnep  ifup-ipv6  ifup-plusb   ifup-sit       init.ipv6-global
ifcfg-ens34  ifdown-bnep  ifdown-ipv6  ifdown-routes  ifup           ifup-eth   ifup-isdn  ifup-post    ifup-tunnel    network-functions
ifcfg-lo     ifdown-eth   ifdown-isdn  ifdown-sit     ifup-aliases   ifup-ippp  ifup-plip  ifup-routes  ifup-wireless  network-functions-ipv6

然后尝试更改IP地址:
CentOS8使用network.service服务管理网络_第1张图片
此时,已经可以使用network服务进行管理IP了

你可能感兴趣的:(centos,Linux,linux,centos,network.service,networkmanager)