目錄
- 一.VMware Fusion自定義網段
- 1.什麼是VMware Fusion
- 2.自定義VMware Fusion網段
- 二.Ubuntu 22.04LTS基本配置
- 1.安裝ubuntu系統
- 2.配置root使用者登陸
- 3.配置靜態IP地址
- 4.修改預設的網路卡為ens33
- 5.配置PS1變數
- 6.設定登陸介面為字元介面
一.VMware Fusion自定義網段
1.什麼是VMware Fusion
VMware Fusion是VMware公司推出MacOS的虛擬化解決方案,熟悉"VMware Workstation"的小夥伴使用起來很友好。
因為這兩個產品均出自一家公司,很多設計套路幾乎是一致的。MacOS的使用者僅需要個別配置注意下。
2.自定義VMware Fusion網段
1.停止vm網路服務
sudo /Applications/VMware\ Fusion.app/Contents/Library/vmnet-cli --stop
2.修改網段配置
# sudo vim /Library/Preferences/VMware\ Fusion/networking
...
# 僅需要修改VNET的網段,比如我將網段和子網掩碼作如下修改。
answer VNET_8_HOSTONLY_NETMASK 255.255.255.0
answer VNET_8_HOSTONLY_SUBNET 10.0.0.0
3.應用配置生效,會覆蓋現有的網路配置檔案
sudo /Applications/VMware\ Fusion.app/Contents/Library/vmnet-cli --configure
...
溫馨提示:
此步驟,會自動生成"/Library/Preferences/VMware\ Fusion/vmnet8/nat.conf"和"/Library/Preferences/VMware\ Fusion/vmnet8/dhcpd.conf"的配置檔案,如果之前修改過的話會直接覆蓋喲~
4.啟動vm網路服務
sudo /Applications/VMware\ Fusion.app/Contents/Library/vmnet-cli --start
二.Ubuntu 22.04LTS基本配置
1.安裝ubuntu系統
基於VMware Fusion或者"VMware Workstation"軟體環境安裝Ubuntu 22.04LTS版本可參考我之前的筆記。
參考連結:
2.配置root使用者登陸
1.更新軟體源
sudo apt update
sudo apt -y install gdm3 net-tools iputils-ping
2.修改"gdm-password"配置檔案
sudo vim /etc/pam.d/gdm-password
...
# auth required pam_succeed_if.so user != root quiet_success
3.修改"gdm-autologin"配置檔案
sudo vim /etc/pam.d/gdm-autologin
...
# auth required pam_succeed_if.so user != root quiet_success
4.修改sshd服務的配置檔案
sudo vim /etc/ssh/sshd_config
...
PermitRootLogin yes
5.重啟sshd服務
sudo systemctl restart sshd
6.配置root的密碼
sudo passwd root
3.配置靜態IP地址
1.修改網路卡的配置檔案
root@yinzhengjie:~# cat /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
ethernets:
ens33:
dhcp4: false
addresses:
- 10.0.0.99/24
routes:
- to: default
via: 10.0.0.2
nameservers:
addresses:
# 114 DNS
- 114.114.114.114
- 114.114.115.115
# 阿里雲DNS
- 223.5.5.5
- 223.6.6.6
# 騰訊雲DNS
- 119.29.29.29
- 119.28.28.28
# 百度DNS
- 180.76.76.76
# Google DNS
- 8.8.8.8
- 4.4.4.4
version: 2
root@yinzhengjie:~#
2.應用配置
root@yinzhengjie:~# netplan apply
WARNING:root:Cannot call Open vSwitch: ovsdb-server.service is not running.
root@yinzhengjie:~#
3.測試登陸
yinzhengjie@bogon ~ % ssh root@10.0.0.128
ssh: connect to host 10.0.0.128 port 22: Host is down
yinzhengjie@bogon ~ %
yinzhengjie@bogon ~ % ssh root@10.0.0.99
The authenticity of host '10.0.0.99 (10.0.0.99)' can't be established.
ED25519 key fingerprint is SHA256:0nx8FS4qKOmN/qeKLRFMrY/MlyqRKzHGi6zmiMhS/1Q.
This host key is known by the following other names/addresses:
~/.ssh/known_hosts:1: 10.0.0.128
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '10.0.0.99' (ED25519) to the list of known hosts.
root@10.0.0.99's password:
Welcome to Ubuntu 22.04.4 LTS (GNU/Linux 5.15.0-112-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/pro
System information as of Sat Jun 8 05:47:16 AM UTC 2024
System load: 0.24853515625 Processes: 224
Usage of /: 33.1% of 22.94GB Users logged in: 2
Memory usage: 14% IPv4 address for ens33: 10.0.0.99
Swap usage: 0%
* Strictly confined Kubernetes makes edge and IoT secure. Learn how MicroK8s
just raised the bar for easy, resilient and secure K8s cluster deployment.
https://ubuntu.com/engage/secure-kubernetes-at-the-edge
Expanded Security Maintenance for Applications is not enabled.
24 updates can be applied immediately.
To see these additional updates run: apt list --upgradable
Enable ESM Apps to receive additional future security updates.
See https://ubuntu.com/esm or run: sudo pro status
*** System restart required ***
Last login: Sat Jun 8 05:30:29 2024 from 10.0.0.1
root@yinzhengjie:~#
4.修改預設的網路卡為ens33
1.修改前檢視網路卡資訊
root@yinzhengjie:~# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.0.99 netmask 255.255.255.0 broadcast 10.0.0.255
inet6 fe80::20c:29ff:fe7c:3446 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:7c:34:46 txqueuelen 1000 (Ethernet)
RX packets 183808 bytes 254335961 (254.3 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 27678 bytes 2825913 (2.8 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 177 bytes 16580 (16.5 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 177 bytes 16580 (16.5 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
root@yinzhengjie:~#
2.修改配置檔案
root@yinzhengjie:~# vim /etc/default/grub
...
GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0"
3.用"grub-mkconfig"工具重新生成新的配置檔案
root@yinzhengjie:~# grub-mkconfig -o /boot/grub/grub.cfg
Sourcing file `/etc/default/grub'
Sourcing file `/etc/default/grub.d/init-select.cfg'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.15.0-112-generic
Found initrd image: /boot/initrd.img-5.15.0-112-generic
Warning: os-prober will not be executed to detect other bootable partitions.
Systems on them will not be added to the GRUB boot configuration.
Check GRUB_DISABLE_OS_PROBER documentation entry.
Adding boot menu entry for UEFI Firmware Settings ...
done
root@yinzhengjie:~#
4.檢視網路卡的配置資訊
root@yinzhengjie:~# cat /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
ethernets:
eth0:
dhcp4: false
addresses:
- 10.0.0.99/24
routes:
- to: default
via: 10.0.0.2
nameservers:
addresses:
# 114 DNS
- 114.114.114.114
- 114.114.115.115
# 阿里雲DNS
- 223.5.5.5
- 223.6.6.6
# 騰訊雲DNS
- 119.29.29.29
- 119.28.28.28
# 百度DNS
- 180.76.76.76
# Google DNS
- 8.8.8.8
- 4.4.4.4
version: 2
root@yinzhengjie:~#
5.重啟虛擬機器
root@yinzhengjie:~# reboot
Connection to 10.0.0.99 closed by remote host.
Connection to 10.0.0.99 closed.
yinzhengjie@bogon ~ %
6.連線測試,觀察網路卡是否變更成功
yinzhengjie@bogon ~ % ssh root@10.0.0.99
root@10.0.0.99's password:
Welcome to Ubuntu 22.04.4 LTS (GNU/Linux 5.15.0-112-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/pro
System information as of Sat Jun 8 06:42:43 AM UTC 2024
System load: 0.59033203125 Processes: 296
Usage of /: 33.2% of 22.94GB Users logged in: 0
Memory usage: 15% IPv4 address for eth0: 10.0.0.99
Swap usage: 0%
* Strictly confined Kubernetes makes edge and IoT secure. Learn how MicroK8s
just raised the bar for easy, resilient and secure K8s cluster deployment.
https://ubuntu.com/engage/secure-kubernetes-at-the-edge
Expanded Security Maintenance for Applications is not enabled.
24 updates can be applied immediately.
To see these additional updates run: apt list --upgradable
Enable ESM Apps to receive additional future security updates.
See https://ubuntu.com/esm or run: sudo pro status
Last login: Sat Jun 8 05:47:16 2024 from 10.0.0.1
root@yinzhengjie:~#
root@yinzhengjie:~# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.0.99 netmask 255.255.255.0 broadcast 10.0.0.255
inet6 fe80::20c:29ff:fe7c:3446 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:7c:34:46 txqueuelen 1000 (Ethernet)
RX packets 265 bytes 303006 (303.0 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 118 bytes 17912 (17.9 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 115 bytes 9607 (9.6 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 115 bytes 9607 (9.6 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
root@yinzhengjie:~#
5.配置PS1變數
cat <<EOF >> ~/.bashrc
PS1='[\[\e[34;1m\]\u@\[\e[0m\]\[\e[32;1m\]\H\[\e[0m\]\[\e[31;1m\] \W\[\e[0m\]]# '
EOF
source ~/.bashrc
6.設定登陸介面為字元介面
1.切換到字元介面
[root@yinzhengjie ~]# systemctl set-default multi-user.target
Created symlink /etc/systemd/system/default.target → /lib/systemd/system/multi-user.target.
[root@yinzhengjie ~]#
2.重啟作業系統
[root@yinzhengjie ~]# reboot
Connection to 10.0.0.99 closed by remote host.
Connection to 10.0.0.99 closed.
yinzhengjie@bogon ~ %
溫馨提示:
我的環境預設安裝的Ubuntu系統,對於VMware Fusion虛擬機器開啟發現是圖形化介面,還沒有終端可以操作。
因此建議配置完成後,一定要將預設級別設定為字元介面,如果你真的很想用圖形化介面,可以使用如下命令。
方法一:
systemctl set-default graphical.target
方案二:
startx
方法三:
init 5