ez-port-forward


Nameez-port-forward JSON
Version 0.2.0 PyPI version JSON
download
home_page
SummaryCreate DNAT port forwarding rules from easy-to-read YAML files.
upload_time2024-03-16 18:36:45
maintainer
docs_urlNone
authorRaphael Kriegl
requires_python>=3.9
license
keywords nat port-forwarding proxmox
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ez_port_forward
[![PyPI - Version](https://img.shields.io/pypi/v/ez-port-forward?style=flat-square&logo=pypi&label=PyPI)](https://pypi.org/project/ez-port-forward/) [![PyPI - Downloads](https://img.shields.io/pypi/dm/ez-port-forward?style=flat-square&logo=pypi)](https://pypi.org/project/ez-port-forward/) [![github](https://img.shields.io/badge/GitHub-100000?style=flat-square&logo=github&logoColor=white)](https://github.com/rk-exxec/ez_port_forward) 


Create DNAT port forwarding rules from easy-to-read YAML files.

Are you tired of always having to look up the `iptables` command every couple of months to change a single port forwarding on your proxmox/hypervisor because a friend asks you to make a new container for that very popular new game?

Here is the solution:   
A YAML-powered port forwarding tool, that does all that for you. 
You simply need to change some numbers in the very readable and easy-to-understand config file. The script then converts that to 100% valid `iptables` commands.

Has shortcut notation for multiple ports and ssh ports, and can do different input and output ports.  
Checks port collisions and validity.



## Installation:
`pip install ez_port_forward`

Installs a command `ez-port-forward` and its shorthand `ezpf`.

## Usage:

- `ez-port-forward`:  
Looks in the current dir for a file named `port_config.yaml` and writes the results to `/etc/network/interfaces.d/port_forwards`.  
WILL REPLACE THE FILE WITHOUT ASKING!  

- `ez-port-forward /path/to/my/port_config.yaml`:  
Uses given input file and writes results to `/etc/network/interfaces.d/port_forwards`.  
WILL REPLACE FILE WITHOUT ASKING!  

- `ez-port-forward -o /target/path/port_forwards`:  
Looks in the current dir for a file named `port_config.yaml` and writes the results to the given output file.  
WILL REPLACE THE FILE WITHOUT ASKING!  

- `ez-port-forward /path/to/my/port_config.yaml -o /target/path/port_forwards`:  
Uses the given input file and writes the results to the given output file.  
WILL REPLACE THE FILE WITHOUT ASKING!  

Same usage for the `ezpf` shorthand.

## Requirements:

Python >= 3.9  
PyYAML

Make sure your `/etc/network/interfaces` config contains the line
`source /etc/network/interfaces.d/*`.

Tested on Proxmox.

## Example:

```yaml
# the name of the bridge
vmbr0:
    # the interface the bridge is connected to
    bridge: eno1
    # the ip range of your subnet you want to make port forwards in
    # container ID are used as last octet for the ip
    subnet: 10.0.0.0/24
    # this section contains all the forwarding magic
    forwards: 
    # this forwards to the container with id 101 and ip 10.0.0.101
        101:
            # forwards external port 10122 to internal port 22
            ssh: true
            # forwards multiple external ports to identical internal ports for tcp udp and both
            tcp: 123,345,567
            udp: 888,999
            tcpudp: 111,222
        102: 
            # maps external ports 321,345,765 to internal ports 123,345,567
            tcp: 
                321: 123
                345: 345 # will notice this port collision with 101 and mark the line in the output as comment
                765: 567
        201: # this is equivalent to below
            ssh:
        202:
            tcp:
                20222: 22
        233:
            # use port 23 for ssh shorthand, forwards 23323 to 23
            ssh: 23 
```

Result:
```bash
iface vmbr0 inet static
#--- Container 101
        post-up iptables -t nat -A PREROUTING -i eno1 -p tcp --dport 10122 -j DNAT --to 10.0.0.101:22
        post-up iptables -t nat -A PREROUTING -i eno1 -p tcp --dport 123 -j DNAT --to 10.0.0.101:123
        post-up iptables -t nat -A PREROUTING -i eno1 -p tcp --dport 345 -j DNAT --to 10.0.0.101:345
        post-up iptables -t nat -A PREROUTING -i eno1 -p tcp --dport 567 -j DNAT --to 10.0.0.101:567
        post-up iptables -t nat -A PREROUTING -i eno1 -p udp --dport 888 -j DNAT --to 10.0.0.101:888
        post-up iptables -t nat -A PREROUTING -i eno1 -p udp --dport 999 -j DNAT --to 10.0.0.101:999
        post-up iptables -t nat -A PREROUTING -i eno1 -p tcp --dport 111 -j DNAT --to 10.0.0.101:111
        post-up iptables -t nat -A PREROUTING -i eno1 -p udp --dport 111 -j DNAT --to 10.0.0.101:111
        post-up iptables -t nat -A PREROUTING -i eno1 -p tcp --dport 222 -j DNAT --to 10.0.0.101:222
        post-up iptables -t nat -A PREROUTING -i eno1 -p udp --dport 222 -j DNAT --to 10.0.0.101:222
#---
#--- Container 102
        post-up iptables -t nat -A PREROUTING -i eno1 -p tcp --dport 321 -j DNAT --to 10.0.0.102:123
#        post-up iptables -t nat -A PREROUTING -i eno1 -p tcp --dport 345 -j DNAT --to 10.0.0.102:345
        post-up iptables -t nat -A PREROUTING -i eno1 -p tcp --dport 765 -j DNAT --to 10.0.0.102:567
#---
#--- Container 201
        post-up iptables -t nat -A PREROUTING -i eno1 -p tcp --dport 20122 -j DNAT --to 10.0.0.201:22
#---
#--- Container 202
        post-up iptables -t nat -A PREROUTING -i eno1 -p tcp --dport 20222 -j DNAT --to 10.0.0.202:22
#---
#--- Container 233
        post-up iptables -t nat -A PREROUTING -i eno1 -p tcp --dport 23323 -j DNAT --to 10.0.0.233:23
#---
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "ez-port-forward",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "",
    "keywords": "nat,port-forwarding,proxmox",
    "author": "Raphael Kriegl",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/b8/54/7943e55158c3bad5caaa240e2536c1184a13fcf3c9efd4530b00cab1aa98/ez_port_forward-0.2.0.tar.gz",
    "platform": null,
    "description": "# ez_port_forward\n[![PyPI - Version](https://img.shields.io/pypi/v/ez-port-forward?style=flat-square&logo=pypi&label=PyPI)](https://pypi.org/project/ez-port-forward/) [![PyPI - Downloads](https://img.shields.io/pypi/dm/ez-port-forward?style=flat-square&logo=pypi)](https://pypi.org/project/ez-port-forward/) [![github](https://img.shields.io/badge/GitHub-100000?style=flat-square&logo=github&logoColor=white)](https://github.com/rk-exxec/ez_port_forward) \n\n\nCreate DNAT port forwarding rules from easy-to-read YAML files.\n\nAre you tired of always having to look up the `iptables` command every couple of months to change a single port forwarding on your proxmox/hypervisor because a friend asks you to make a new container for that very popular new game?\n\nHere is the solution:   \nA YAML-powered port forwarding tool, that does all that for you. \nYou simply need to change some numbers in the very readable and easy-to-understand config file. The script then converts that to 100% valid `iptables` commands.\n\nHas shortcut notation for multiple ports and ssh ports, and can do different input and output ports.  \nChecks port collisions and validity.\n\n\n\n## Installation:\n`pip install ez_port_forward`\n\nInstalls a command `ez-port-forward` and its shorthand `ezpf`.\n\n## Usage:\n\n- `ez-port-forward`:  \nLooks in the current dir for a file named `port_config.yaml` and writes the results to `/etc/network/interfaces.d/port_forwards`.  \nWILL REPLACE THE FILE WITHOUT ASKING!  \n\n- `ez-port-forward /path/to/my/port_config.yaml`:  \nUses given input file and writes results to `/etc/network/interfaces.d/port_forwards`.  \nWILL REPLACE FILE WITHOUT ASKING!  \n\n- `ez-port-forward -o /target/path/port_forwards`:  \nLooks in the current dir for a file named `port_config.yaml` and writes the results to the given output file.  \nWILL REPLACE THE FILE WITHOUT ASKING!  \n\n- `ez-port-forward /path/to/my/port_config.yaml -o /target/path/port_forwards`:  \nUses the given input file and writes the results to the given output file.  \nWILL REPLACE THE FILE WITHOUT ASKING!  \n\nSame usage for the `ezpf` shorthand.\n\n## Requirements:\n\nPython >= 3.9  \nPyYAML\n\nMake sure your `/etc/network/interfaces` config contains the line\n`source /etc/network/interfaces.d/*`.\n\nTested on Proxmox.\n\n## Example:\n\n```yaml\n# the name of the bridge\nvmbr0:\n    # the interface the bridge is connected to\n    bridge: eno1\n    # the ip range of your subnet you want to make port forwards in\n    # container ID are used as last octet for the ip\n    subnet: 10.0.0.0/24\n    # this section contains all the forwarding magic\n    forwards: \n    # this forwards to the container with id 101 and ip 10.0.0.101\n        101:\n            # forwards external port 10122 to internal port 22\n            ssh: true\n            # forwards multiple external ports to identical internal ports for tcp udp and both\n            tcp: 123,345,567\n            udp: 888,999\n            tcpudp: 111,222\n        102: \n            # maps external ports 321,345,765 to internal ports 123,345,567\n            tcp: \n                321: 123\n                345: 345 # will notice this port collision with 101 and mark the line in the output as comment\n                765: 567\n        201: # this is equivalent to below\n            ssh:\n        202:\n            tcp:\n                20222: 22\n        233:\n            # use port 23 for ssh shorthand, forwards 23323 to 23\n            ssh: 23 \n```\n\nResult:\n```bash\niface vmbr0 inet static\n#--- Container 101\n        post-up iptables -t nat -A PREROUTING -i eno1 -p tcp --dport 10122 -j DNAT --to 10.0.0.101:22\n        post-up iptables -t nat -A PREROUTING -i eno1 -p tcp --dport 123 -j DNAT --to 10.0.0.101:123\n        post-up iptables -t nat -A PREROUTING -i eno1 -p tcp --dport 345 -j DNAT --to 10.0.0.101:345\n        post-up iptables -t nat -A PREROUTING -i eno1 -p tcp --dport 567 -j DNAT --to 10.0.0.101:567\n        post-up iptables -t nat -A PREROUTING -i eno1 -p udp --dport 888 -j DNAT --to 10.0.0.101:888\n        post-up iptables -t nat -A PREROUTING -i eno1 -p udp --dport 999 -j DNAT --to 10.0.0.101:999\n        post-up iptables -t nat -A PREROUTING -i eno1 -p tcp --dport 111 -j DNAT --to 10.0.0.101:111\n        post-up iptables -t nat -A PREROUTING -i eno1 -p udp --dport 111 -j DNAT --to 10.0.0.101:111\n        post-up iptables -t nat -A PREROUTING -i eno1 -p tcp --dport 222 -j DNAT --to 10.0.0.101:222\n        post-up iptables -t nat -A PREROUTING -i eno1 -p udp --dport 222 -j DNAT --to 10.0.0.101:222\n#---\n#--- Container 102\n        post-up iptables -t nat -A PREROUTING -i eno1 -p tcp --dport 321 -j DNAT --to 10.0.0.102:123\n#        post-up iptables -t nat -A PREROUTING -i eno1 -p tcp --dport 345 -j DNAT --to 10.0.0.102:345\n        post-up iptables -t nat -A PREROUTING -i eno1 -p tcp --dport 765 -j DNAT --to 10.0.0.102:567\n#---\n#--- Container 201\n        post-up iptables -t nat -A PREROUTING -i eno1 -p tcp --dport 20122 -j DNAT --to 10.0.0.201:22\n#---\n#--- Container 202\n        post-up iptables -t nat -A PREROUTING -i eno1 -p tcp --dport 20222 -j DNAT --to 10.0.0.202:22\n#---\n#--- Container 233\n        post-up iptables -t nat -A PREROUTING -i eno1 -p tcp --dport 23323 -j DNAT --to 10.0.0.233:23\n#---\n```\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Create DNAT port forwarding rules from easy-to-read YAML files.",
    "version": "0.2.0",
    "project_urls": {
        "Homepage": "https://github.com/rk-exxec/ez_port_forwarding",
        "Issues": "https://github.com/rk-exxec/ez_port_forwarding/issues"
    },
    "split_keywords": [
        "nat",
        "port-forwarding",
        "proxmox"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c8b67c5e75461456054dc7f10af9b4c37bf0f25e5ca8f60988cd64a8e8161dd7",
                "md5": "65a411ba8375ae593a7448ae3d8cb79b",
                "sha256": "eccac0af92aa9e7c58b6c5272ecf60934748fe1977cd4ddfe4a199d242337fbc"
            },
            "downloads": -1,
            "filename": "ez_port_forward-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "65a411ba8375ae593a7448ae3d8cb79b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 18842,
            "upload_time": "2024-03-16T18:36:44",
            "upload_time_iso_8601": "2024-03-16T18:36:44.137876Z",
            "url": "https://files.pythonhosted.org/packages/c8/b6/7c5e75461456054dc7f10af9b4c37bf0f25e5ca8f60988cd64a8e8161dd7/ez_port_forward-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b8547943e55158c3bad5caaa240e2536c1184a13fcf3c9efd4530b00cab1aa98",
                "md5": "87f664e386cec927e6dee8da55898db9",
                "sha256": "4acdadf005c7660b2855c5d317d78e3cb9677abf94b2e9ab4138d958d1e7a012"
            },
            "downloads": -1,
            "filename": "ez_port_forward-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "87f664e386cec927e6dee8da55898db9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 21752,
            "upload_time": "2024-03-16T18:36:45",
            "upload_time_iso_8601": "2024-03-16T18:36:45.406711Z",
            "url": "https://files.pythonhosted.org/packages/b8/54/7943e55158c3bad5caaa240e2536c1184a13fcf3c9efd4530b00cab1aa98/ez_port_forward-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-16 18:36:45",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "rk-exxec",
    "github_project": "ez_port_forwarding",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "ez-port-forward"
}
        
Elapsed time: 0.30344s