一、虚拟机网卡设置
虚拟机设置->网络。配置网卡1 NAT模式用来上网:
网卡2 Host-Only模式用来主机SSH连接登录
以上混杂模式均设置成全部允许
二、虚拟里配置两个网卡DHCP自动分配ip
查看网卡名ifconfig -a
,找到enp开头的网卡名,第一个enps03就是上步中的网卡1,enps08为网卡2
切换到cd /etc/netplan/
目录下,编辑sudo vim 00-installer-config.yaml
文件,若没有则新建一个,注意后缀为.yaml
即可,写入内容如下:
# This is the network config written by 'subiquity'
network:
ethernets:
enp0s3:
dhcp4: true
dhcp4-overrides:
route-metric: 100
enp0s8:
dhcp4: true
dhcp4-overrides:
route-metric: 200
version: 2
上述配置详细说明可参考:https://netplan.io/examples/,应用更改sudo netplan apply
,查看分配的ip地址:
ninja@ken:~$ ip ro
default via 10.0.2.2 dev enp0s3 proto dhcp src 10.0.2.15 metric 100
10.0.2.0/24 dev enp0s3 proto kernel scope link src 10.0.2.15
10.0.2.2 dev enp0s3 proto dhcp scope link src 10.0.2.15 metric 100
172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1 linkdown
192.168.56.0/24 dev enp0s8 proto kernel scope link src 192.168.56.104
三、测试
ping
下网络,ok!
martin@ken:~$ ping www.baidu.com
PING www.a.shifen.com (14.215.177.39) 56(84) bytes of data.
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=1 ttl=53 time=11.7 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=2 ttl=53 time=10.5 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=3 ttl=53 time=8.96 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=4 ttl=53 time=9.70 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=5 ttl=53 time=10.9 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=6 ttl=53 time=10.5 ms
记录下enp0s8的ip地址,ssh登录
PS C:\Users\NingZ> ssh ninja@192.168.56.104
ninja@192.168.56.104's password:
Welcome to Ubuntu 18.04.5 LTS (GNU/Linux 4.15.0-151-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
大工告成!