virtualbox中的网络模式,网络设置,固定IP

ops/2024/9/23 4:21:01/

virtualbox关于网络设置的文档:https://www.virtualbox.org/manual/topics/networkingdetails.html#networkingdetails

DHCP

Dynamic Host Configuration Protocol:动态主机配置协议,是专门用来给网络中的节点分发IP地址,确保每个节点的IP地址都是唯一。从协议字面意思来理解"动态"意味着自动处理,当网络环境发生变化时,可以自动调整而不需要人为的干预。比如新节点的加入/离开,DHCP Server可以自动的回收/分发对应IP地址。

它分为两个部份:一个是服务器端,而另一个是客户端。所有的 IP 网络设定数据都由 DHCP 服务器集中管理,并负责处理客户端的 DHCP 要求;而客户端则会使用从服务器分配下来的IP环境数据。

DHCP是局域网的标配,会自动给每个电脑分配动态的IP,意味着你每次启动电脑得到的局域网IP是不同的,如果你希望自己得IP能够固定下来,则需要进行一些设置,步骤如下。

控制面板–>网络和共享中心–>更改适配器设置–>我这里是以太网3

右键以太网3,选择“状态”,查看相关信息,或者点击屏幕右下角的网络图标获取信息。

在这里插入图片描述

右键以太网3,选择“属性”,按如下步骤输入信息,选择“使用下面的IP地址”,即放弃DHCP协议。

IP地址是要输入的,其他都是根据上面查到的信息填写。

在这里插入图片描述

1、内部网络 Internal

多台虚拟机组成一个局域网,他们无法与主机相互访问,也无法与公网相互访问。

NAT 网络:它是 Internal 模式的变种,忽略。与下面的NAT网络地址转换是不同的东西。

2、Host-only Adapter〈宿主机模式〉

在Host-Only模式下,一台宿主机和多台虚拟机构成了一个局域网,他们之间可以相互访问,但是这些虚拟机都无法访问此局域网之外的网络,即无法访问互联网。

在此模式下需要选择一个“主机网络管理器”,在主界面中的管理-->主机网络管理器,可以设置网络管理器。

3、NAT 网络地址转换

Network Address Translation,在没有任何设置的情况下,这是虚拟机默认的网络模式,一个局域网可能有几百台机器,他们要想访问公网,只需要一个公网IP即可,这就是NAT的工作,如果你不设置NAT,那内网IP在公网是无法识别的,也就无法上网。这种方式虚拟机可以上外网,如果宿主机想要访问虚拟机需要设置端口转发。

4、桥接网络 Bridged Adapter

在桥接模式下,虚拟机会选择一个宿主机上的网卡来进行网络数据通信,虚拟机ip地址需要与主机在同一个网段,如果需要联网,则网关与DNS需要与主机网卡一致。同一网段的IP都可以相互通信,包括虚拟机与主机。

在设置桥接网络的时候需要选择一个网卡。第一个是有线网络的,第二个带有 Wireless 字样的是无线网络,这个要跟实际相符。

在这里插入图片描述

5、对比

Introduction to Networking Modes

Each of the networking adapters can be separately configured to operate in one of the following modes:

  • Not attached. In this mode, Oracle VirtualBox reports to the guest that a network card is present, but that there is no connection. This is as if no Ethernet cable was plugged into the card. Using this mode, it is possible to pull the virtual Ethernet cable and disrupt the connection, which can be useful to inform a guest operating system that no network connection is available and enforce a reconfiguration.

  • Network Address Translation (NAT). If all you want is to browse the Web, download files, and view email inside the guest, then this default mode should be sufficient for you, and you can skip the rest of this section. Please note that there are certain limitations when using Windows file sharing. See NAT Limitations.

  • NAT Network. A NAT network is a type of internal network that allows outbound connections. See Network Address Translation Service.

  • Bridged networking. This is for more advanced networking needs, such as network simulations and running servers in a guest. When enabled, Oracle VirtualBox connects to one of your installed network cards and exchanges network packets directly, circumventing your host operating system’s network stack.

  • Internal networking. This can be used to create a different kind of software-based network which is visible to selected virtual machines, but not to applications running on the host or to the outside world.

  • Host-only networking. This can be used to create a network containing the host and a set of virtual machines, without the need for the host’s physical network interface. Instead, a virtual network interface, similar to a loopback interface, is created on the host, providing connectivity among virtual machines and the host.

  • Cloud networking. This can be used to connect a local VM to a subnet on a remote cloud service.

  • Generic networking. Rarely used modes which share the same generic network interface, by allowing the user to select a driver which can be included with Oracle VirtualBox or be distributed in an extension pack.

    The following submodes are available:

    • UDP Tunnel: Used to interconnect virtual machines running on different hosts directly, easily, and transparently, over an existing network infrastructure.
    • VDE (Virtual Distributed Ethernet) networking: Used to connect to a Virtual Distributed Ethernet switch on a Linux or a FreeBSD host. At the moment this option requires compilation of Oracle VirtualBox from sources, as the Oracle packages do not include it.

在这里插入图片描述

Port forward 为端口转发,意思就是如果宿主机想要访问虚拟机需要设置端口转发。虽然NAT模式下可以通过此种方式来实现宿主机对虚拟机的访问,但是,如果虚拟机上运行了多个API服务,那就需要设置多个端口转发,所以不太适用。

NAT模式下,VM可以访问Host,此时Host的IP为10.0.2.2,比如VM运行WEB服务器,Host运行数据库服务。

NAT网络对应的标识符为ifcfg-enp0s3

桥接网络或Host-only对应的标识符为ifcfg-enp0s8

一般情况下,我们使用NAT + Host-only组合,网卡1使用NAT访问外网,网卡2使用Host-only满足VM和Host之间的通讯,然后在Host-only可以设置使用DHCP动态分配IP还是使用固定的IP。

无论是桥接模式还是Host-only都可以设置固定IP,需要修改配置文件。

/etc/sysconfig/network-scripts/ifcfg-enp0s8

#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant. Do not modify.
NM_CONTROLLED=yes
BOOTPROTO=none
ONBOOT=yes
IPADDR=192.168.2.200
NETMASK=255.255.255.0
DEVICE=enp0s8
PEERDNS=no
#VAGRANT-END

http://www.ppmy.cn/ops/113938.html

相关文章

Kubernetes集群部署(kubernetes)

三台主机恢复到docker快照状态; 检查驱动器类型为sytemd; 设置各个节点的主机名; 然后同步会话,修改hosts文件; 在k8s运行过程中不建议使用交换分区; 关闭交换分区; 但是这种方法是临时性的&am…

go语言 结构体

结构体类型别名和自定义类型 自定义类型 类型别名结构体创建结构体实例访问结构体字段修改结构体字段嵌套结构体结构体方法结构体内存布局 空结构体 题 关于 range 循环的陷阱构造函数方法 和 接收者定义方法 什么时候应该使用指针类型接收者任意类型添加方法 结构体的匿名字段…

druid jdbc 执行 sql 输出 开销耗时

druid 执行sql输出 参考链接配置_LogFilter alibaba/druid Wiki GitHub 看不太懂的往这里瞅瞅。 1. 别名映射 这个地方 给我们提供了 5 种 logfilter : log4j、log4j2、slf4j、commonlogging和commonLogging 每一种实际上都代表一个日志框架 或 日志门面。 -Ddruid.fil…

【Linux】线程概念

一、再次认识进程地址空间 我们知道,进程地址空间有几个分区: 每一个进程在启动的时候,OS都会给其分配一个地址空间,这就是进程地址空间 以先描述再组织的思想,进程地址空间其实是操作系统内核的一个数据结构struct m…

1. stm32创建工程并下载

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 文章目录 前言一、stm32是什么?二、keli5创建工程1.创建空工程和文件夹2.创建其他文件夹,包含stm32启动和库文件 总结 前言 提示:这里可以…

Matlab simulink建模与仿真 第十七章(补充离散库和补充数学库)

参考视频:simulink1.1simulink简介_哔哩哔哩_bilibili 一、补充离散库和补充数学库中的模块概览 1、补充离散库 注:每个版本的补充离散库不一定相同,也不是每个版本的库都有如上所有模块。 2、补充数学库 二、离散直接传递函数Ⅱ模块 1、…

【SpringCloud】注册中心的其他实现 - Nacos

目录 注册中心的其他实现-NacosNacos简介Nacos安装下载安装包Windows解压修改单机模式启动Nacos常见问题 Linux准备安装包单机模式启动常见问题 Nacos快速上手服务注册/服务发现引入Spring Cloud Alibaba依赖引入Nacos 依赖引入Load Balance依赖 配置Nacos地址远程调用启动服务…

Gateway--服务网关

网关简介 大家都知道在微服务架构中,一个系统会被拆分为很多个微服务。那么作为客户端要如何去调用 这么多的微服务呢?如果没有网关的存在,我们只能在客户端记录每个微服务的地址,然后分别去调用。 这样的架构,会存在…