Rocky linux 9 初始化
# Rocky Linux 9 初始化
# 更改阿里源
aliyun rockylinux (opens new window)
sed -e 's|^mirrorlist=|#mirrorlist=|g' \
-e 's|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl=https://mirrors.aliyun.com/rockylinux|g' \
-i.bak \
/etc/yum.repos.d/[Rr]ocky*.repo
dnf makecache
1
2
3
4
5
2
3
4
5
更改官方提供的CN源
eScience Center, Nanjing University (opens new window)
sed -e 's|^mirrorlist=|#mirrorlist=|g' \
-e 's|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl=https://mirrors.nju.edu.cn/rocky|g' \
-i.bak \
/etc/yum.repos.d/[Rr]ocky*.repo
dnf makecache
1
2
3
4
5
2
3
4
5
Dalian Neusoft University of Information (opens new window)
sed -e 's|^mirrorlist=|#mirrorlist=|g' \
-e 's|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl=https://mirrors.neusoft.edu.cn/rocky|g' \
-i.bak \
/etc/yum.repos.d/[Rr]ocky*.repo
dnf makecache
1
2
3
4
5
2
3
4
5
# 安装常用软件
dnf -y install epel-release
dnf -y install screen lrzsz
# 更新
dnf -y update
1
2
3
4
2
3
4
# 更改网卡名称为 eth0
# 查看当前网卡信息
ifconfig
1
2
2
# 更改 NetworkManager 服务配置,使其能自动生成配置文件在 /etc/sysconfig/network-scripts
sed -i 's/#plugins=keyfile,ifcfg-rh/plugins=ifcfg-rh/g' /etc/NetworkManager/NetworkManager.conf
# 重启服务
systemctl restart NetworkManager
# 新增 eth0 连接并生成配置文件
nmcli connection add type ethernet con-name eth0 ifname ens160
# 删除原网卡连接
nmcli connection delete ens160
nmcli connection show
# 更改设备名称
sed -i 's/ens160/eth0/g' /etc/sysconfig/network-scripts/ifcfg-eth0
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
# 修改核心配置
# 备份配置文件
cp /etc/default/grub /etc/default/grub.bak
# 修改配置文件
sed -i 's/rhgb/net.ifnames=0 &/' /etc/default/grub
# 生成启动文件
grub2-mkconfig -o /boot/grub2/grub.cfg
# 重启
shutdown -r now
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
# 配置固定ip地址
# 将网卡由ip自动获取改为静态
sed -i 's/BOOTPROTO=dhcp/BOOTPROTO=static/g' /etc/sysconfig/network-scripts/ifcfg-eth0
cat >>/etc/sysconfig/network-scripts/ifcfg-eth0<<EOF
IPADDR=192.168.7.4
PREFIX=24
GATEWAY=192.168.7.2
DNS1=192.168.7.2
DNS2=223.5.5.5
EOF
# 重新加载配置文件&&重启网卡
nmcli connection reload && nmcli connection up eth0
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
# 系统语言修改成英文
sed -e 's|^LANG=|#LANG=|g' \
-e '1aLANG=en_US.UTF-8' \
-i \
/etc/locale.conf
# 重启
shutdown -r now
1
2
3
4
5
6
2
3
4
5
6
上次更新: 2024/05/11, 03:55:33