VirtualBox下为Ubuntu虚机添加第二块网卡

前端之家收集整理的这篇文章主要介绍了VirtualBox下为Ubuntu虚机添加第二块网卡前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

问题描述

因为做Docker网络实验,需要将原先Ubuntu虚机的一块“桥接”网卡改为“HostOnly”网卡,并且添加另一块“NAT”网卡。几经周折发现只有第一块网卡可以正确配置,ifconfig里根本看不到有第二块网卡。

查找问题

于是上网找了找,找到了一个CentOS虚机的,不太适用,但思路大概有了,就继续往下搜,找到了Ubuntu的一篇文章。试了试,发现有点门路。

但我的网络设备不是“eth0”,而是“enp0s3”,于是find了一下可能的目录,果然找到了第二块网卡的名字。

解决步骤

我的解决步骤:

schen@H_404_24@@scvmu01:/sys/class/net@H_404_24@$ ls
docker0 enp0s3 enp0s8 lo
schen@scvmu01:~$ sudo vi /etc/network/interfaces
[sudo] password for schen: 
# This file describes the network interfaces available on your system
# and how to activate them. For more information,see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto enp0s3
iface enp0s3 inet dhcp

# The user added network interface
auto enp0s8
iface enp0s8 inet dhcp
~
~

(照猫画虎添加最后三行内容

  • 启动网络设备
schen@scvmu01:~$ sudo ifup enp0s8
Internet Systems Consortium DHCP Client 4.3.3
Copyright 2004-2015 Internet Systems Consortium.
All rights reserved.
For info,please visit https://www.isc.org/software/dhcp/

Listening on LPF/enp0s8/08:00:27:13:1e:58
Sending on LPF/enp0s8/08:00:27:13:1e:58
Sending on Socket/fallback
DHCPDISCOVER on enp0s8 to 255.255.255.255 port 67 interval 3 (xid=0xee28051e)
DHCPREQUEST of 192.168.56.103 on enp0s8 to 255.255.255.255 port 67 (xid=0x1e0528ee)
DHCPOFFER of 192.168.56.103 from 192.168.56.100
DHCPACK of 192.168.56.103 from 192.168.56.100
bound to 192.168.56.103 -- renewal in 514 seconds.
schen@scvmu01:~$
  • 查看网络设备
schen@H_404_24@@scvmu01:~@H_404_24@$ ifconfig enp0s8
enp0s8    Link encap:Ethernet  HWaddr 08:00:27:13:1e:58  
          inet addr:192.168.56.103  Bcast:192.168.56.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe13:1e58/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:18 errors:0 dropped:0 overruns:0 frame:0
          TX packets:58 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:3073 (3.0 KB)  TX bytes:8585 (8.5 KB)

schen@H_404_24@@scvmu01:~@H_404_24@$ 
  • 重启虚机
schen@H_404_24@@scvmu01:~@H_404_24@$ sudo reboot

参考文章

这篇文章给我提供了思路:
VirtualBox上Ubuntu Server虚拟机配置双网卡

CentOS的同学可以参考这篇文章
virtualbox虚拟机添加双网卡不起作用的解决办法

鸣谢以上文章作者!

原文链接:https://www.f2er.com/ubuntu/356189.html

猜你在找的Ubuntu相关文章