New on LowEndTalk? Please Register and read our Community Rules.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
Need help with IP Block script
I'm trying to make an IP Ban Script, so my Admins of my Gameserver can easely ban people by IP
I want it like this: ./ipban.sh IPHERE
I already got this:
#!/bin/sh if [ -z "$ip" ] then executable=$ip shift while [ -n "ip" ] do iptables -A INPUT -s $ip -j DROP done fi
But when u do ./ipban.sh IPHERE i get this:
Bad argument `DROP' Try `iptables -h' or 'iptables --help' for more information.
Can someone help me with this?
Comments
Use
/etc/hosts.deny
, line-based like regular hosts file, much simpler.Usage: ./filename.sh ip.addr.to.ban
Mustn't you make anything like $ip=$1? $1 would be "IPHERE"
Or replace "$ip" in your script with "$1".
Doesn't display any errors anymore
But now it doesn't block IP's...
What have you exactly done? What does iptables -L show?
I changed the $ip to $1
Output from iptables -L
These are the IP's i banned manually with iptables -A INPUT -s iphere -j DROP
Not with the script
Hmm, looks like that you banned already some IPs and it should work. You could try to reset iptables with iptables -F and /etc/init.d/iptables restart, but it should work already. - Is it an openvz container? Don't know why but had already some problems with it and iptables. Iptables showed banned IPs but it haven't blocked them.
@Amfy
Those Ip's i didn't ban with the script
Just via console, with iptables -A INPUT -s IP -j DROP
@joodle: Don't know what your problem exactly is, but it makes no difference if you use the script or just the console with your iptables command.
@amfy
It's easier for my Admins to just give them a script, instead of them keep asking me for the command line
@joodle
My comment above was the answer to "Those Ip's i didn't ban with the script "
But do whatever you want.