Log parser / blocker using Golang and nftables.
- Make sure you have nftables installed on your system
- Download the binary to
/usr/local/bin/ - Download the config to
/usr/local/bin/ - Update hosts.deny
- Enjoy
You can also do the Super Lazy install of:
curl -sSL https://raw.githubusercontent.com/palner/blockhosts-nft/refs/heads/main/install_blockhosts.sh | bash
If you do the super lazy install, please check the /etc/hosts.deny for accuracy as well as adding your IP to /usr/local/bin/bhconfig.json.
cd /usr/local/bin
wget https://github.com/palner/blockhosts-nft/raw/refs/heads/main/binary/blockhosts-nft
chmod +x blockhosts-nft
cd /usr/local/bin
wget https://raw.githubusercontent.com/palner/blockhosts-nft/refs/heads/main/bhconfig.yaml
There is a section called Allowed. Add your CIDRs as desired.
Examples...
allowed:
- cidr: 192.168.0.0/16allowed:
- cidr: 192.168.0.0/16
- cidr: 1.1.1.1/32
- cidr: 10.1.1.0/24"Allowed": [{"cidr":"192.168.0.3/32"}]"Allowed": [{"cidr":"192.168.0.0/16"},{"cidr":"1.1.1.1/32"},{"cidr":"10.0.10.0/24"}]"Allowed": [{"cidr":"192.168.0.0/16"}]Examples:
#
# hosts.deny This file describes the names of the hosts which are
# *not* allowed to use the local INET services, as decided
# by the '/usr/sbin/tcpd' server.
#
sshd : ALL : spawn (/usr/local/bin/blockhosts-nft) : allow
sshd : ALL : allow
#
# hosts.deny This file describes the names of the hosts which are
# *not* allowed to use the local INET services, as decided
# by the '/usr/sbin/tcpd' server.
#
sshd : ALL : spawn (/usr/local/bin/blockhosts-nft -ssh=/var/log/secure) : allow
sshd : ALL : allow
ssh: log file to parseset: nftables set name (default isAPIBANLOCAL) (Note: will be created if it doesn't exist)log: log file for output (default is /var/log/blockhosts.log)xtra:true|false. defaultfalse. Used for extra loggingfull:true|false. defaultfalse. Read full log (vs 5000 line chunks)yaml:true|false. defaulttrue. Use YaML (default) or json for config
Example:
/usr/local/bin/blockhosts-nft -ssh=/var/log/secure -xtra=true -set=SSHCHAIN
License: GPLv3
Copyright: Fred Posner (The Palner Group)
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Like it? Please star and consider sponsoring.
Contributions and Issues are welcome!