Skip to content

Instantly share code, notes, and snippets.

@ExtremeGTX
Last active Mar 28, 2020
Embed
What would you like to do?
This script is to configure an intermediate machine to allow remote access to a development board

This script is to configure an intermediate machine to allow remote access to a development board

#!/bin/sh

# Network Topology
#
# [Developer Machine]   <-->  [Remote Machine(Linux)]  <-->  [Development Board]
#    Machine (A)                   Machine (B)                  Machine (C)
#    192.168.1.2        <-->    eth0: 192.168.1.3
#                               eth1: 10.1.10.2        <-->      10.1.10.3
#
# The goal of this script is to configure one of interfaces of Machine (B)
# to allow transparent connection to Machine (C) from Machine (A)
# Connection request from (A) to (C) redirected by (B)

# This script will Run on Machine (B)

# Configure nic connected to Machine (C)
ifconfig eth1 up 10.1.10.2

# Allow forwarding
sysctl -w net.ipv4.ip_forward=1

# Enable NAT on incoming port 4321, to be redirected to 10.1.10.3:4322
iptables -t nat -A  PREROUTING -p tcp --dport 4321 -j DNAT --to 10.1.10.3:4322
# Update SourceIP of the outgoing packet based on Machine (B) IP, Check Refs
iptables -t nat  -A POSTROUTING -j MASQUERADE

Refs:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment