Code Monkey home page Code Monkey logo

simpletun's Introduction

simpletun

Simple half duplex tunnel

Host A(172.18.0.2)

./simpletun -s -i tun0 
ip route add a.a.a.a/b dev tun0

Host B(172.18.0.1)

./simpletun -i tun0 -c 172.18.0.2 
ip route add c.c.c.c/d dev tun0

Host A ------------------------------------ Host B

On host A, the flow to a.a.a.a/b will go through the tunnel. On host B, the flow to c.c.c.c/d will go through the tunnel.

....

Why is it half duplex? Because SimpleTun has only one thread and can only handle one direction at a time.

for tunnat:

Host A -----------------Host M------------------- Host B On host A:

ifconfig enp0s9 172.16.0.1/24
route add -host 172.18.0.1 gw 172.16.0.2

On host M:

ifconfig enp0s9 172.16.0.2/24
ifconfig enp0s10 172.18.0.2/24
./tunnat -i tun1 -o 172.16.0.1 -m 123.110.0.1
ip rule add from 172.16.0.1 tab tunnat
ip route add default dev tun1
ip route add 123.110.0.1/32 dev tun1

On host B:

ifconfig enp0s10 172.18.0.1/24
route add default gw 172.18.0.2

Host A ping Host B ping 172.18.0.1

07:48:02.584525 IP 123.110.0.1 > 172.18.0.1: ICMP echo request, id 5, seq 2167, length 64
07:48:02.584795 IP 172.18.0.1 > 123.110.0.1: ICMP echo reply, id 5, seq 2167, length 64
07:48:03.612804 IP 123.110.0.1 > 172.18.0.1: ICMP echo request, id 5, seq 2168, length 64
07:48:03.613082 IP 172.18.0.1 > 123.110.0.1: ICMP echo reply, id 5, seq 2168, length 64
07:48:04.639537 IP 123.110.0.1 > 172.18.0.1: ICMP echo request, id 5, seq 2169, length 64
07:48:04.639939 IP 172.18.0.1 > 123.110.0.1: ICMP echo reply, id 5, seq 2169, length 64
07:48:05.667918 IP 123.110.0.1 > 172.18.0.1: ICMP echo request, id 5, seq 2170, length 64
07:48:05.668204 IP 172.18.0.1 > 123.110.0.1: ICMP echo reply, id 5, seq 2170, length 64

for tunnat64:

Host A -----------------Host M------------------- Host B

On host A(IPv6 only):

ip -6 addr add dev enp0s8 fdbd:dc03:ff:1:1:227:88:205/64
ip -6 route add default via fe80::dd7:1398:196d:66bf dev enp0s8 # Link-local address fe80::dd7:1398:196d:66bf is at Host M

On host M(NAT6/4):

ifconfig enp0s10 172.18.0.2/24
./tunnat -i tun1 -m 123.110.0.1
ip -6 route add default dev tun1
ip route add 123.110.0.1/32 dev tun1

On host B(IPv4 only):

ifconfig enp0s10 172.18.0.1/24
route add default gw 172.18.0.2

Host A ping Host B ping 64:ff9b::172.18.0.1 Host A:

## ping result
PING 64:ff9b::172.18.0.1(64:ff9b::ac12:1) 56 data bytes
64 bytes from 64:ff9b::ac12:1: icmp_seq=1 ttl=62 time=1.06 ms
64 bytes from 64:ff9b::ac12:1: icmp_seq=2 ttl=62 time=0.983 ms

## tcpdump result
12:06:32.047425 IP6 fdbd:dc03:ff:1:1:227:88:205 > 64:ff9b::ac12:1: ICMP6, echo request, seq 1, length 64
12:06:32.048469 IP6 64:ff9b::ac12:1 > fdbd:dc03:ff:1:1:227:88:205: ICMP6, echo reply, seq 1, length 64
12:06:33.049774 IP6 fdbd:dc03:ff:1:1:227:88:205 > 64:ff9b::ac12:1: ICMP6, echo request, seq 2, length 64
12:06:33.050734 IP6 64:ff9b::ac12:1 > fdbd:dc03:ff:1:1:227:88:205: ICMP6, echo reply, seq 2, length 64

Host B:

## tcpdump result
23:03:52.193734 IP 123.110.0.1 > 172.18.0.1: ICMP echo request, id 13, seq 1, length 64
23:03:52.193765 IP 172.18.0.1 > 123.110.0.1: ICMP echo reply, id 13, seq 1, length 64
23:03:53.196104 IP 123.110.0.1 > 172.18.0.1: ICMP echo request, id 13, seq 2, length 64
23:03:53.196250 IP 172.18.0.1 > 123.110.0.1: ICMP echo reply, id 13, seq 2, length 64

enjoy yourself!

simpletun's People

Contributors

marywangran avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.