Git Product home page Git Product logo

microvpn's Introduction

microvpn

シンプルなネットワーク学習用VPNです。もちろん実用向けではありません。

  • 認証、暗号化なし
  • クライアントはひとつだけ
  • IPv4

準備

サーバ

  • ルーティング
# (1) 仮想デバイスにIPアドレスを割り当てる
# system("ip addr add 10.0.0.1 dev tunserver");
# (2) 仮想デバイスをリンクアップさせる
# system("ip link set tunserver up");
# (3) VPN内宛のパケットを仮想デバイスに向ける
# system("ip route add 10.0.0.0/24 dev tunserver");
  • カーネルパラメータでIPフォワードを許可
# /etc/sysctl.conf
# ルーティングの(3)に対応
net.ipv4.ip_forward=1
  • ファイアウォール(iptables)
# VPNから出ていく通信についてIPマスカレードを適用する
sudo iptables -t nat -A POSTROUTING -s 10.0.0.0/24 -o eth0 -j MASQUERADE
# VPNサーバへ入るUDPパケットを許可する
sudo iptables -A INPUT -p udp --dport 1195 -j ACCEPT
# インターネットからVPNに入る通信が仮想デバイスに行くのを許可する
# ルーティングの(3)に対応
sudo iptables -A FORWARD -i eth0 -o tunserver -d 10.0.0.0/24 -j ACCEPT

クライアント

  • ルーティング
# (1) 仮想デバイスにIPアドレスを割り当てる
# system("sudo ip addr add 10.0.0.2 dev tunclient");
# (2) 仮想デバイスをリンクアップさせる
# system("sudo ip link set tunclient up");
# (3) VPNサーバへは直接接続するようにする
sudo ip route add 7.256.22.2 via 192.168.0.1 dev eno1
# (4) すべての宛先への通信を仮想デバイスに向ける
sudo ip route add 0.0.0.0/0 dev tunclient

使い方

環境変数にIPアドレスを設定

export CLIENT_IPADDR="3.256.8.1"
export SERVER_IPADDR="7.256.22.2"

サーバ

gcc -g util.c server.c -o server.out
sudo -E ./server.out

クライアント

gcc -g util.c client.c -o client.out
sudo -E ./client.out

接続テスト

sudo traceroute -i tunclient 1.1.1.1 -4 -I -n

microvpn's People

Contributors

shosatojp avatar

Stargazers

 avatar  avatar

Watchers

 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.