虚拟机每次重新启动,都会动态分配IP,这导致我们无法使用一个固定的ip连接到虚拟机内部。解决该问题的最直接有效的办法就是给虚拟机绑定2张网卡
,一张用于连接外网、一张用于连接内网。
注意,图上选中的是外部,您别选错了。选内部啊
网络和 Internet
,点击查看网络状态和任务
先看一下原有内容
# This is the network config written by 'subiquity'
network:
ethernets:
eth0:
dhcp4: true
version: 2
我们在ethernets
下边再追加一组网卡信息
# This is the network config written by 'subiquity'
network:
ethernets:
eth0:
dhcp4: true
eth1:
dhcp4: false
addresses:
- 192.168.66.254/24
nameservers:
addresses: [114.114.114.114]
version: 2
dhcp4 设置为 false
addresses 设置为192.168.66.xxx/24,这个xxx只要在[1,255)之间,且跟您在控制面板中,对static网卡设置的ip不一样即可;控制面板中对static网卡设置的ip会作为路由;至于为什么后边有/24,大家自行科普一下计算机网络内容,如网段的定义等。
eth0就是第一块网卡,我们追加的网卡命名为eth1(0的基础上加1),代表第二块网卡
nameservers这一组对应的是dns的地址,可以不设置
所以最简的设定为:
# This is the network config written by 'subiquity'
network:
ethernets:
eth0:
dhcp4: true
eth1:
dhcp4: false
addresses:
- 192.168.66.254/24
version: 2
netplan apply
,让配置生效用动态ip再连接一次
这也就是一台机器两个ip的实现方式。撒花~,呱唧呱唧
若遇到ssh无法连接的问题,如下:
ssh dawn@192.168.66.1
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ED25519 key sent by the remote host is
SHA256:xxxxxxxxxx.
Please contact your system administrator.
Add correct host key in C:\\Users\\xxx/.ssh/known_hosts to get rid of this message.
Offending ED25519 key in C:\\Users\\xxx/.ssh/known_hosts:29
Host key for 192.168.66.1 has changed and you have requested strict checking.
Host key verification failed.
使用ssh-keygen -R "XXX.XXX.XXX.XXX"
,将key移除就好了
ssh-keygen -R "192.168.66.1"
# Host 192.168.66.1 found: line 29
C:\Users\xxx/.ssh/known_hosts updated.
Original contents retained as C:\Users\xxx/.ssh/known_hosts.old