{"id":2606,"date":"2017-05-08T10:15:22","date_gmt":"2017-05-08T15:15:22","guid":{"rendered":"https:\/\/www.foell.org\/justin\/?p=2606"},"modified":"2019-10-21T11:50:54","modified_gmt":"2019-10-21T16:50:54","slug":"virtualbox-connect-to-ubuntu-host-served-website","status":"publish","type":"post","link":"https:\/\/www.foell.org\/justin\/virtualbox-connect-to-ubuntu-host-served-website\/","title":{"rendered":"VirtualBox: connect to Ubuntu host served website"},"content":{"rendered":"<p>I set up a new testing environment for IE11 through VirtualBox on my computer running Ubuntu. But I couldn&#8217;t get to any of my sites that are served by the Ubuntu host. I had to <a href=\"http:\/\/jakegoulding.com\/blog\/2014\/04\/26\/running-dnsmasq-on-os-x-and-routing-to-virtual-machines\/\" target=\"_blank\" rel=\"noopener noreferrer\">do some tricks to get this working on my old work Mac<\/a>, and the same principle applies for Ubuntu.<\/p>\n<p><!--more--><\/p>\n<p>On my Ubuntu system, I use <a href=\"https:\/\/www.foell.org\/justin\/tag\/dnsmasq\/\">Dnsmasq<\/a> for local DNS so I can test sites locally like <code>client1.test<\/code>, <code>client2.test<\/code>, etc. Normally those fake top-level domains resolve to a localhost IP: 127.0.0.1. But when you bring VirtualBox into the mix, the host and the guest both have their own notions of localhost. We need a common ground to communicate on. This is solved with a loopback alias.<\/p>\n<h2>Loopback Alias<\/h2>\n<p>A loopback alias is just another IP that you can assign to your localhost loopback device. To add one, add the following to your network interfaces configuration file:<\/p>\n<p><code>sudo vi \/etc\/network\/interfaces<\/code><\/p>\n<pre>\r\nauto lo:0\r\niface lo:0 inet static\r\n\taddress 10.254.254.254\r\n\tnetwork 10.0.0.0\r\n\tnetmask 255.255.255.255\r\n<\/pre>\n<p><code>sudo service networking restart<\/code><\/p>\n<h2>Dnsmasq<\/h2>\n<p>Now instead of having your fake TLDs resolve to 127.0.0.1, we need them to resolve to our loopback alias address &#8211; 10.254.254.254. Depending if you&#8217;re using Dnsmasq with or without NetworkManager, you can edit\/add the following file (respectively):<\/p>\n<p><code>sudo vi \/etc\/NetworkManager\/dnsmasq.d\/01_localhost<\/code><br \/>\nOR<br \/>\n<code>sudo vi \/etc\/dnsmasq.d\/01_localhost<\/code><\/p>\n<pre>\r\naddress=\/test\/10.254.254.254\r\n<\/pre>\n<p><code>sudo service network-manager restart<\/code><\/p>\n<h2>VirtualBox Networking<\/h2>\n<p>Lastly, we just need to tell our VirtualBox guest to use the DNS from our host system. These instructions work for both OSX and Linux hosts: <a href=\"https:\/\/serverfault.com\/questions\/453185\/vagrant-virtualbox-dns-10-0-2-3-not-working\/453260#453260\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/serverfault.com\/questions\/453185\/vagrant-virtualbox-dns-10-0-2-3-not-working\/453260<\/a><\/p>\n<p>I&#8217;m using the 2nd option to make the guest use the host&#8217;s DNS settings:<\/p>\n<p><code>VBoxManage modifyvm \"VM name\" --natdnshostresolver1 on<\/code><\/p>\n<p>Test everything out by starting your VM guest and pinging 10.254.254.254 for network connectivity. Then try to ping a <code>.test<\/code> domain from the guest. If it looks good you should be able to load a <code>.test<\/code> domain through Internet Explorer on the guest OS.<\/p>\n<div class='kindleWidget kindleLight' ><img decoding=\"async\" src=\"https:\/\/www.foell.org\/justin\/wp-content\/plugins\/send-to-kindle\/media\/white-15.png\" \/><span>Send to Kindle<\/span><\/div>","protected":false},"excerpt":{"rendered":"<p>I set up a new testing environment for IE11 through VirtualBox on my computer running Ubuntu. But I couldn&#8217;t get to any of my sites that are served by the Ubuntu host. I had to do some tricks to get this working on my old work Mac, and the same principle applies for Ubuntu. Send&hellip; <a href=\"https:\/\/www.foell.org\/justin\/virtualbox-connect-to-ubuntu-host-served-website\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"VirtualBox - connecting to Ubuntu host served website","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1,17,8,22],"tags":[116,23,166,152,151],"class_list":["post-2606","post","type-post","status-publish","format-standard","hentry","category-business","category-dns","category-ubuntu","category-wordpress","tag-apple","tag-dnsmasq","tag-linux","tag-mac","tag-osx"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.foell.org\/justin\/wp-json\/wp\/v2\/posts\/2606","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.foell.org\/justin\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.foell.org\/justin\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.foell.org\/justin\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.foell.org\/justin\/wp-json\/wp\/v2\/comments?post=2606"}],"version-history":[{"count":14,"href":"https:\/\/www.foell.org\/justin\/wp-json\/wp\/v2\/posts\/2606\/revisions"}],"predecessor-version":[{"id":3579,"href":"https:\/\/www.foell.org\/justin\/wp-json\/wp\/v2\/posts\/2606\/revisions\/3579"}],"wp:attachment":[{"href":"https:\/\/www.foell.org\/justin\/wp-json\/wp\/v2\/media?parent=2606"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.foell.org\/justin\/wp-json\/wp\/v2\/categories?post=2606"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.foell.org\/justin\/wp-json\/wp\/v2\/tags?post=2606"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}