Code Monkey home page Code Monkey logo

vpn-port-passthrough's Introduction

Vpn-port-passthrough

Simple bash script to pass port over to vpn client and pass it back using iptables or ufw.

This script takes user input and then passes 2 iptables commands to make port passthrough work.

This script is to be run on the machine acting as VPN Server!

For example you can have VPS server acting as vpn server, and access ssh of the vpn client from outside world using this script.

You must set net.ipv4.ip_forward=1 to make both scripts work

Variables:

  • Mode - choose which script to use (iptables or ufw). (Only available in vpncombined.sh)
  • Input Port - port you want to access from outside world.
  • Port - port which you want to access on VPN client (eg ssh server port)
  • WAN - WAN of your VPS (VPN Server)
  • Client - Internal vpn ip address of your VPN client (run ip addr on your VPN Client to check, (tun0 section))
  • Server - Internal vpn ip address of your VPN server (run ip addr on your VPN Server to check, (tun0 section))

Iptables:

This script:

  • Runs 2 commands to add rules to iptables

These commands are useful to remove unwanted iptables rules:

  • List PREROUTING rules with line numbers: iptables -t nat -v -L PREROUTING -n --line-number
  • Remove PREROUTING roule with given number: iptables -t nat -D PREROUTING NUMBER
  • List POSTROUTING rules with line numbers: iptables -t nat -v -L POSTROUTING -n --line-number
  • Remove POSTROUTING roule with given number: iptables -t nat -D POSTROUTING NUMBER

UFW:

To make this script work:

  • You must have 'DEFAULT_FORWARD_POLICY="ACCEPT"' in /etc/default/ufw
  • This must be set this manually at the end of /etc/ufw/before.rules
*nat
:PREROUTING ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]

-F

COMMIT
  • COMMIT must be the last line of the file in order for script to work correctly

This script:

  • Removes COMMIT at the end of /etc/ufw/before.rules
  • Adds rules for port passthrough at the end of the file
  • Adds comment above added rules to explain what they do
  • Adds COMMIT at the end of /etc/ufw/before.rules

vpn-port-passthrough's People

Contributors

georgeghost avatar

Stargazers

 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.