centos8配置网络环境及阿里云网络yum源

发布时间 2024-01-12 15:51:24作者: 存钱罐儿

一、centos8配置网络环境

1.修改配置网卡配置文件

[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens18
TYPE=Ethernet
NAME=ens18
DEVICE=ens18
IPADDR=192.168.1.76
PERFIX=24
GATEWAY=192.168.1.1
NETMASK=255.255.255.0
DNS1=223.5.5.5
DNS2=202.99.160.68
ONBOOT=yes

2.修改DNS配置文件

[root@localhost ~]# vim /etc/resolv.conf
# Generated by NetworkManager
nameserver 223.5.5.5
nameserver 202.99.160.68

3.重启网络

[root@localhost ~]# nmcli c reload

4.验证是否可以访问外网

[root@localhost ~]# ping baidu.com
PING baidu.com (110.242.68.66) 56(84) bytes of data.
64 bytes from 110.242.68.66 (110.242.68.66): icmp_seq=1 ttl=50 time=15.8 ms
64 bytes from 110.242.68.66 (110.242.68.66): icmp_seq=2 ttl=50 time=17.7 ms
64 bytes from 110.242.68.66 (110.242.68.66): icmp_seq=3 ttl=50 time=20.0 ms 

 

二、配置阿里云网络yum源

1.下载阿里云centos8源

wget -O /etc/yum.repos.d/CentOS-Linux-BaseOS.repo http://mirrors.aliyun.com/repo/Centos-8.repo

1.1如果上一步没有wget命令,则手动下载并上传至/etc/yum.repos.d 目录下。

2.清理本地缓存。

[root@localhost yum.repos.d]# yum clean all
[root@localhost yum.repos.d]# yum makecache

3.验证是否可以正常使用yum网络源

[root@localhost yum.repos.d]# yum install wget -y
Last metadata expiration check: 0:02:59 ago on Fri 12 Jan 2024 03:25:53 PM CST.
Dependencies resolved.
=============================================================================================================================================================================================
 Package                                  Architecture                               Version                                             Repository                                     Size
=============================================================================================================================================================================================
Installing:
 wget                                     x86_64                                     1.19.5-10.el8                                       AppStream                                     734 k

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

Total download size: 734 k
Installed size: 2.8 M
Downloading Packages:
wget-1.19.5-10.el8.x86_64.rpm                                                                                                                                781 kB/s | 734 kB     00:00    
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                        779 kB/s | 734 kB     00:00     
warning: /var/cache/dnf/AppStream-bf1daca1ea021975/packages/wget-1.19.5-10.el8.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 8483c65d: NOKEY
CentOS-8 - AppStream - mirrors.aliyun.com                                                                                                                     21 kB/s | 1.6 kB     00:00    
Importing GPG key 0x8483C65D:
 Userid     : "CentOS (CentOS Official Signing Key) <security@centos.org>"
 Fingerprint: 99DB 70FA E1D7 CE22 7FB6 4882 05B5 55B3 8483 C65D
 From       : http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                                     1/1 
  Installing       : wget-1.19.5-10.el8.x86_64                                                                                                                                           1/1 
  Running scriptlet: wget-1.19.5-10.el8.x86_64                                                                                                                                           1/1 
  Verifying        : wget-1.19.5-10.el8.x86_64                                                                                                                                           1/1 

Installed:
  wget-1.19.5-10.el8.x86_64                                                                                                                                                                  

Complete!