|
[Linux] Block IP Address using IPtables
1. Login to your server via SSH and su - to root (do not forget the - after su).
2. After logging in as root, you may want to look at what's already loaded, if anything. To look at the tables that are currently in effect:
(Note: You might need to add "| less" to the end of your iptables -L commands if you have a lot of iptables rules. This will let you view the rules one page at a time. You can use "q" to quit.)
# iptables -L -n
3. To successfully block an IP address, the syntax would be:
# iptables -I INPUT -s IP_ADDRESS_HERE -j DROP
e.g.:
# iptables -I INPUT -s 123.123.123.123 -j DROP
4. To verify that your entry was successful:
(Note: You might need to add "| less" to the end of your iptables -L commands if you have a lot of iptables rules. This will let you view the rules one page at a time. You can use "q" to quit.)
(as root still)
# /sbin/iptables -L -n
5. If you want to flush your IPtables:
# /sbin/iptables -F
You can find other options to choose from with the following command:
# /sbin/iptables --help
|