Centos8 配置IP地址与阿里YUM源

Centos8 系统中无法找到network.service网络服务,默认已经被nmcli替换了,所以修改方式略微变化,在/etc/sysconfig/network-scripts/里也看不到任何脚本文件,没有传统的network.service。

IP地址的配置

Centos8 系统中无法找到network.service网络服务,默认已经被nmcli替换了,所以修改方式略微变化,在/etc/sysconfig/network-scripts/里也看不到任何脚本文件,没有传统的network.service。

  1. 修改 vi /etc/sysconfig/network-scripts/ifcfg-ens32
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
IPADDR=192.168.1.30
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=8.8.8.8
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
NAME=ens32
UUID=08a82de8-2371-4411-ba0f-36053776c8ae
DEVICE=ens32
ONBOOT=no

网卡启动查询关闭删除等命令: 使用nmcli重新回载网络配置

# 重载所有ifcfg或route到connection(不会立即生效)
nmcli c reload

# 重载指定ifcfg或route到connection(不会立即生效)
nmcli c load /etc/sysconfig/network-scripts/ifcfg-ens32
nmcli c load /etc/sysconfig/network-scripts/route-ens32

# 启用connection(相当于ifup)
nmcli c up ens32

# 停止connection(相当于ifdown)
nmcli c down ens32

# 删除connection(类似于ifdown并删除ifcfg)
nmcli c delete ens32

# 查看connection列表
nmcli c show

# 查看connection详细信息
nmcli c show ens32

命令行配置IP地址的方式:

# 创建connection,配置静态ip(等同于配置ifcfg,其中BOOTPROTO=none,并ifup启动)
nmcli c add type ethernet con-name ens32 ifname ens32 ipv4.addr 192.168.1.30/24 ipv4.gateway 192.168.1.1 ipv4.method manual
 
# 创建connection,配置动态ip(等同于配置ifcfg,其中BOOTPROTO=dhcp,并ifup启动)
nmcli c add type ethernet con-name ens32 ifname ens32 ipv4.method auto

# 修改ip(非交互式)
nmcli c modify ens32 ipv4.addr '192.168.1.30/24'
nmcli c up ens32

# 修改ip(交互式)
nmcli c edit ens32
nmcli> goto ipv4.addresses
nmcli ipv4.addresses> change
Edit 'addresses' value: 192.168.1.30/24
Do you also want to set 'ipv4.method' to 'manual'? [yes]: yes
nmcli ipv4> save
nmcli ipv4> activate
nmcli ipv4> quit

查询网卡的方法:

nmcli d         # 查询device列表
nmcli d show ens32  # 查询指定网卡
nmcli d connect ens32  # 激活网卡
nmcli r all off    # 关闭无线网络

配置阿里YUM仓库

CentOS 8更改了软件包的安装程序,取消了 yum 的配置方法,改而使用了dnf 作为安装程序。

1.默认是这样的。

[root@localhost yum.repos.d]# ls
CentOS-AppStream.repo   CentOS-CR.repo         CentOS-fasttrack.repo  CentOS-PowerTools.repo
CentOS-Base.repo        CentOS-Debuginfo.repo  CentOS-HA.repo         CentOS-Sources.repo
CentOS-centosplus.repo  CentOS-Extras.repo     CentOS-Media.repo      CentOS-Vault.repo
[root@localhost yum.repos.d]#

2.配置文件,依次配置一下四个目录。

[root@localhost yum.repos.d]# cat CentOS-AppStream.repo
[AppStream]
name=CentOS-$releasever - AppStream
baseurl=http://mirrors.aliyun.com/centos/$releasever/AppStream/$basearch/os/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial


[root@localhost yum.repos.d]# cat CentOS-Base.repo
[BaseOS]
name=CentOS-$releasever - Base
baseurl=http://mirrors.aliyun.com/centos/$releasever/BaseOS/$basearch/os/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial

[root@localhost yum.repos.d]# cat CentOS-Epel.repo
[epel]
name=CentOS-$releasever - Epel
baseurl=http://mirrors.aliyun.com/epel/8/Everything/$basearch
enabled=1
gpgcheck=0

3.建立缓存。

[root@localhost ~]# dnf clean all
20 files removed
[root@localhost ~]# dnf makecache
CentOS-8 - AppStream                                                                    4.5 MB/s | 6.4 MB     00:01
CentOS-8 - Base                                                                         3.5 MB/s | 5.0 MB     00:01
CentOS-8 - Epel                                                                         4.4 MB/s | 5.7 MB     00:01
CentOS-8 - Extras                            [                  ===                   ] ---  B/s |   0  B     --:-- ETA

本地源配置

通过RPM命令我们可以导入系统镜像的原厂证书,当DNF配置文件中的gpgcheck=1时安装程序之前会验证该证书.

[root@localhost ~]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial   # 导入证书
[root@localhost ~]# rpm -qa | grep pubkey                                      # 查询证书序列号
gpg-pubkey-8483c65d-5ccc5b19

[root@localhost ~]# rpm -qi gpg-pubkey-8483c65d-5ccc5b19                       # 查询详细信息
Name        : gpg-pubkey
Version     : 8483c65d
Release     : 5ccc5b19
Architecture: (none)
Install Date: 2022年02月07日 星期一 01时33分16秒
Group       : Public Keys
Size        : 0
License     : pubkey
Signature   : (none)
Source RPM  : (none)
Build Date  : 2019年05月03日 星期五 11时15分37秒
Build Host  : localhost
Relocations : (not relocatable)
Packager    : CentOS (CentOS Official Signing Key) <security@centos.org>
Summary     : gpg(CentOS (CentOS Official Signing Key) <security@centos.org>)
Description :
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: rpm-4.14.3 (NSS-3)

配置本地源需要跳转到/etc/yum.repos.d/清空当前目录下所有的配置文件,新建CentOS-Stream-Media.repo并写入如下内容,指定当前镜像位置.

[root@localhost yum.repos.d]# cat CentOS-Stream-Media.repo

[media-baseos]
name=CentOS Stream $releasever - Media - BaseOS
baseurl=file:///mnt/BaseOS
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial

[media-appstream]
name=CentOS Stream $releasever - Media - AppStream
baseurl=file:///mnt/AppStream
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
posted @ 2020-02-16 15:52  lyshark  阅读(2165)  评论(0编辑  收藏  举报

loading... | loading...
博客园 - 开发者的网上家园