[WorksForMe] NAT not working

Discussions related to using VirtualBox on Linux hosts.
Post Reply
techiebiker
Posts: 20
Joined: 26. Dec 2007, 18:27
Location: connecticut

[WorksForMe] NAT not working

Post by techiebiker »

Can't connect to webserver on guest anymore. How to fix?

Ubuntu 16.04 guest server on 18.04 host Desktop.

The VM guest is set up with Apache for testing websites.

Has not been used for a while. Was working several months ago. Only difference is updates, not version upgrades, on both guest and host.

VM adapter is connected to host via NAT. NAT is port forwarding several ports. Firewall, ufw, is disabled on host and guest.

The NAT settings are:

Code: Select all

host:~$ VBoxManage showvminfo "TestDevLAMP"
...
NIC 1:                       MAC: ************, Attachment: NAT, Cable connected: on, Trace: off (file: none), Type: virtio, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none
NIC 1 Settings:  MTU: 0, Socket (send: 64, receive: 64), TCP Window (send:64, receive: 64)
NIC 1 Rule(0):   name = SSH, protocol = tcp, host ip = 127.0.0.1, host port = 2224, guest ip = , guest port = 22
NIC 1 Rule(1):   name = SSL, protocol = tcp, host ip = 127.0.0.1, host port = 4443, guest ip = , guest port = 443
NIC 1 Rule(2):   name = Web, protocol = tcp, host ip = 127.0.0.1, host port = 8800, guest ip = , guest port = 80
NIC 1 Rule(3):   name = Web8080, protocol = tcp, host ip = 127.0.0.1, host port = 8080, guest ip = , guest port = 8080
...
NOTE: "host ip" was empty and I changed it to 127.0.0.1 attempting to get web connections working. ssh works regardless whether "host ip" has a value.

The guest is accessible from the host over ssh with either of the following commands...

Code: Select all

host:~$ ssh -p 2224 localhost
host:~$ ssh -p 2224 127.0.0.1
The Apache server is NOT accessible from the host with any of the following commands...

Code: Select all

host:~$ links2 localhost:8800
host:~$ links2 127.0.0.1:8800
host:~$ links2 http://localhost:8800
host:~$ links2 http://127.0.0.1:8800
The Apache server IS running on the guest...

Code: Select all

guest:~$ sudo systemctl status apache2
[sudo] password for user: 
● apache2.service - LSB: Apache2 web server
   Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled)
...
   Active: active (running) since Tue 2019-10-29 14:40:39 EDT; 2h 52min ago
...
Oct 29 14:40:39 cms-vm systemd[1]: Started LSB: Apache2 web server.
The Apache server IS accessible on the guest with the following commands...

Code: Select all

guest:~$ links2 127.0.0.1
guest:~$ links2 http://127.0.0.1
guest:~$ links2 http://localhost
But it can't be accessed with...

Code: Select all

guest:~$ links2 localhost
On the guest, netstat doesn't show the Apache server listening on IPv4 port 80, even while links2 is connected by guest:~$ links2 127.0.0.1 in a separate terminal. IPv6 port 80 is shown as listening though...

Code: Select all

guest:~$ sudo netstat -l
[sudo] password for user: 
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 *:ssh                   *:*                     LISTEN     
tcp        0      0 localhost.localdoma:953 *:*                     LISTEN     
tcp        0      0 localhost.localdo:mysql *:*                     LISTEN     
tcp6       0      0 [::]:http               [::]:*                  LISTEN     
tcp6       0      0 [::]:domain             [::]:*                  LISTEN     
tcp6       0      0 [::]:ssh                [::]:*                  LISTEN     
tcp6       0      0 localhost:953           [::]:*                  LISTEN
Suggestions please.
Last edited by socratis on 9. Nov 2019, 01:34, edited 1 time in total.
Reason: Marked as [WorksForMe].
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: NAT not working

Post by scottgus1 »

Please zip and post the guest's .vbox file, from the guest's folder, using the forum's Upload Attachment tab.

Also try a new Ubuntu 16.04 guest, fresh install, set to NAT, and see if you have internet access in the guest and can configure to allow ping through NAT both ways. This will check if there's anything wrong with Virtualbox on the host.
techiebiker
Posts: 20
Joined: 26. Dec 2007, 18:27
Location: connecticut

Re: NAT not working

Post by techiebiker »

@scotgus1

.vbox file attached to thread.

Your request and suggestion gave me some ideas.

Looking through the .vbox file I noted a <NAT> section and a <NATNetwork name="CMS Test"/> section.

The <NAT> section reflected the info in the UI. So no surprise.

The <NATNetwork name="CMS Test"/> was a surprise because the vm is NOT connected to the NAT Network. The vm's NIC 1 is NAT'd as described in first post.

Took vm NIC 1 off NAT and connected instead to "NAT Network". Host web browsing of guest webserver now possible. Switch NIC 1 back to NAT and again host can't browse guest webserver.

Created new vm with no drive and set up NAT as on problem VM. Inspect new .vbox file and find <NAT> section as in other VM and this time no <NATNetwork...> section. Again as expected. Add hard drive to vm by copying problem vm's hd and attaching copy to new vm. Contents of .vbox file do not change with regard to <NAT> section and <NATNetwork...> section does not appear. Now host cannot connect to guest webserver or ssh. Guest cannot see or connect to any external resource.

Created new vm with empty drive, booted from CD, installed Ubuntu server 18.04 and Apache2. Set up NAT as on other attempts. Links2 on guest can access default Apache webpage on guest and can access other websites on my home network (a different subnet) and the Internet. Host can connect to guest with ssh but unable to connect to webserver.

As with other guest vms, disconnecting guest from NAT and connecting to NAT network provides host access to guest webserver.

Any suggestions to make guest webserver available via NAT?
Attachments
TestDevLAMP.vbox.zip
connections to vm's webserver fail
(2.93 KiB) Downloaded 12 times
socratis
Site Moderator
Posts: 27330
Joined: 22. Oct 2010, 11:03
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Win(*>98), Linux*, OSX>10.5
Location: Greece

Re: NAT not working

Post by socratis »

First of all, please read the read the following: User Manual, ch. 6.2. Introduction to networking modes including the Overview table, which shows quickly what kind of connection is required to achieve what you want. And remember, you can always have more than one network card in your guest to cover multiple scenarios.

Which you do. You have NIC1 attached to NAT (with port-forwarding rules in the "<VM>.vbox" that you attached), and NIC2 attached to NATnetwork "CMS Test", with rules that cannot be seen from the "<VM>.vbox" file but only from the "/Users/<you>/.config/VirtualBox/VirtualBox.xml" file. Could you ZIP and attach that as well?

And please can you summarize in one sentence what is your end goal? "NAT not working" is not...
Do NOT send me Personal Messages (PMs) for troubleshooting, they are simply deleted.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
techiebiker
Posts: 20
Joined: 26. Dec 2007, 18:27
Location: connecticut

Re: NAT not working

Post by techiebiker »

Thought I had already replied... sorry for the extended silence.

End goal: vm Apache server to test virtual hosting using Apache <VirtualHost> directives to distinguish websites by port. e.g. host browse to http://localohost:8800 gets to website A on vm, browse to http://localhost:8801 gets to website B on vm, etc.

Had already read 6.2 Introduction to networking modes, more than once. The overview table's VM←Host column at the NAT row shows that the config I'm experimenting with is a supported config, imho.

The file you asked for, VirtualBox.xml, isn't available. I deleted the vms and started over. And still had the same problems in each of the browsers I tried, Firefox, Chrome, Chromium.

The solution seems to be that some plug-in in each browser is causing the problem.

In desperation I created a new Firefox profile and launched it in a browser. Now, host can surf guest webserver. Haven't figured out what add-on might have been blocking and for now not interested in pursuing.

Problem solved. It was some browser add-in.
socratis
Site Moderator
Posts: 27330
Joined: 22. Oct 2010, 11:03
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Win(*>98), Linux*, OSX>10.5
Location: Greece

Re: NAT not working

Post by socratis »

techiebiker wrote:Problem solved. It was some browser add-in.
Thank you for the feedback and the solution, hope someone finds it useful in the future. Marking as [WorksForMe].
Do NOT send me Personal Messages (PMs) for troubleshooting, they are simply deleted.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
Post Reply