Log parser / blocker using Golang and IPtables.
- Make sure you have iptables 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/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/raw/refs/heads/main/binary/blockhosts
chmod +x blockhosts
cd /usr/local/bin
wget https://raw.githubusercontent.com/palner/blockhosts/refs/heads/main/bhconfig.json
There is a section (in json
) called Allowed. Add your CIDRs as desired.
Examples...
"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) : 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 -ssh=/var/log/secure) : allow
sshd : ALL : allow
ssh
: log file to parsetarget
: iptables action (default isDROP
)chain
: iptables chain 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
. default false. Used for extra loggingfull
:true|false
. default false. Read full log (vs 5000 line chunks)
Example:
/usr/local/bin/blockhosts -ssh=/var/log/secure -xtra=true -chain=SSHCHAIN -target=REJECT
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.
See LICENSE for more details
Like it? Please star and consider a sponsor