Port forwarding not working on a NAT network interface with static IP (Ubuntu)

Discussions about using Linux guests in VirtualBox.
Post Reply
Jdupont
Posts: 5
Joined: 8. Apr 2022, 20:58

Port forwarding not working on a NAT network interface with static IP (Ubuntu)

Post by Jdupont »

Good afternoon.
I hope you're doing great wherever you are.
I been struggling with the following issue for the whole day and I'm starting to bang my head again the wall.

Here is my setup :

[*]Host : Windows 10 + VirtualBox 6.
  1. -> VirtualBox Host network manager : 192.168.88.1 / 255.255.255.0 no DHCP
  2. -> Network adapter 1 (internet) : Automatic
  3. -> -> Network adapter 2 (for Jetson network) : 192.168.88.13 / 255.255.255.0

[*]VM : Ubuntu 18.04 LTS[/list]
  1. - > Adapter 1 NAT => (enp0s3) set to static IP ( cf. yaml file) -> 192.168.88.40/24
  2. -> Adapter 2 Bridged (for internet connectivity) => (enp0s8) default settings
[*]Nvidia Jetson : Ubuntu 18.04 LTS
  1. -> VirtualBox Host network manager : 192.168.88.1 / 255.255.255.0 no DHCP
  2. -> Network adapter 1 (internet) : Automatic
  3. -> -> Network adapter 2 (for Jetson network) : 192.168.88.13 / 255.255.255.0
[*]VM : Ubuntu 18.04 LTS
  1. -> IP (Static) : 192.168.88.1 / 255.255.255.0
In the current context I have to code both on a Jetson computer and on a VM of the Jetson.
In principle the VM is supposed to run the same code as the physical hardware (I’m not trying to emulate the arm64 Jetson architecture for now, just the OS is the same).
Thus their IPs are the same and set to static.

As I cannot expose the VM static with a Bridge or Host-Only adapter, as the IP will be conflicting (192.168.88.40).
I went for a NAT adapter on the VM with a port forwarding policy to hide the VM static IP (cf rule above) for the VM host.

Code: Select all

Port Forwarding rule : 
| _Name_ | _Protocol_ | _Host IP_     | _Host Port_ | _Guest IP_    | _Guest Port_ |
|--------|------------|---------------|-------------|---------------|--------------|
| SSH    | TCP        | 192.168.88.1  | 9099        |               | 22           |

Code: Select all

ssh -l vbuntu 192.168.88.1 -p 9099
If I ssh into the VM, without the enp0s3 interface set to a static IP. I’m able to get in.
And as expected, the associated ip is not visible from the outside (ex: via ping), which is great news for my usecase.


But if enp0s3 is set to a static IP, I cannot log-in anymore with the exact same forwarding rule.
I’ve tried with various *Host IP* (void, 127.0.0.1,192.168.88.1) and various Guest IP (void, 192.168.88.40, 127.0.0.1 ) nothing worked and this drive me crazy.

I’m kinda newby regarding virtualisation and some help would be greatly appreciated here.
Do you know a way to solve this issue?

All the best

JDupont

Code: Select all

——— Yaml Configuration : /etc/netplan/01-netcfg.yaml (some indentations might have been lost)——— 

# Yaml netplan config files
network:
    version: 2
    ethernets:
        enp0s3:
            dhcp4: no
            addresses: [192.168.88.40/24]
            gateway4: 192.168.88.1
			
——— ifconfig ———

Code: Select all

enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.88.40  netmask 255.255.255.0  broadcast 192.168.88.255
        inet6 fe80::a00:27ff:feb0:20fb  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:b0:20:fb  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 130  bytes 11085 (11.0 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.255.43.65  netmask 255.255.255.0  broadcast 10.255.43.255
        inet6 fe80::7112:afa8:f57f:3ef  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:41:d8:3e  txqueuelen 1000  (Ethernet)
        RX packets 105  bytes 12741 (12.7 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 40  bytes 6295 (6.2 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 262  bytes 22620 (22.6 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 262  bytes 22620 (22.6 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
[/code]
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Port forwarding not working on a NAT network interface with static IP (Ubuntu)

Post by scottgus1 »

Jdupont wrote:In the current context I have to code both on a Jetson computer and on a VM of the Jetson.
If I understand correctly you're trying to duplicate the Jetson's ARM environment inside the Virtualbox VM. I'll surmise that means you've transferred the runtime data from the Jetson to the VM, since Virtualbox can't run ARM code, only x86 OSs.
Jdupont wrote:VirtualBox Host network manager
Is this the Host-Only network?

****************
Jdupont wrote:Network adapter 2 (for Jetson network)
Is this a connection to the physical Jetson device?

****************
Jdupont wrote:Nvidia Jetson : Ubuntu 18.04 LTS
Are you running Ubuntu on the physical Jetson device?

****************
Jdupont wrote:VM : Ubuntu 18.04 LTS[/list]
- > Adapter 1 NAT => (enp0s3) set to static IP ( cf. yaml file) -> 192.168.88.40/24
-> Adapter 2 Bridged (for internet connectivity) => (enp0s8) default settings
...
[*]VM : Ubuntu 18.04 LTS
-> IP (Static) : 192.168.88.1 / 255.255.255.0
Are you running two Ubuntu VMs? If so, what network type is the second VM?

****************
Jdupont wrote:Nvidia Jetson : Ubuntu 18.04 LTS
-> VirtualBox Host network manager
Are you running Virtualbox on the Jetson also?

****************


I see what might be some possible configuration issues:
Jdupont wrote:Host : Windows 10 + VirtualBox 6.
-> VirtualBox Host network manager : 192.168.88.1
...
Nvidia Jetson : Ubuntu 18.04 LTS
-> VirtualBox Host network manager : 192.168.88.1
...
[*]VM : Ubuntu 18.04 LTS
-> IP (Static) : 192.168.88.1
It looks like you have the same IP address on at least 3 devices in the network, which will really cause problems.
Jdupont wrote:VM : Ubuntu 18.04 LTS[/list]
- > Adapter 1 NAT => (enp0s3) set to static IP ( cf. yaml file) -> 192.168.88.40/24
-> Adapter 2 Bridged (for internet connectivity) => (enp0s8) default settings
NAT also allows internet. NAT by default only listens to 10.0.2.#/24, (though Virtualbox NAT can have its IP range changed, but changing the range to the other side's IP range can cause issues) so manually changing the adapter's IP address might break the connection.

I am not sure how your setup is set up. Can you please clarify, maybe draw a picture? (post it with the forum's Upload Attachment tab).
Jdupont
Posts: 5
Joined: 8. Apr 2022, 20:58

Re: Port forwarding not working on a NAT network interface with static IP (Ubuntu)

Post by Jdupont »

Good afternoon scottgus1,
Thanks for your reply,
I'm sorry for this late answer I did not got any email notification.
In the current context I have to code both on a Jetson computer and on a VM of the Jetson.
As mentioned in my previous message. The Jestson is running an ARM64 version of Ubuntu 18.04 LTS, but the VM is on Ubuntu 18.04 LTS x86_64. For now the code (ROS Code) is architecture agnostic and run both on x64 and ARM architecture. The only requirements the code have is to have a static ip that should be the same between both system (the VM and the physical device -> jetson).

In some configuration I need to have both the VM and the Jetson connected to the computer at the same time and obviously there will be an IP clash. In order to solve this issue I went for a NAT network adapter (to whom the ip is set to static) with the idea of doing port forwarding to ssh into it (cf previous message, here https://linuxhint.com/configure-port-fo ... irtualbox/).

Schematic in attachment and here : https://ibb.co/fCYnd5J
In the schematic the Virtualbox network adapter (VirtualBox Host network manager) is the Host-Only network.

My previous message add some typo :
* There is only one VM (the second one in my previous message was a typo).
* Virtualbox is not supposed to run on the jetson as the code developed on the VM, is just expected to be pushed to the Jetson OS.
* 192.168.88.1 is just the IP of VirtualBox Host network manager

My issue mainly rely on port forwarding with NAT, when the IP linked to the NAT adapter is set to static.


Best
Attachments
Diagram Jetson and VM
Diagram Jetson and VM
Diagram-Jetson-VM.png (97 KiB) Viewed 3545 times
Last edited by Jdupont on 14. Apr 2022, 14:19, edited 1 time in total.
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Port forwarding not working on a NAT network interface with static IP (Ubuntu)

Post by scottgus1 »

Thanks for the further information!
Jdupont wrote:Schematic : https://ibb.co/fCYnd5J
scottgus1 wrote:maybe draw a picture? (post it with the forum's Upload Attachment tab).
:wink: We want the picture on the forum so future readers of this topic will know what is being talked about, in case the link goes stale. Please comply.
Jdupont wrote:I went for a NAT network adapter (to whom the ip is set to static)
Please post the VM's .vbox file, so we can see the VM's settings:
Right-click the VM in the main Virtualbox window's VM list, choose Show in Explorer/Finder/File Manager. Zip the VM's .vbox file (not the .vbox-prev file), and post the zip file, using the forum's Upload Attachment tab. (Configure your host OS to show all extensions if the folder that opens does not show a .vbox file.)

Also, please post the output of these commands:

cd "C:\Program Files\Oracle\Virtualbox"
vboxmanage list hostonlyifs
vboxmanage list bridgedifs
vboxmanage list natnets
Jdupont
Posts: 5
Joined: 8. Apr 2022, 20:58

Re: Port forwarding not working on a NAT network interface with static IP (Ubuntu)

Post by Jdupont »

Good afternoon scottgus1,
Thanks for your answer.

I've added the .vbox file in attachment, and schematic on the previous message.
Regarding the command, here there are :

Code: Select all

C:\Program Files\Oracle\VirtualBox>vboxmanage list hostonlyifs
Name:            VirtualBox Host-Only Ethernet Adapter
GUID:            57baf9c5-808c-4600-bcd3-95f6bdd45593
DHCP:            Disabled
IPAddress:       192.168.88.1
NetworkMask:     255.255.255.0
IPV6Address:     fe80::2c7c:4325:b5c9:7c5d
IPV6NetworkMaskPrefixLength: 64
HardwareAddress: 0a:00:27:00:00:10
MediumType:      Ethernet
Wireless:        No
Status:          Up
VBoxNetworkName: HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter


C:\Program Files\Oracle\VirtualBox>vboxmanage list bridgedifs
Name:            Realtek PCIe GbE Family Controller #2
GUID:            2367b3b2-3847-426b-a9ad-ca5b3177d409
DHCP:            Enabled
IPAddress:       10.255.43.56
NetworkMask:     255.255.255.0
IPV6Address:     fe80::80b3:1683:b51b:51c6
IPV6NetworkMaskPrefixLength: 64
HardwareAddress: 00:13:3b:5a:5f:37
MediumType:      Ethernet
Wireless:        No
Status:          Up
VBoxNetworkName: HostInterfaceNetworking-Realtek PCIe GbE Family Controller #2

Name:            Realtek PCIe GbE Family Controller #3
GUID:            874a3630-568f-4a79-ad85-601d5d428452
DHCP:            Disabled
IPAddress:       10.24.8.13
NetworkMask:     255.255.255.0
IPV6Address:     fe80::69e0:81aa:11bd:32f9
IPV6NetworkMaskPrefixLength: 64
HardwareAddress: 00:13:3b:5a:5f:38
MediumType:      Ethernet
Wireless:        No
Status:          Up
VBoxNetworkName: HostInterfaceNetworking-Realtek PCIe GbE Family Controller #3

Name:            Realtek PCIe GbE Family Controller
GUID:            af980996-105a-4706-9952-b0fee5a6051b
DHCP:            Enabled
IPAddress:       169.254.246.184
NetworkMask:     255.255.0.0
IPV6Address:     fe80::3c20:305e:d8f8:f6b8
IPV6NetworkMaskPrefixLength: 64
HardwareAddress: a8:5e:45:12:13:5c
MediumType:      Ethernet
Wireless:        No
Status:          Down
VBoxNetworkName: HostInterfaceNetworking-Realtek PCIe GbE Family Controller


C:\Program Files\Oracle\VirtualBox>vboxmanage list natnets
As I ran those command I realized that my 'Realtek PCIe GbE Family Controller #3' (Ethernet adapter Ethernet 2 Jetson) seems to have two IP's registered (cf below "ipconfig"on my host machine).
The IP here is set to static (192.168.88.13) but appear with "vboxmanage list bridgedifs" as 10.24.8.13.
I've no idea what's going on there.

Code: Select all

C:\Users\jdupont>ipconfig

Windows IP Configuration


Ethernet adapter Eth_MotherBoard:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . : myCompany.local

Ethernet adapter Ethernet:

   Connection-specific DNS Suffix  . : myCompany.local
   Link-local IPv6 Address . . . . . : fe80::80b3:1683:b51b:51c6%4
   IPv4 Address. . . . . . . . . . . : 10.255.43.56
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 10.255.43.254

Ethernet adapter Ethernet 2 Jetson:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::69e0:81aa:11bd:32f9%11
   IPv4 Address. . . . . . . . . . . : 10.24.8.13
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   IPv4 Address. . . . . . . . . . . : 192.168.88.13
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . :

Ethernet adapter VirtualBox Host-Only Network:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::2c7c:4325:b5c9:7c5d%16
   IPv4 Address. . . . . . . . . . . : 192.168.88.1
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . :
Thanks :-)
Attachments
Ubuntu 18.04 LTS.vbox.zip
(2.17 KiB) Downloaded 2 times
Jdupont
Posts: 5
Joined: 8. Apr 2022, 20:58

Re: Port forwarding not working on a NAT network interface with static IP (Ubuntu)

Post by Jdupont »

As an extra information, I'm currently trying to do redirected the VM Static IP (192.168.88.40, port 22 for SSH) to 192.168.88.1 (port 9099).
But I'm not specifically tied to 192.168.88.1, and I can use any other IP's if its easier for the port redirection.
fth0
Volunteer
Posts: 5668
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: Port forwarding not working on a NAT network interface with static IP (Ubuntu)

Post by fth0 »

I think your main problem is that you've configured the same IP network on two network adapters on your host. Take a look at the routing table of your Windows host (e.g. route print).

The routes for one of the network adapters will come before the routes for the other network adapter, and all traffic to IP addresses in the 192.168.88.0/24 network will therefore be routed to the first of those two network adapters. Especially, I'd guess that traffic for 192.168.88.1 will go over 192.168.88.13 and never reach the VirtualBox network adapter.
Jdupont
Posts: 5
Joined: 8. Apr 2022, 20:58

Re: Port forwarding not working on a NAT network interface with static IP (Ubuntu)

Post by Jdupont »

Hi fth0,
Thanks for your feedback.
Here is the route print.
I'll try to set those tow network adapters on two different IP network.

Code: Select all

C:\Users\jdupont>route print
===========================================================================
Interface List
 17...a8 5e 45 12 13 5c ......Realtek PCIe GbE Family Controller
  4...00 13 3b 5a 5f 37 ......Realtek PCIe GbE Family Controller #2
 11...00 13 3b 5a 5f 38 ......Realtek PCIe GbE Family Controller #3
 16...0a 00 27 00 00 10 ......VirtualBox Host-Only Ethernet Adapter
  1...........................Software Loopback Interface 1
===========================================================================

IPv4 Route Table
===========================================================================
Active Routes:
Network Destination        Netmask          Gateway       Interface  Metric
          0.0.0.0          0.0.0.0    10.255.43.254     10.255.43.56     25
        10.24.8.0    255.255.255.0         On-link        10.24.8.13    281
       10.24.8.13  255.255.255.255         On-link        10.24.8.13    281
      10.24.8.255  255.255.255.255         On-link        10.24.8.13    281
      10.255.43.0    255.255.255.0         On-link      10.255.43.56    281
     10.255.43.56  255.255.255.255         On-link      10.255.43.56    281
    10.255.43.255  255.255.255.255         On-link      10.255.43.56    281
        127.0.0.0        255.0.0.0         On-link         127.0.0.1    331
        127.0.0.1  255.255.255.255         On-link         127.0.0.1    331
  127.255.255.255  255.255.255.255         On-link         127.0.0.1    331
     192.168.88.0    255.255.255.0         On-link        10.24.8.13    281
     192.168.88.0    255.255.255.0         On-link      192.168.88.1    330
     192.168.88.1  255.255.255.255         On-link      192.168.88.1    330
    192.168.88.13  255.255.255.255         On-link        10.24.8.13    281
   192.168.88.255  255.255.255.255         On-link        10.24.8.13    281
   192.168.88.255  255.255.255.255         On-link      192.168.88.1    330
        224.0.0.0        240.0.0.0         On-link         127.0.0.1    331
        224.0.0.0        240.0.0.0         On-link      10.255.43.56    281
        224.0.0.0        240.0.0.0         On-link        10.24.8.13    281
        224.0.0.0        240.0.0.0         On-link      192.168.88.1    330
  255.255.255.255  255.255.255.255         On-link         127.0.0.1    331
  255.255.255.255  255.255.255.255         On-link      10.255.43.56    281
  255.255.255.255  255.255.255.255         On-link        10.24.8.13    281
  255.255.255.255  255.255.255.255         On-link      192.168.88.1    330
===========================================================================
Persistent Routes:
  None

IPv6 Route Table
===========================================================================
Active Routes:
 If Metric Network Destination      Gateway
  1    331 ::1/128                  On-link
  4    281 fe80::/64                On-link
 11    281 fe80::/64                On-link
 16    281 fe80::/64                On-link
 16    281 fe80::2c7c:4325:b5c9:7c5d/128
                                    On-link
 11    281 fe80::69e0:81aa:11bd:32f9/128
                                    On-link
  4    281 fe80::80b3:1683:b51b:51c6/128
                                    On-link
  1    331 ff00::/8                 On-link
  4    281 ff00::/8                 On-link
 11    281 ff00::/8                 On-link
 16    281 ff00::/8                 On-link
===========================================================================
Persistent Routes:
  None

fth0
Volunteer
Posts: 5668
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: Port forwarding not working on a NAT network interface with static IP (Ubuntu)

Post by fth0 »

The routing table is a bit different from what I thought, because I didn't envision the consequences of the assignment of two IP addresses to one of the network interfaces. But the key problem is the same: An IP packet sent to 192.168.88.1 will probably match the first route to 192.168.88.0/24, so that the corresponding ARP request will be sent on the 10.24.8.13 network interface.
Post Reply