CentOS常用命令
# 实验基础环境搭建
# 关闭防火墙
systemctl stop firewalld
systemctl status firewalld
systemctl disable firewalld
1
2
3
2
3
# 关闭NetworkManager
# 关闭NetworkManager服务
$ sudo systemctl stop NetworkManager
$ sudo systemctl status NetworkManager
$ sudo systemctl disable NetworkManager
1
2
3
4
2
3
4
# 禁用selinux
查看selinux状态
getenforce
1
如果值为Disables则表明为关闭状态,其他值可通过修改配置文件方式进行修改,
永久关闭selinux,需要重启系统
vim /etc/selinux/config
修改selinux=disable
或
#永久生效,但是必须要重启系统。
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
1
2
3
4
5
2
3
4
5
暂时关闭selinux,不需要重启系统
setenforce 0
1
# 更换yum源
国内yum源:
阿里yum源:http://mirrors.aliyun.com/repo/
163(网易)yum源: http://mirrors.163.com/.help/
中科大的Linux安装镜像源:http://centos.ustc.edu.cn/
先备份
sudo mkdir /etc/yum.repos.d.backup
备份
sudo cp /etc/yum.repos.d/* /etc/yum.repos.d.backup
1
2
3
4
2
3
4
方法一
直接替换/etc/yum.repos.d目录下的文件 文件下载地址 (opens new window) 提取码: f34i
#清理yum缓存,并生成新的缓存
yum clean all
yum makecache
1
2
3
2
3
方法二
阿里yum源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
网易源:
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
1
2
3
4
5
2
3
4
5
#清理yum缓存,并生成新的缓存
yum clean all
yum makecache
#若更新yum源不更新内核,直接在 yum 的命令后面加上如下的参数
yum --exclude=kernel* update
1
2
3
4
5
6
2
3
4
5
6
# Linux配置静态IP地址
#切换至特权模式,并输入密码
su root
#进入网卡ens33的配置页面
vim /etc/sysconfig/network-scripts/ifcfg-ens33
#内容修改为如下内容,并保存
BOOTPROTO="static"
ONBOOT=yes
IPADDR="xxx.xxx.xxx.xxx"
NETMASK="255.255.255.0"
GATEWAY="xxx.xxx.xxx.xxx"
DNS1="114.114.114.114"
#重启网卡
systemctl restart network
#查看网卡ens33的IP地址已经变成配置的静态IP地址
ip addr
#ping自己,ping网关,验证网络能通
ping xxx.xxx.xxx.xxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 修改主机名
查看主机名
hostname
1
修改主机名
hostnamectl set-hostname 名称
1
# 安装VMware Tools
# 解压命令
tar -zxvf VMwareTools-10.3.22-15902021.tar.gz
1
Last Updated: 2025/11/21, 16:34:23