GithubHelp home page GithubHelp logo

hostname2set's Introduction

hostname2set

Script that resolves a hostname (or multiple) to its corresponding IP addresses and adds these to an nftables set.


Use case

At time of writing, nftables lacks the capability to add addresses to a set in the case that a hostname maps to more than a single IP address. This means that nft add element inet filter ipv4-temp-egress-web { myhost.myhost.example } fails in that case.

To make this work, this script does the name resolution using the dig tool. IP addresses matching the address type of the nftables set are then added to the set one after another.

This is useful for adding IP addresses to sets in a safe manner. With this, one can temporarily allow egress traffic to certain destinations, e.g. for loading updates.

   table inet filter {
        set ipv4-temp-egress-web {
            type ipv4_addr
            timeout 200s
        }
        ...

Installation

Just download the shell script and make it executable (chmod u+x hostname2set.sh). Now you can test it:

./hostname2set.sh --help

The script used the dig utility to resolve hostnames to ip addresses. Make sure it is installed (already available in Debian default installation; apk add bind-tools for Alpine Linux).


Quickstart

Execute the script to add IP addresses to a nftables set based on a given hostname (or a comma-separated list of hostnames):

./hostname2set.sh -t A inet filter ipv4-temp-egress-web myhost.myhost.example

# Optionally check the result
nft list set inet filter ipv4-temp-egress-web

Note that the nftables set must exist prior to attempting to add elements.


Reporting bugs

In case you encounter any bugs, please report the expected behavior and the actual behavior so that the issue can be reproduced and fixed.


Developers

Clone repository

Clone this repo to your local machine using https://github.com/towalink/hostname2set.git.


License

License

hostname2set's People

Contributors

towalink avatar

Watchers

 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.