# Connecting from other Computers

## Overview

In case you intend to run AMC or any other application connection to a virtual skynode on another host in your network, this page describes how to expose the necessary ports on your simulation machine.

{% @mermaid/diagram content="flowchart LR
2nd\_host\[2nd Host]
vm\[Virtual Skynode<br/>10.41.200.2]
port\[(ports 5790 / 8553)]

```
2nd_host <-->|eth network| port
port <-->|iptables routing| vm

subgraph Host_Computer [Host Computer running Virtual Skynode]
    port
    vm
end" %}
```

{% hint style="info" %}

## Assumptions:

* The Virtual Skynode host is a Linux computer with access to [iptables](https://wiki.archlinux.org/title/Iptables)
* No services on the host computer are already listening to port 5790 via TCP
  {% endhint %}

## Automated exposition of ports

Since virtual skynode 0.2.0, you can simply run

```
virtual-skynode expose -i <any-network-interface>
```

to expose MAVLink via port 5790 and RTSP (video) via port 8553 over any viable ethernet connection your simulation machine has access to.

A typical configuration summary looks like:

```
--- Configuration Complete! ---
Summary of Applied iptables Rules:
---------------------------------
PC's Primary Interface:       enx68da73a18a2f
PC's Primary IPv4 Address:    192.168.178.29
PC's Local Network:           192.168.178.0/24
Virtual Skynode Internal IP:  10.41.200.2
MAVLink Port:                 5790 (TCP)
RTSP Port:                    8553 (TCP & UDP)
Skynode Outgoing Interface:   vsnbridge
PC's IP on Skynode Network:   10.41.200.1
```

In case your virtual skynode\`s IP differs from the default, use `--skynode-ip <your-skynode-ip>` to adapt.

## Manual IP forwarding

The following instructions are required for older versions of the `virtual-skynode` package and build a starting point to help users connect a GCS device such as an Android Tablet to a *separate* host computer that is running Virtual Skynode. Depending on your exact setup the steps below might need to be adopted. The goal of this guide is to provide a minimal starting point.

### TCP Packet forwarding via iptables

We are going to configure packet forwarding on the host machine that is running Virtual Skynode. With this method the ground station device will be connecting to the host machine. The ground station is not aware of there being a Virtual Skynode. The ground station also does not need to know anything about the IPV4 address 10.41.200.2, as from its perspective the host machine itself is a Skynode.

The method below uses [IP forwarding](https://en.wikipedia.org/wiki/IP_routing) to get packets from the incoming interface to virtual skynode and back. [Network Address Translation (NAT)](https://en.wikipedia.org/wiki/Network_address_translation) is required to manipulate the source and destination IPv4 address of packets such that Virtual Skynode is cleanly "hidden" behind the host machine.

{% hint style="info" %}
The commands bellow generally require root
{% endhint %}

{% hint style="info" %}
All changes mentioned below generally reset after a reboot of the host machine. Making iptables persistent after a reboot is outside the scope of this guide.
{% endhint %}

Configuring iptables:

```bash
# Rule for forwarding packets that arrive on port 5790 via TCP to Virtual Skynode:
iptables -I FORWARD -d 10.41.200.2 -m comment --comment "Accept to forward mavlink traffic" -m tcp -p tcp --dport 5790 -j ACCEPT    
iptables -t nat -I PREROUTING -m tcp -p tcp --dport 5790 -j DNAT --to-destination 10.41.200.2:5790

# Forward packets coming back from the Virtual Skynode
iptables -I FORWARD -s 10.41.200.2 -m tcp -p tcp --sport 5790 -j ACCEPT

# Setup NAT
iptables -t nat -I POSTROUTING -d 10.41.200.2 -o eth0 -j MASQUERADE
iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
```

Enable packet forwarding in the Linux kernel

```
sysctl -w net.ipv4.ip_forward=1
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.auterion.com/app-development/simulation/virtual-skynode/connecting-from-other-computers.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
