Created
August 29, 2021 08:38
-
-
Save carneeki/b314f8a6271c88a11722f46ab584e08c to your computer and use it in GitHub Desktop.
Fish shell function to reject a host using UFW and conntrack to purge state table entries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function reject | |
touch ~/rejected.txt | |
for host in $argv | |
if grep $host ~/rejected.txt | |
echo "$host already rejected!" | |
sudo conntrack -D --src $host | |
sudo conntrack -D --dst $host | |
continue | |
end | |
echo "rejecting $host" | |
echo "$host" >> ~/rejected.txt | |
sudo ufw insert 1 reject in from $host to any | |
sudo ufw insert 1 reject out to $host from any | |
sudo conntrack -D --src $host | |
sudo conntrack -D --dst $host | |
end | |
end | |
function unreject | |
for host in $argv | |
sudo ufw delete reject from any to $host | |
sudo ufw delete reject from $host to any | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment