Giter Club home page Giter Club logo

dhclient-pd's Introduction

dhclient-pd

dhclient-pd is a script that takes an incoming IPv6 prefix delegation from dhclient and assigns subnet prefix addresses to one or more additional interfaces on the system. It is also a standalone tool that may be called from any source, not just dhclient. Only the hook script is dhclient specific.

Why two scripts?

dhclient actually sources the hook scripts, which means that the hook script must be valid shell script code. However, working with IP addresses in shell scripting is both error prone and complex, so I implemented that logic in python instead. Python was chosen because it is nearly always available on any modern linux system.

Requirements

  • a modern version of python3

Installation

sudo cp ./src/prefix-delegation /etc/dhcp/dhclient-exit-hooks.d/prefix-delegation
sudo chmod 644 /etc/dhcp/dhclient-exit-hooks.d/prefix-delegation
sudo cp ./src/dhclient-pd /usr/local/bin/dhclient-pd
sudo chmod 755 ./src/dhclient-pd /usr/local/bin/dhclient-pd
sudo mkdir /etc/dhclient-pd

Configuration

Create /etc/dhclient-pd/interfaces.json. Example syntax:

[
    {
        "name": "enp4s0f0.3",
        "prefix_id": "3"
    },
    {
        "name": "enp4s0f1.4",
        "prefix_id": "4"
    },
    {
        "name": "enp4s0f1.5",
        "prefix_id": "af1"
    },
    {
        "name": "enp4s0f1.6",
        "prefix_id": "6"
    },
    {
        "interface_ids": [
            "::1",
            "::3"
        ],
        "name": "lo",
        "prefix_id": "0"
        "prefix_length: 128
    }
]

name and prefix_id are mandatory. Note that prefix_id is a string containing the hex representation of the id, so the value needs to be quoted to avoid being interpreted as an integer if there are no letters in the id. interface_ids is set to ["::1"] by default unless overriden. You may define multiple interface_ids within the same prefix, which is normally useful only for loopback addresses (/128). If you want to have multiple different prefixes on the same interface, just add another configuration block for that interface with an unique prefix_id.

Manual execution

You are not bound to dhclient. The hook script manages all the dhclient specifics. dhclient-pd is a standalone tool that may be called from any source. Typically you would call it manually with:

dhclient-pd config -p $prefix [-o $old_prefix]

You must replace $prefix with your actual delegated prefix.

If you run config without any prefix options nothing will happen as dhclient-pd then doesn't know which prefixes to manage.

To quickly show the configuration:

dhclient-pd show

dhclient-pd's People

Contributors

hkbakke 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.