Cấu hình Host-Only Networking với VirtualBox

Cấu hình Host-Only Networking với VirtualBox

I’ve been playing around with VirtualBox lately, and it’s pretty nifty. Initially I just used it to set up an Ubuntu machine so I could easily run GnuCash on my MacBook, but lately I’ve decided to start using it at work, too. I’ve got lots of plans: figure out how to use Chef, set up my own Hudson server, get a MongoDB cluster running, etc. I’d like all of these machines to be able to access the internet for downloading packages and the like, and I also want to be able to access them easily from my host machine. I don’t want these servers to be accessible from anywhere else on the network, however; these are just for me to experiment with for the time being. After banging my head on this for a little while, I think I’ve finally hit upon a (the?) solution.

Just for completeness’ sake, my host is Mac OS X and my guests are all Ubuntu boxes, so any system-specific instructions here are going to have a UNIX orientation. You have been warned.

Step 1: Access the Internet from the Guest

Set up one of your guest machine’s networking adapters to NAT. This is really easy, since it’s the default.

This will allow the guest system to access the broader internet through your host’s connection. You’ll be able to download packages, check email; whatever. Nobody outside sees anything of your guest system; as far as they’re concerned, it doesn’t exist. However, you cannot access any guest resources from your host machine, nor can any guest machines access each other. Yet.

Step 2: Access the Guest from the Host (and Other Guests)

We’ll need to add another network adapter to your guest machine, but this time, it’ll be a Host-Only Adapter. By using this type of adapter, you’ll be able to access a private, virtual network consisting solely of your host and any guests. Any of the member machines can access each other, but nothing outside of this self-contained “network in a box” can get in.

VirtualBox can create several of these virtual host-only networks (it’s what the “Name” field refers to in the Network Adapter Setup screen above). You can configure these in the VirtualBox Preferences; there should be one already created for you called vboxnet0 network.

Click on the “Edit” button for your Host-only network; you’ll see a dialog like this:

Take note of the adapter’s IP address (192.168.56.1here); that’s the address at which your guests can access the host.

By default, there’s a DHCP server set up on the network. Since we’re going to be assigning static IP addresses, we don’t really need this, so you can uncheck the “Enable Server” box on the DHCP configuration panel.

Step 3: Configure Guests

We need each of the guests to have a static IP address on the host-only network. Log in to your Ubuntu guest and issue the following command:

ifconfig eth1 192.168.56.101 netmask 255.255.255.0 up

(Use whatever IP on your host-only network you like, of course.) This binds a network interface to one of the IP addresses on your host-only network (eth0 was bound to the NAT adapter). Now you should be able to SSH into your guest from your host (for example) using this IP address.

This is just temporary, however; once you reboot, this configuration will disappear. To make it permanent, add this to your /etc/network/interfacesfile (as root):

# The host-only network interface
auto eth1
iface eth1 inet static
address 192.168.56.101
netmask 255.255.255.0
network 192.168.56.0
broadcast 192.168.56.255

Reboot, and this interface should now show up when you type ifconfig.

Step 4: Make Networking Easier with /etc/hosts

Remembering IP addresses is a pain; we’d much rather use machine names. Fortunately, we don’t need to bother with a DNS server, since /etc/hostsmakes this trivial. Just edit the file (as root) adding lines like the following:

192.168.56.101    myserver1
192.168.56.102    myserver2

… and so on. You can do this on the host as well as on the guests. This makes it really simple to access any machine on the host-only network. Now you can just do something like ssh myserver1instead of ssh 192.168.56.101.

And that ought to do it.

Tags: 
Bạn thấy bài viết này như thế nào?: 
No votes yet
Ảnh của Khanh Hoang

Khanh Hoang - Kenn

Kenn is a user experience designer and front end developer who enjoys creating beautiful and usable web and mobile experiences.

Tìm kiếm bất động sản

 

Advertisement

 

jobsora

Dich vu khu trung tphcm

Dich vu diet chuot tphcm

Dich vu diet con trung

Quảng Cáo Bài Viết

 
MacBook Pro Retina 13 inch sẽ được phát hành trong tháng Chín

MacBook Pro Retina 13 inch sẽ được phát hành trong tháng Chín

Theo chuyên gia phân tích Ming-Chi Kuo của KGI Securities dự đoán, một phiên bản mới của MacBook Pro Retina với màn hình 13 inch sẽ được Apple giới thiệu ra thị trường vào tháng 9 tới đây.

Yu Pan là đồng sáng lập PayPal

12 khai quốc công thần của YouTube giờ đang làm gì?

Hiện tại, ông đã rời công ty và chuyển sang làm kỹ sư phần mềm cho Origin Protocol - doanh nghiệp được sáng lập bởi cựu nhân viên YouTube Matthew Liu

Cải thiện Performance và Scalability trong Drupal Site

Cải thiện Performance và Scalability trong Drupal Site

Here at Achieve Internet, we perform a lot of system reviews for our clients to help them improve the performance and scalability of their sites.  From these numerous system reviews, we've identified 5 common things that are missing from many hosting configurations.

Công ty diệt chuột T&C

 

Diet con trung