# 版本
[root@localhost ~]# hostnamectl
Static hostname: n/a
Transient hostname: localhost
Icon name: computer-vm
Chassis: vm 🖴
Machine ID: 4748448370474b72a05bc780ede57860
Boot ID: fc425789750b42d98d28759d693db379
Virtualization: vmware
Operating System: Red Hat Enterprise Linux 9.1 (Plow)
CPE OS Name: cpe:/o:redhat:enterprise_linux:9::baseos
Kernel: Linux 5.14.0-162.6.1.el9_1.x86_64
Architecture: x86-64
Hardware Vendor: VMware, Inc.
Hardware Model: VMware Virtual Platform
[root@localhost ~]# mkdir /rhel9
[root@localhost ~]# mount /dev/cdrom /rhel9/
mount: /rhel9: WARNING: source write-protected, mounted read-only.
[root@localhost ~]# vim /etc/rc.d/rc.local
# 定位最后一行,添加挂载命令
mount /dev/cdrom /rhel9/
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ll
总用量 0
[root@localhost yum.repos.d]# vim rhel9.repo
[root@localhost yum.repos.d]# cat rhel9.repo
[AppStream]
name=AppStream
baseurl=file:///rhel9/AppStream
gpgcheck=0
[BaseOS]
name=BaseOS
baseurl=file:///rhel9/BaseOS
gpgcheck=0
[root@localhost bin]# vim /bin/vmset.sh
[root@localhost bin]# cat /bin/vmset.sh
#!/bin/bash
rm -fr /etc/NetworkManager/system-connections/$1.nmconnection
cat > /etc/NetworkManager/system-connections/$1.nmconnection <<EOF
[connection]
id=$1
type=ethernet
interface-name=$1
[ipv4]
address1=$2/24,172.25.254.2
method=manual
dns=114.114.114.114;
EOF
chmod 600 /etc/NetworkManager/system-connections/$1.nmconnection
nmcli connection reload
nmcli connection up $1
hostnamectl hostname $3
cat > /etc/hosts <<EOF
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
$2 $3
EOF
# 设置网卡规范名称
[root@localhost bin]# grubby --update-kernel ALL --args net.ifnames=0
# 设置selinux位关闭
[root@localhost bin]# grubby --update-kernel ALL --args selinux=0
# 关闭防火墙
[root@localhost bin]# systemctl stop firewalld
[root@localhost bin]# systemctl mask firewalld.service
Created symlink /etc/systemd/system/firewalld.service → /dev/null.
[root@localhost bin]# vmset.sh eth0 172.25.254.100 apache.timinglee.org
[root@localhost bin]# chmod +x /bin/vmset.sh
[root@localhost bin]# vmset.sh eth0 172.25.254.100 apache.timinglee.org
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/2)
[root@localhost bin]#
# 测试
[root@localhost bin]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.25.254.100 apache.timinglee.org
[root@apache ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 172.25.254.2 0.0.0.0 UG 100 0 0 eth0
172.25.254.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
# 环境测试成功,删除eth0
[root@apache ~]# nmcli connection show
NAME UUID TYPE DEVICE
eth0 7ba00b1d-8cdd-30da-91ad-bb83ed4f7474 ethernet eth0
[root@apache ~]# nmcli connection delete eth0
成功删除连接 "eth0" (7ba00b1d-8cdd-30da-91ad-bb83ed4f7474)。
# 清空历史命令
[rootelocalhost~]# history -c
[rootelocalhost~]# > ~/.bash_history
# 关闭图形化(可关可不关)
[rootelocalhost~]# systemctl set-default multi-user.target