VirtualBox虚拟机Ubuntu配置网络及SSH登陆

一、虚拟机网卡设置

虚拟机设置->网络。配置网卡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

大工告成!

  • 5
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Roc大鹏君

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值