I'm trying to connect my guest that runs Ubuntu server 16.04 with internet so apt-get update etc. will work and I also want to see from my host my sites that are served from Apache in the guest. My host is Ubuntu Mate 16.04: cent@cent:~/ubs$ ifconfig -a eno1 Link encap:Ethernet HWaddr 5c:26:0a:5f:f9:f0 inet addr:192.168.1.1 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::834e:38d7:f70a:5e51/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:139303 errors:0 dropped:0 overruns:0 frame:0 TX packets:149901 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:95319338 (95.3 MB) TX bytes:32833668 (32.8 MB) Interrupt:20 Memory:e2e00000-e2e20000 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:9832 errors:0 dropped:0 overruns:0 frame:0 TX packets:9832 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1 RX bytes:1682145 (1.6 MB) TX bytes:1682145 (1.6 MB) vboxnet0 Link encap:Ethernet HWaddr 0a:00:27:00:00:00 inet addr:192.168.56.1 Bcast:192.168.56.255 Mask:255.255.255.0 inet6 addr: fe80::800:27ff:fe00:0/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:132 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:32438 (32.4 KB) wlp2s0 Link encap:Ethernet HWaddr a0:88:b4:4d:e5:14 BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) My guest: magellan@g3site001:~$ ifconfig -a enp0s3 Link encap:Ethernet HWaddr 08:00:27:4b:16:87 inet addr:192.168.56.101 Bcast:192.168.56.255 Mask:255.255.255.0 inet6 addr: fe80::a00:27ff:fe4b:1687/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:1888 errors:0 dropped:0 overruns:0 frame:0 TX packets:2034 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:136983 (136.9 KB) TX bytes:277181 (277.1 KB) enp0s9 Link encap:Ethernet HWaddr 08:00:27:a7:9f:32 inet6 addr: fe80::a00:27ff:fea7:9f32/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:8 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:648 (648.0 B) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:250 errors:0 dropped:0 overruns:0 frame:0 TX packets:250 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1 RX bytes:20152 (20.1 KB) TX bytes:20152 (20.1 KB) The configuration of my virtual box related with the guest server: cent@cent:~/ubs$ VBoxManage showvminfo "Ubuntu Server 64bits 16.04.1 LTS" --details Name: Ubuntu Server 64bits 16.04.1 LTS Groups: / Guest OS: Ubuntu (64-bit) UUID: a86595aa-b95f-422d-9d82-3f65a1d51bf8 Config file: /home/cent/VirtualBox VMs/Ubuntu Server 64bits 16.04.1 LTS/Ubuntu Server 64bits 16.04.1 LTS.vbox Snapshot folder: /home/cent/VirtualBox VMs/Ubuntu Server 64bits 16.04.1 LTS/Snapshots Log folder: /home/cent/VirtualBox VMs/Ubuntu Server 64bits 16.04.1 LTS/Logs Hardware UUID: a86595aa-b95f-422d-9d82-3f65a1d51bf8 Memory size: 1024MB Page Fusion: off VRAM size: 16MB CPU exec cap: 100% ...................... Storage Controller Bootable (1): on IDE (1, 0): /usr/share/virtualbox/VBoxGuestAdditions.iso (UUID: 288888b9-33a4-493d-8582-dcaa4a335f71) SATA (0, 0): /home/cent/VirtualBox VMs/Ubuntu Server 64bits 16.04.1 LTS/Snapshots/{0c796e39-9a2e-410b-be73-6694226d019b}.vdi (UUID: 0c796e39-9a2e-410b-be73-6694226d019b) NIC 1: MAC: 0800274B1687, Attachment: Host-only Interface 'vboxnet0', Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none NIC 2: disabled NIC 3: MAC: 080027A79F32, Attachment: NAT Network 'NatNetwork', Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: allow-all, Bandwidth group: none NIC 4: disabled NIC 5: disabled NIC 6: disabled NIC 7: disabled NIC 8: disabled Pointing Device: USB Tablet ..................... Shared folders: Name: 'shared', Host path: '/home/cent/VirtualBox VMs/Ubuntu Server 64bits 16.04.1 LTS/shared' (machine mapping), writable ....................... Description: Host: gesite001 User: magellan Pass: Installed Packages ---------------------------- DNS server OpenSSH server Guest: Configured memory balloon size: 0 MB OS type: Linux26_64 Additions run level: 2 Additions version: 5.1.2 r108956 Guest Facilities: Facility "VirtualBox Base Driver": active/running (last update: 2016/11/07 09:07:42 UTC) Facility "VirtualBox System Service": active/running (last update: 2016/11/07 09:07:58 UTC) Facility "Seamless Mode": not active (last update: 2016/11/07 09:07:42 UTC) Facility "Graphics Mode": not active (last update: 2016/11/07 09:07:42 UTC) Snapshots: Name: Snapshot 1 (UUID: ef398313-16ae-43cd-8cf2-5712523f066e) * Now, I followed this to set a static ip for my guest Host-Only interface vboxnet0 that uses 192.168.56.1 as it can be seen from the outputs above. magellan@g3site001:~$ sudo cat /etc/network/interfaces [sudo] password for magellan: # This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). source /etc/network/interfaces.d/* # The loopback network interface auto lo iface lo inet loopback # The primary network interface auto enp0s3 #iface enp0s3 inet dhcp iface enp0s3 inet static address 192.168.56.101 netmask 255.255.255.0 gateway 192.168.56.1 dns-nameservers 8.8.8.8 Then, I tried to follow an outdated tutorial there and insert rules in my iptables: # fix for vbox iptables -A FORWARD -o eno1 -i vboxnet0 -s 192.168.56.0/24 -m conntrack --ctstate NEW -j ACCEPT iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT iptables -A POSTROUTING -t nat -j MASQUERADE install dnsmasq and replaced step 3 with a new entry in /etc/network/interfaces: magellan@g3site001:~$ sudo cat /etc/network/interfaces # This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). source /etc/network/interfaces.d/* # The loopback network interface auto lo iface lo inet loopback # The primary network interface auto enp0s3 #iface enp0s3 inet dhcp iface enp0s3 inet static address 192.168.56.101 netmask 255.255.255.0 gateway 192.168.56.1 dns-nameservers 8.8.8.8 dns-nameservers 192.168.1.1 After a restart still can't connect my guest to internet...... What is the proper way to handle such a situation?
In the VBox settings, select bridged networking. Then it should automagically work and your VM get an own IP in your lan.
I've tested this but with no result. The strange thing is that a clone I made after first install is connected to internet! That clone has address 10.0.2.15 at nic enp0s3
I'm going to write the exact steps that worked for me: A. Enabling connection with the internet 1. At guest Settings -> Adapter 1 -> enable NAT Network (NatNetwork) 2. Don't touch guest's file '/etc/network/interfaces': magellan@g3site001:~$ sudo cat /etc/network/interfaces # This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). source /etc/network/interfaces.d/* # The loopback network interface auto lo iface lo inet loopback # The primary network interface #auto enp0s3 iface enp0s3 inet dhcp B. Enabling ssh from host 1. At guest Settings -> Adapter 2 -> enable Host-only Adapter (vboxnet0) 2. At vbox window File -> Preferences -> Network -> NatNetwork -> Edit: check DHCP and Port Forwarding with rule 1: Host Port 2222 Guest IP 10.0.2.15 (copy IP from B.5) Guest Port 22 We edit 2 networks here! 3. Restart guest. 4. Inspect in guest: 'ifconfig' 5. If only 'lo' then 'ifconfig -a' magellan@g3site001:~$ ifconfig -aenp0s3 Link encap:Ethernet HWaddr 08:00:27:4b:16:87 inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0 inet6 addr: fe80::a00:27ff:fe4b:1687/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:375 errors:0 dropped:0 overruns:0 frame:0 TX packets:544 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:43822 (43.8 KB) TX bytes:539625 (539.6 KB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:18 errors:0 dropped:0 overruns:0 frame:0 TX packets:18 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1 RX bytes:1621 (1.6 KB) TX bytes:1621 (1.6 KB) Enable: 'sudo ifup enp0s3' and use address 10.0.2.15 in step 2. C. Connect to guest from host 1. Inspect from host Host-only Adapter (vboxnet0 from B.1) with: cent@cent:~$sudo nmcli device show vboxnet0 GENERAL.DEVICE: vboxnet0 GENERAL.TYPE: ethernet GENERAL.HWADDR: 0A:00:27:00:00:00 GENERAL.MTU: 1500 GENERAL.STATE: 10 (unmanaged) GENERAL.CONNECTION: -- GENERAL.CON-PATH: -- WIRED-PROPERTIES.CARRIER: on IP4.ADDRESS[1]: 192.168.56.1/24 IP4.GATEWAY: IP6.ADDRESS[1]: fe80::800:27ff:fe00:0/64 IP6.GATEWAY:Keep address IP4: 92.168.56.1 2. Type in host: 'cent@cent:~$ ssh -p 2222 [email protected]' with address from previous step. D. Inspect default Apache's page in guest from host 1. At vbox window File -> Preferences -> Network -> NatNetwork -> Port Forwarding add another rule 2: Host Port 8888 Guest IP 10.0.2.15 (copy IP from B.5) Guest Port 80 2. Restart guest. 3. Login in guest and edit apache default page '/var/www/html/index.html': replace ' <title>Apache2 Ubuntu Default Page: It works</title>' with '<title>Apache2 Ubuntu Default Page: It works from GUEST</title>' and <div class="section_header section_header_red"> <div id="about"></div> It works! </div> with <div class="section_header section_header_red"> <div id="about"></div> It works from GUEST! </div> 4. Restart apache in guest 'sudo apache2ctl restart'. 5. Open browser in host and type: 'http://192.168.56.1:8888/' and you should see your guest's default page. Address is from step C.1 and port from rule 2 in D.1. E. Inspect apache's virtual hosts in guest from host 1. At vbox window File -> Preferences -> Network -> NatNetwork -> Port Forwarding add another rule 3: Host Port 8000 Guest IP 10.0.2.15 (copy IP from B.5) Guest Port 8000 and rule 4: Host Port 8001 Guest IP 10.0.2.15 (copy IP from C.2) Guest Port 8001 for two virtual hosts. 2. Restart guest. 3. Edit in host file '/etc/hosts': cent@cent:~$ sudo cat /etc/hosts 127.0.0.1 localhost 192.168.56.1:8000 suexec-test suexec-test 192.168.56.1:8001 test_f1HaK4Kp test_f1HaK4Kp 127.0.1.1 cent cent 192.168.56.1 g3site001 g3site0014. edit in guest virtual hosts based on ports from rules in E.1 and on ip from B.5 magellan@g3site001:~$ sudo nano /etc/apache2/sites-enabled/suexec-test.conf #NameVirtualHost *:80 Listen 8000 <VirtualHost 10.0.2.15:8000> ServerName suexec-test ServerAlias suexec-test ServerAdmin [email protected] ......................and agellan@g3site001:~$ sudo nano /etc/apache2/sites-enabled/test_f1HaK4Kp.conf #NameVirtualHost *:80 Listen 8001 <VirtualHost 10.0.2.15:8001> ServerName test_f1HaK4Kp ServerAlias test_f1HaK4Kp ServerAdmin test_f1HaK4Kp@test_f1HaK4Kp.com .......................5. restart apache `sudo apache2ctl restart' 6. Open browser in host and type: 'http://192.168.56.1:8001/test_f1hak4kp/index.php' or 'http://192.168.56.1:8000/suexec-test/index.php'. That should do for testing of a couple of sites. Again IP is from step C.1 and ports from rules 3 and 4 in E.1.