Vbox Networking Settings

更新時間: 2024-07-05

目錄

  • 為 VM 加 Lan Card
  • 連接(是否有插線)
  • 連接方式(bridged, nat, host, intranet)
  • 限速
  • dhcpservers
  • natnetwork
    NAT vs NAT Network
  • ssh guest

 


為 VM 加 Lan Card

vboxmanage modifyvm  <VM_NAME>  --nic<1-N> <none|null|nat|bridged|intnet|hostonly|generic>

Default Type: 82540EM  <--- intel pro e1000

連接(是否有插線)

vboxmanage modifyvm  <VM_NAME>  --cableconnected<1-N> on|off

Example:

vboxmanage modifyvm winxp-sp3 --nic1 bridged --cableconnected1 on

連接方式

1) 把 vm bridge 到 host 的 Lan Card 上(尤如插線落 Router)

vbox modifyvm <VM>  --nic<1-N>  bridged

vbox modifyvm <VM> --bridgeadapter<1-N> <devicename>

2) NAT

--natpf<1-N> [<name>],tcp|udp,[<hostip>],<hostport>,[<guestip>], <guestport>

--natpf<1-N> delete <name>:

3) 尤如用 crossover cable 與主機連接

--intnet<1-N> network

4) 建立一個獨立的 Lan Segment

vbox modifyvm <VM>  --nic? intnet

vbox  modifyvm <VM>  --intnet?  <network name>

限速

# 限制速度為 5 Mbps

vboxmanage modifyvm winxp-sp3 --nicspeed1 5000

 


dhcpservers

 

# vbox Ver. 7

* 此 dhcp server 與 "virtual NAT engine" 的 dhcp 各不相干

CLI

VBoxManage.exe list dhcpservers

NetworkName:    HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter
Dhcpd IP:       192.168.56.100
LowerIPAddress: 192.168.56.101
UpperIPAddress: 192.168.56.254
NetworkMask:    255.255.255.0
Enabled:        Yes
Global Configuration:
    minLeaseTime:     default
    defaultLeaseTime: default
    maxLeaseTime:     default
    Forced options:   None
    Suppressed opts.: None
        1/legacy: 255.255.255.0
Groups:               None
Individual Configs:   None

 


natnetwork

 

# vbox Ver. 7

CLI

VBoxManage natnetwork list

Name:         NatNetwork
Enabled:      Yes
Network:      10.0.2.0/24
Gateway:      10.0.2.1
DHCP Server:  Yes
IPv6:         No
IPv6 Prefix:
IPv6 Default: No
loopback mappings (ipv4)
        127.0.0.1=2

1 network found

NAT vs NAT Network

NAT

* default
* no VM1↔VM2

NAT Network

A NAT service is attached to an internal network.
Virtual machines which are to make use of it should be attached to that internal network.
The name of internal network is chosen when the NAT service is created and
the internal network will be created if it does not already exist.

 


ssh guest

 

方案

  1. Add a second adapter set to host-only
  2. use port forwarding in NAT

[1] host-only adapter

...

[2] port forwarding

GUI

In VirtualBox > VM's Network panel
 > click on advanced
 > click on "Port Forwarding" button

Name: guestssh
Host IP: 127.0.0.1
Host Port: 2201
Guest IP: 10.0.2.15    # 可省
Guest Port: 22

CLI

VBoxManage modifyvm "VM name" --natpf1 "guestssh,tcp,127.0.0.1,2201,,22"