Introduction to the bridge mode of Virtualbox network card (transfer)

 

The default network card mode of Virtualbox client is NAT mode. NAT mode allows clients to access the Internet, which is sufficient for general users. But if you want to allow the client and the host to access each other, such as SSH login, mutual access to the web server, and other devices in the local area network can also access the client, then you need to select the bridge mode for the network card in the Virtualbox settings.

Change the network card mode to bridge mode

When the client is closed, open the setting window of the virtual machine. Click the Network tab in the left column .

virtualbox bridge mode

By default, Virtualbox only enables the first virtual network card for the client, and other network cards are disabled. The default mode of NIC 1 is NAT mode. To change the network card mode to bridged mode, just click NAT, and then select Bridged Adapter in the list . Finally, save the settings, which is very simple.

IP address of the client in bridge mode

Now, start the client. My host is ubuntu, and my client is openSUSE. After entering the client system, open a terminal and enter the ifconfig command to find the IP address of the client. As you can see, the IP address of my openSUSE client is 192.168.1.102 .

IP address of the client in bridge mode

Then open a terminal on the host computer and enter the ifconfig command to view the host computer's IP address. As you can see, the IP address of my ubuntu host is 192.168.1.101 .

IP address of the host

192.168.1.101 and 192.168.1.102 are in the same network segment (192.168.1.0/24). So I can ping the client from the host. The host and client are in the same network segment in bridge modeI can also ping the host from the client.

Same network segment

In the bridge mode, the IP of the Virtualbox client is assigned by the router in the local LAN (if your host computer uses a router to access the Internet). This means that the default gateway of the client in bridge mode is the router of the local network. You can open a terminal in the client and enter the following command to view the IP address of the default gateway.

ip route show

Selection_699

In the first line of the output, the IP address behind the default via is the IP address of the default gateway. You will find that this IP address is the address of the router.

Access the web server of the host in the client

I installed the nginx website server on the ubuntu host , and I can access the nginx website of the ubuntu host in the openSUSE client. Just enter the host's IP address in the client browser.

Access the web server of the host in the client

You can also install an Nginx web server in the client , and then access the client's Nginx website in the host.

Other devices in the local area network can also access the client

My android phone is connected to my local area network, so I can also access the nginx website in the client on the android phone. Just enter the client's IP in the mobile browser.

Other devices in the local area network can also access the client

The client can log in to the host through SSH, and the host can also log in to the client through SSH. Clients can also access the Internet.

In short, in the bridge mode, the virtualbox client is exposed to the local area network. From the other devices in the LAN, the client is a physical device in the LAN. In NAT mode, the Virtualbox virtual machine is protected by a virtual router and cannot directly communicate with the host machine and other devices. In NAT mode, the host and other devices must set up port forwarding to access the client. Whether in NAT mode or bridge mode, clients can access the Internet.

 

https://www.linuxdashen.com/virtualbox%E7%BD%91%E5%8D%A1%E7%9A%84%E6%A1%A5%E6%8E%A5%E6%A8%A1%E5%BC%8F%E4%BB%8B%E7%BB%8D

 

Guess you like

Origin blog.csdn.net/wxb880114/article/details/109235381