VirtualBox: How to Use Host Interface Networkin in Linux

Source: Internet
Author: User

VirtualBox, I have always treated it as an alternative to VMWare and insisted on using it. It is gratifying to see that there are more and more excellent non-commercial software.
 
However, a problem with VirtualBox has plagued me for a long time, that is, communication between the host system and the guest system, that is, communication between the virtual network of the virtual host and the real network. VMWare has solved this problem well. For VMWare, any virtual network will not affect the access to the virtual host network. However, for VirtualBox, its default NAT mode has inherent limitations, including the inability to forward ICMP, and the inability to access virtual hosts from the real network. However, VirtualBox does provide two other types of virtual networks to solve this problem.
 
I rummaged out UserManual of VirtualBox from time to time and looked at it. Every time I saw virtual networking, I was very depressed because I couldn't understand it. I tried to configure the virtual network card as shown above, but all ended in failure.
 
Just yesterday, a CentOS 5.0 virtual system was installed. I thought I had to solve the problem of network interconnectivity. Otherwise, it would be too inconvenient.
 
A few hours ago, I tried again according to the method in the manual. As expected, I failed again.
 
Just now, I started dynamips and made a small experiment. I thought of the virtual network card used by dynamips. If I had any chance, I would be enlightened.
 
 
As a result, the following solution is roughly divided into several steps:
 
1) manually create a virtual network card
 
To facilitate the creation of virtual NICs, I wrote a script:
 
#! /Bin/sh
 
 
If [-z "$ EUID"-a-x/usr/bin/id]; then
EUID = 'id-U'
Fi
 
If ["$ EUID" = "0"]; then
 
# ----- Vbox0 -------------------------------------------------------------
/Sbin/ifconfig vbox0>/dev/null 2> & 1
If ["$? "=" 0 "]; then
Tunctl-d vbox0
Echo
Echo "*** vbox0 was removed! ***"
Echo
Exit 1
Else
Tunctl-u wandering-t vbox0
Ifconfig vbox0 172.16.0.1 netmask 255.255.255.0 up
Echo
Ifconfig vbox0
Echo
Echo "*** vbox0 was created with ip address of 172.16.0.1/24! ***"
Echo
Fi
 
Else
 
Echo
Echo "*** Permission denied, please run this as root! ***"
Echo
Exit 1
 
Fi
 
 
 
Before using this script, remember to replace wandering in "tunctl-u wandering-t vbox0" with the username to run VirtualBox on your system.
 
 
 
2) reference the virtual network card created in step 1 in the configuration file of the VirtualBox Virtual System
 
<A> open the setting interface of the VirtualBox Virtual System and go to "settings-> NetWork-> Adapter 2 ";
<B> select "Enable Network Adapter ";
<C> select the "Host interface" item in the "Attached to" drop-down box;
<D> enter "vbox0" in the "Interface Name" input box (this is the Name of the manually created virtual network card, depending on the actual creation );
<E> click "OK" to close the configuration;
 
 
 
3) configure the network for the new Nic In the started Virtual System
 
Take my installed CentOS 5.0 as an example:
 
# Ifconfig eth1 172.16.0.2 netmask 255.255.255.0 up
 
 
In the Host system, ping the IP address of the new Nic of the virtual system:
 
#
#
# Ping 172.16.0.2
PING 172.16.0.2 (172.16.0.2) 56 (84) bytes of data.
64 bytes from 172.16.0.2: icmp_seq = 1 ttl = 64 time = 0.209 MS
^ C
--- 172.16.0.2 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0 ms
Rtt min/avg/max/mdev = 0.209/0.209/0.209/0.000 MS
#
#
# Ssh-l root 172.16.0.2
The authenticity of host' 172. 16.0.2 (172.16.0.2) 'can't be established.
RSA key fingerprint is a9: 15: 3d: cf: f5: b1: 5c: 5f: 5d: 96: fb: a9: b0: 9d: 37: 61.
Are you sure you want to continue connecting (yes/no )? Yes
Warning: Permanently added '192. 16.0.2 '(RSA) to the list of known hosts.
Root@172.16.0.2's password:
Last login: Tue Oct 7 00:13:55 2008
[Root @ centos5 ~] #
[Root @ centos5 ~] # Exit
Logout
 
 
 
#
 
 
 
Note: openSUSE 11.0 x86_64 is used for my Desktop.
 
OK. Everything is done. You can communicate normally.
 
 
 
 
This article is from the "Wandering's Blog" Blog

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.