Showing posts with label hosts.deny example. Show all posts
Showing posts with label hosts.deny example. Show all posts

Friday, March 15, 2013

Base IPTables rules that will apply to virtually any web server



Base IPTables rules that will apply to virtually any web server


Hello,
I have put together some basic iptables based firewall rules that I feel should apply to virtually any web server running cPanel/WHM that is connected to the internet. Please give me your feedback and improvements!


I popped the iptables rules into a bash script that can be easily commented and run in order to apply these rules.
#!/bin/bash
#####################################################################

# 1) Clear old Rules
iptables -F # Delete all existing rules

# 2) Default Drop
iptables -P INPUT DROP # Set default chain policies to DROP
iptables -P FORWARD DROP # Set default chain policies to DROP
iptables -P OUTPUT DROP # Set default chain policies to DROP

# 3) Loopback
iptables -A INPUT -i lo -j ACCEPT # Allow loopback access from INPUT
iptables -A OUTPUT -o lo -j ACCEPT # Allow loopback access from Output

# 4) BLACKLIST IP's
# iptables -A INPUT -s "BLOCK_THIS_IP" -j DROP # Block a specific ip-address
# iptables -A INPUT -s "BLOCK_THIS_IP" -j DROP # Block a specific ip-address
# iptables -A INPUT -s "BLOCK_THIS_IP" -j DROP # Block a specific ip-address
# iptables -A INPUT -s "BLOCK_THIS_IP" -j DROP # Block a specific ip-address

# 5) WHITELIST IP's
iptables -A INPUT -s 127.0.0.1/32 -j ACCEPT # Allow Anything from localhost
iptables -A INPUT -s "ALLOW_THIS_IP"/32 -j ACCEPT # Allow Anything from KeyServer

# 6) ALLOWED SERVICES
iptables -A OUTPUT -o eth0 -p tcp --sport 25 -m state --state ESTABLISHED -j ACCEPT # PORT 25 SMTP - Allow connections to outbound
iptables -A OUTPUT -p udp -o eth0 --dport 53 -j ACCEPT # PORT 54 DNS - Allow connections to outbound
iptables -A INPUT -p tcp -m tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT # PORT 80 httpd - Allow connections from anywhere
iptables -A INPUT -p tcp --dport 80 -m limit --limit 25/minute --limit-burst 100 -j ACCEPT # PORT 80 httpd - Rate Limit from outside
iptables -A INPUT -p tcp -m tcp --dport 443 -m state --state NEW,ESTABLISHED -j ACCEPT # PORT 443 SSL - Allow connections from anywhere
iptables -A INPUT -p tcp -m tcp --dport 2082 -m state --state NEW,ESTABLISHED -j ACCEPT # PORT 2082 cPanel - Allow connections to outbound
iptables -A INPUT -p tcp -m tcp --dport 2083 -m state --state NEW,ESTABLISHED -j ACCEPT # PORT 2083 cPanel - Allow connections to outbound
iptables -A INPUT -p tcp -m tcp --dport 2086 -m state --state NEW,ESTABLISHED -j ACCEPT # PORT 2086 WHM - Allow connections to outbound
iptables -A INPUT -p tcp -m tcp --dport 2087 -m state --state NEW,ESTABLISHED -j ACCEPT # PORT 2087 WHM - Allow connections to outbound

# 7) PING
iptables -A INPUT -p icmp -m icmp --icmp-type address-mask-request -j DROP # Drop Ping from address-mask-request
iptables -A INPUT -p icmp -m icmp --icmp-type timestamp-request -j DROP # Drop Ping from timestamp-request
iptables -A INPUT -p icmp -m icmp -m limit --limit 1/second -j ACCEPT # Rate Limit Ping from outside

# 8) Validate packets
iptables -A INPUT -m state --state INVALID -j DROP # Drop invalid packets
iptables -A FORWARD -m state --state INVALID -j DROP # Drop invalid packets
iptables -A OUTPUT -m state --state INVALID -j DROP # Drop invalid packets
iptables -A INPUT -p tcp -m tcp --tcp-flags SYN,FIN SYN,FIN -j DROP # Drop TCP - SYN,FIN packets
iptables -A INPUT -p tcp -m tcp --tcp-flags SYN,RST SYN,RST -j DROP # Drop TCP - SYN,RST packets

# 9) Reject Invalid networks (Spoof)
iptables -A INPUT -s 10.0.0.0/8 -j DROP # (Spoofed network)
iptables -a INPUT -s 192.0.0.1/24 -j DROP # (Spoofed network)
iptables -A INPUT -s 169.254.0.0/16 -j DROP # (Spoofed network)
iptables -A INPUT -s 172.16.0.0/12 -j DROP # (Spoofed network)
iptables -A INPUT -s 224.0.0.0/4 -j DROP # (Spoofed network)
iptables -A INPUT -d 224.0.0.0/4 -j DROP # (Spoofed network)
iptables -A INPUT -s 240.0.0.0/5 -j DROP # (Spoofed network)
iptables -A INPUT -d 240.0.0.0/5 -j DROP # (Spoofed network)
iptables -A INPUT -s 0.0.0.0/8 -j DROP # (Spoofed network)
iptables -A INPUT -d 0.0.0.0/8 -j DROP # (Spoofed network)
iptables -A INPUT -d 239.255.255.0/24 -j DROP # (Spoofed network)
iptables -A INPUT -d 255.255.255.255 -j DROP # (Spoofed network)

# 10) CHAINS

# FTP_BRUTE CHAIN
iptables -A INPUT -p tcp -m multiport --dports 20,21 -m state --state NEW -m recent --set --name FTP_BRUTE
iptables -A INPUT -p tcp -m multiport --dports 20,21 -m state --state NEW -m recent --update --seconds 60 --hitcount 4 --rttl --name FTP_BRUTE -j DROP

# SYNFLOOD CHAIN
iptables -A INPUT -m state --state NEW -p tcp -m tcp --syn -m recent --name SYNFLOOD--set
iptables -A INPUT -m state --state NEW -p tcp -m tcp --syn -m recent --name SYNFLOOD --update --seconds 1 --hitcount 60 -j DROP

# Logging CHAIN
iptables -N LOGGING # Create `LOGGING` chain for logging denied packets
iptables -A INPUT -j LOGGING # Create `LOGGING` chain for logging denied packets
iptables -A LOGGING -m limit --limit 2/min -j LOG --log-prefix "IPTables Packet Dropped: " --log-level 6 # Log denied packets to /var/log/messages
iptables -A LOGGING -j DROP # Drop everything

Base IPTables rules that will apply to virtually any web server



Base IPTables rules that will apply to virtually any web server


Hello,
I have put together some basic iptables based firewall rules that I feel should apply to virtually any web server running cPanel/WHM that is connected to the internet. Please give me your feedback and improvements!


I popped the iptables rules into a bash script that can be easily commented and run in order to apply these rules.
#!/bin/bash
#####################################################################

# 1) Clear old Rules
iptables -F # Delete all existing rules

# 2) Default Drop
iptables -P INPUT DROP # Set default chain policies to DROP
iptables -P FORWARD DROP # Set default chain policies to DROP
iptables -P OUTPUT DROP # Set default chain policies to DROP

# 3) Loopback
iptables -A INPUT -i lo -j ACCEPT # Allow loopback access from INPUT
iptables -A OUTPUT -o lo -j ACCEPT # Allow loopback access from Output

# 4) BLACKLIST IP's
# iptables -A INPUT -s "BLOCK_THIS_IP" -j DROP # Block a specific ip-address
# iptables -A INPUT -s "BLOCK_THIS_IP" -j DROP # Block a specific ip-address
# iptables -A INPUT -s "BLOCK_THIS_IP" -j DROP # Block a specific ip-address
# iptables -A INPUT -s "BLOCK_THIS_IP" -j DROP # Block a specific ip-address

# 5) WHITELIST IP's
iptables -A INPUT -s 127.0.0.1/32 -j ACCEPT # Allow Anything from localhost
iptables -A INPUT -s "ALLOW_THIS_IP"/32 -j ACCEPT # Allow Anything from KeyServer

# 6) ALLOWED SERVICES
iptables -A OUTPUT -o eth0 -p tcp --sport 25 -m state --state ESTABLISHED -j ACCEPT # PORT 25 SMTP - Allow connections to outbound
iptables -A OUTPUT -p udp -o eth0 --dport 53 -j ACCEPT # PORT 54 DNS - Allow connections to outbound
iptables -A INPUT -p tcp -m tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT # PORT 80 httpd - Allow connections from anywhere
iptables -A INPUT -p tcp --dport 80 -m limit --limit 25/minute --limit-burst 100 -j ACCEPT # PORT 80 httpd - Rate Limit from outside
iptables -A INPUT -p tcp -m tcp --dport 443 -m state --state NEW,ESTABLISHED -j ACCEPT # PORT 443 SSL - Allow connections from anywhere
iptables -A INPUT -p tcp -m tcp --dport 2082 -m state --state NEW,ESTABLISHED -j ACCEPT # PORT 2082 cPanel - Allow connections to outbound
iptables -A INPUT -p tcp -m tcp --dport 2083 -m state --state NEW,ESTABLISHED -j ACCEPT # PORT 2083 cPanel - Allow connections to outbound
iptables -A INPUT -p tcp -m tcp --dport 2086 -m state --state NEW,ESTABLISHED -j ACCEPT # PORT 2086 WHM - Allow connections to outbound
iptables -A INPUT -p tcp -m tcp --dport 2087 -m state --state NEW,ESTABLISHED -j ACCEPT # PORT 2087 WHM - Allow connections to outbound

# 7) PING
iptables -A INPUT -p icmp -m icmp --icmp-type address-mask-request -j DROP # Drop Ping from address-mask-request
iptables -A INPUT -p icmp -m icmp --icmp-type timestamp-request -j DROP # Drop Ping from timestamp-request
iptables -A INPUT -p icmp -m icmp -m limit --limit 1/second -j ACCEPT # Rate Limit Ping from outside

# 8) Validate packets
iptables -A INPUT -m state --state INVALID -j DROP # Drop invalid packets
iptables -A FORWARD -m state --state INVALID -j DROP # Drop invalid packets
iptables -A OUTPUT -m state --state INVALID -j DROP # Drop invalid packets
iptables -A INPUT -p tcp -m tcp --tcp-flags SYN,FIN SYN,FIN -j DROP # Drop TCP - SYN,FIN packets
iptables -A INPUT -p tcp -m tcp --tcp-flags SYN,RST SYN,RST -j DROP # Drop TCP - SYN,RST packets

# 9) Reject Invalid networks (Spoof)
iptables -A INPUT -s 10.0.0.0/8 -j DROP # (Spoofed network)
iptables -a INPUT -s 192.0.0.1/24 -j DROP # (Spoofed network)
iptables -A INPUT -s 169.254.0.0/16 -j DROP # (Spoofed network)
iptables -A INPUT -s 172.16.0.0/12 -j DROP # (Spoofed network)
iptables -A INPUT -s 224.0.0.0/4 -j DROP # (Spoofed network)
iptables -A INPUT -d 224.0.0.0/4 -j DROP # (Spoofed network)
iptables -A INPUT -s 240.0.0.0/5 -j DROP # (Spoofed network)
iptables -A INPUT -d 240.0.0.0/5 -j DROP # (Spoofed network)
iptables -A INPUT -s 0.0.0.0/8 -j DROP # (Spoofed network)
iptables -A INPUT -d 0.0.0.0/8 -j DROP # (Spoofed network)
iptables -A INPUT -d 239.255.255.0/24 -j DROP # (Spoofed network)
iptables -A INPUT -d 255.255.255.255 -j DROP # (Spoofed network)

# 10) CHAINS

# FTP_BRUTE CHAIN
iptables -A INPUT -p tcp -m multiport --dports 20,21 -m state --state NEW -m recent --set --name FTP_BRUTE
iptables -A INPUT -p tcp -m multiport --dports 20,21 -m state --state NEW -m recent --update --seconds 60 --hitcount 4 --rttl --name FTP_BRUTE -j DROP

# SYNFLOOD CHAIN
iptables -A INPUT -m state --state NEW -p tcp -m tcp --syn -m recent --name SYNFLOOD--set
iptables -A INPUT -m state --state NEW -p tcp -m tcp --syn -m recent --name SYNFLOOD --update --seconds 1 --hitcount 60 -j DROP

# Logging CHAIN
iptables -N LOGGING # Create `LOGGING` chain for logging denied packets
iptables -A INPUT -j LOGGING # Create `LOGGING` chain for logging denied packets
iptables -A LOGGING -m limit --limit 2/min -j LOG --log-prefix "IPTables Packet Dropped: " --log-level 6 # Log denied packets to /var/log/messages
iptables -A LOGGING -j DROP # Drop everything

Automatically Updating Banned IPs With hosts.deny or iptables



Automatically Updating Banned IPs With hosts.deny or iptables


First let me start off by saying that this can be used for iptables with some minor tweaking, but I chose to implement this using tcp_wrappers instead (/etc/hosts.allow; hosts.deny). Main reason being is I wrote this for Rob to make his task of updating a list of banned IPs that much easier.

Requirements
Before getting started, there are some requirements. One of them being that this was written with Bash in mind, so if you use Zsh or some other shell, there's no guarantees it will work right out of the box. Secondly, cURL OR wget must be installed. Originally I wrote this with only cURL support, but also decided to work in wget since it was trivial.

Notes
There is not a whole lot of error checking, and there are areas that can be improved. I've never claimed, nor will I ever, to be a script-fu master. If what I write works, then I'm proud of myself. If not, I see how I can make it work. So, basically consider it your homework to add the line into tcp_wrappers after the list is generated. The script will be provided at the end of this post, like usual. Also, be aware that this is generated in CIDR format (which both tcp_wrapper & iptables support). The format can be changed, but that will be extra credit.

Purpose
Maintaining an ACL (access control list) can be very daunting, for one. Especially when you have to maintain the same ACL on multiple servers. You can push out a customized file for the servers and be done with it. But, how do you even populate that list? While the source for these IPs is not the de-facto, it provides a good amount to use.

Why, then, write this script? Easy. For those who want to keep an up-to-date bad IP (reported for whatever reason). Maybe you're running a network of cloud servers and want to reduce the threat of attacks.

How To Use
Throughout the rest of this article I'll assume you're using the default name of the script, fetch.sh.

So how is this script used exactly? Simple, it takes up to 2 arguments:

  • Country list

  • Bad IP filename


 

The country list argument has to be enclosed in quotes if you're wanting more than 1 originating-country's IP list. Also, the list must be in ISO format. So, for example if you want all reported IPs from Afghanistan and USA, it would be "AF US". By default all countries are fetched (see the CL variable for more).

The bad IP filename is the absolute path to the file where the IPs will be stored. By default the path (and file) is /tmp/bad_ips. If you want to specify it as something else then just do this: ./fetch.sh /path/to/file/IPs.list

If you run the script without any arguments, it'll use the defaults for both options. If you run it with just one argument then it assumes the argument is the bad IP filename. However, the defaults can be changed by editing the Bash script.

Examples of Use
Fetching IPs For First Time
These examples of use assume using defaults. Running the script for the first time typically doesn't take as long as there's no IPs to check.

ehansen@hometest:~/CodeDump$ ./fetch.sh
-- Bad IP Fetcher v1.0 --
Script Usage: ./fetch.sh [country list] [IP list filename]
- Country list: List of 2-character code countries to get reportedly bad IPs from.
- IP list filename: This is the output file where the IPs will be stored.
If only 1 argument is given, it is assumed to be the output filename.
A word of warning, this script may take a while as it checks every IP address to see if it is already in the ban list.
Output file: /tmp/bad_ips
Fetching 253 countries.
Use cURL: 1
[06:09:52 PM] Fetching IP list from http://www.countryipblocks.net/country-blocks/select-formats/
Starting cURL...done.
!! Elapsed time to HTML for IPs: 0:00:03
[06:09:55 PM] Fetching IPs and storing them in /tmp/bad_ips...done.
!! Elapsed time for storing IP list: 0:00:05
[06:10:00 PM] A total of 143798 blacklisted IPs were fetched, ./fetch.sh stored 143798 of them in /tmp/bad_ips, while 0 were already present.
!! Script execution time: 0:00:08
ehansen@hometest:~/CodeDump$

Getting Updates
The script checks to see if the current IP from the fetched list exists in the file already, and if not adds it. This takes longer to run due to the constant checking (mind you, the server I ran this on is a REALLY, REALLY old desktop [reaching the 10 years mark], with extremely low-end specs). Here is the output from running it a second time:

ehansen@hometest:~/CodeDump$ ./fetch.sh
-- Bad IP Fetcher v1.0 --
Script Usage: ./fetch.sh [country list] [IP list filename]
- Country list: List of 2-character code countries to get reportedly bad IPs from.
- IP list filename: This is the output file where the IPs will be stored.
If only 1 argument is given, it is assumed to be the output filename.
A word of warning, this script may take a while as it checks every IP address to see if it is already in the ban list.
Output file: /tmp/bad_ips
Fetching 253 countries.
Use cURL: 1
[05:24:13 PM] Fetching IP list from http://www.countryipblocks.net/country-blocks/select-formats/
Starting cURL...done.
!! Elapsed time to HTML for IPs: 0:00:03
[05:24:16 PM] Fetching IPs and storing them in /tmp/bad_ips...done.
!! Elapsed time for storing IP list: 0:35:36
[05:59:52 PM] A total of 143798 blacklisted IPs were fetched, ./fetch.sh stored 0 of them in /tmp/bad_ips, while 143798 were already present.
!! Script execution time: 0:35:39
ehansen@hometest:~/CodeDump$

How To Use In tcp_wrappers
Now the fun part, after all of this talking with the script. Now we get to use it.

Well, assuming the IP list is stored in /tmp/bad_ips, we will set this up to block these IPs from using SSH. All you need to do is open up /etc/hosts.deny and add this line:

sshd: /tmp/bad_ips

If the ACL starts with a / then tcp_wrappers treats it as a file and will read the IP list (each IP separated with a newline) in. Best of all there is no need to restart the system or any services, changes take effect immediately.

Note that hosts.allow takes precedence over hosts.deny. This is why I prefer iptables over tcp_wrappers, but its still not a bad firewall.

Any service that can be configured with tcp_wrappers can use this script and file.

Script / Downloads
fetch.sh - https://github.com/SecurityForUs/CodeDump/blob/master/fetch.sh

Automatically Updating Banned IPs With hosts.deny or iptables



Automatically Updating Banned IPs With hosts.deny or iptables


First let me start off by saying that this can be used for iptables with some minor tweaking, but I chose to implement this using tcp_wrappers instead (/etc/hosts.allow; hosts.deny). Main reason being is I wrote this for Rob to make his task of updating a list of banned IPs that much easier.

Requirements
Before getting started, there are some requirements. One of them being that this was written with Bash in mind, so if you use Zsh or some other shell, there's no guarantees it will work right out of the box. Secondly, cURL OR wget must be installed. Originally I wrote this with only cURL support, but also decided to work in wget since it was trivial.

Notes
There is not a whole lot of error checking, and there are areas that can be improved. I've never claimed, nor will I ever, to be a script-fu master. If what I write works, then I'm proud of myself. If not, I see how I can make it work. So, basically consider it your homework to add the line into tcp_wrappers after the list is generated. The script will be provided at the end of this post, like usual. Also, be aware that this is generated in CIDR format (which both tcp_wrapper & iptables support). The format can be changed, but that will be extra credit.

Purpose
Maintaining an ACL (access control list) can be very daunting, for one. Especially when you have to maintain the same ACL on multiple servers. You can push out a customized file for the servers and be done with it. But, how do you even populate that list? While the source for these IPs is not the de-facto, it provides a good amount to use.

Why, then, write this script? Easy. For those who want to keep an up-to-date bad IP (reported for whatever reason). Maybe you're running a network of cloud servers and want to reduce the threat of attacks.

How To Use
Throughout the rest of this article I'll assume you're using the default name of the script, fetch.sh.

So how is this script used exactly? Simple, it takes up to 2 arguments:

  • Country list

  • Bad IP filename


 

The country list argument has to be enclosed in quotes if you're wanting more than 1 originating-country's IP list. Also, the list must be in ISO format. So, for example if you want all reported IPs from Afghanistan and USA, it would be "AF US". By default all countries are fetched (see the CL variable for more).

The bad IP filename is the absolute path to the file where the IPs will be stored. By default the path (and file) is /tmp/bad_ips. If you want to specify it as something else then just do this: ./fetch.sh /path/to/file/IPs.list

If you run the script without any arguments, it'll use the defaults for both options. If you run it with just one argument then it assumes the argument is the bad IP filename. However, the defaults can be changed by editing the Bash script.

Examples of Use
Fetching IPs For First Time
These examples of use assume using defaults. Running the script for the first time typically doesn't take as long as there's no IPs to check.

ehansen@hometest:~/CodeDump$ ./fetch.sh
-- Bad IP Fetcher v1.0 --
Script Usage: ./fetch.sh [country list] [IP list filename]
- Country list: List of 2-character code countries to get reportedly bad IPs from.
- IP list filename: This is the output file where the IPs will be stored.
If only 1 argument is given, it is assumed to be the output filename.
A word of warning, this script may take a while as it checks every IP address to see if it is already in the ban list.
Output file: /tmp/bad_ips
Fetching 253 countries.
Use cURL: 1
[06:09:52 PM] Fetching IP list from http://www.countryipblocks.net/country-blocks/select-formats/
Starting cURL...done.
!! Elapsed time to HTML for IPs: 0:00:03
[06:09:55 PM] Fetching IPs and storing them in /tmp/bad_ips...done.
!! Elapsed time for storing IP list: 0:00:05
[06:10:00 PM] A total of 143798 blacklisted IPs were fetched, ./fetch.sh stored 143798 of them in /tmp/bad_ips, while 0 were already present.
!! Script execution time: 0:00:08
ehansen@hometest:~/CodeDump$

Getting Updates
The script checks to see if the current IP from the fetched list exists in the file already, and if not adds it. This takes longer to run due to the constant checking (mind you, the server I ran this on is a REALLY, REALLY old desktop [reaching the 10 years mark], with extremely low-end specs). Here is the output from running it a second time:

ehansen@hometest:~/CodeDump$ ./fetch.sh
-- Bad IP Fetcher v1.0 --
Script Usage: ./fetch.sh [country list] [IP list filename]
- Country list: List of 2-character code countries to get reportedly bad IPs from.
- IP list filename: This is the output file where the IPs will be stored.
If only 1 argument is given, it is assumed to be the output filename.
A word of warning, this script may take a while as it checks every IP address to see if it is already in the ban list.
Output file: /tmp/bad_ips
Fetching 253 countries.
Use cURL: 1
[05:24:13 PM] Fetching IP list from http://www.countryipblocks.net/country-blocks/select-formats/
Starting cURL...done.
!! Elapsed time to HTML for IPs: 0:00:03
[05:24:16 PM] Fetching IPs and storing them in /tmp/bad_ips...done.
!! Elapsed time for storing IP list: 0:35:36
[05:59:52 PM] A total of 143798 blacklisted IPs were fetched, ./fetch.sh stored 0 of them in /tmp/bad_ips, while 143798 were already present.
!! Script execution time: 0:35:39
ehansen@hometest:~/CodeDump$

How To Use In tcp_wrappers
Now the fun part, after all of this talking with the script. Now we get to use it.

Well, assuming the IP list is stored in /tmp/bad_ips, we will set this up to block these IPs from using SSH. All you need to do is open up /etc/hosts.deny and add this line:

sshd: /tmp/bad_ips

If the ACL starts with a / then tcp_wrappers treats it as a file and will read the IP list (each IP separated with a newline) in. Best of all there is no need to restart the system or any services, changes take effect immediately.

Note that hosts.allow takes precedence over hosts.deny. This is why I prefer iptables over tcp_wrappers, but its still not a bad firewall.

Any service that can be configured with tcp_wrappers can use this script and file.

Script / Downloads
fetch.sh - https://github.com/SecurityForUs/CodeDump/blob/master/fetch.sh

Install DenyHosts on a CentOS box


Install DenyHosts on a CentOS box


 


The world is full of bad people trying to get into your Linux server (type lastb as root to find out a little more.. it may take a while, but it'll give you a list of bad logins.. the usernames they tried, the ips they're coming from, etc..).

So - you need to catch and block these people, then let others know about it. While we're at it, we'll download a list of ips that others have found trying to log into their servers.. install DenyHosts.


yum install denyhosts


If yum can't find it, install the epel repo:
rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm


Then use yum to install denyhosts as shown above..

After it's installed, add your ip address to /etc/hosts.allow so we don't get locked out
ALL: 209.xx.xx.xx
ALL: 209.xx.xx.xx
ALL: 72.xx.xx.xx
ALL: 71.xx.xx.xx


Edit the denyhosts.cfg located in /etc/denyhosts/ and configure it to your liking. Here are things that we've edited in the past:
ADMIN_EMAIL = hosting@iqnection.com, rkennedy@iqnection.com
BLOCK_SERVICE = ALL
SYNC_SERVER = http://xmlrpc.denyhosts.net:9911
SYNC_INTERVAL = 1h
SYNC_UPLOAD = yes
SYNC_DOWNLOAD = yes
DENY_THRESHOLD_ROOT = 3


Edit the WORK_DIR/allowed-hosts file and add these lines:
(WORK_DIR is sometimes /var/lib/denyhosts/)
# Don't block office Fios or comcast lines
72.xx.xx.xx
71.xx.xx.xx
# Don't block nagios box
209.xx.xx.xx
# Don't block keyserver
209.xx.xx.xx


Ok, now configure it to run on startup:
chkconfig denyhosts on


Start denyhosts:
service denyhosts start

Install DenyHosts on a CentOS box


Install DenyHosts on a CentOS box


 


The world is full of bad people trying to get into your Linux server (type lastb as root to find out a little more.. it may take a while, but it'll give you a list of bad logins.. the usernames they tried, the ips they're coming from, etc..).

So - you need to catch and block these people, then let others know about it. While we're at it, we'll download a list of ips that others have found trying to log into their servers.. install DenyHosts.


yum install denyhosts


If yum can't find it, install the epel repo:
rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm


Then use yum to install denyhosts as shown above..

After it's installed, add your ip address to /etc/hosts.allow so we don't get locked out
ALL: 209.xx.xx.xx
ALL: 209.xx.xx.xx
ALL: 72.xx.xx.xx
ALL: 71.xx.xx.xx


Edit the denyhosts.cfg located in /etc/denyhosts/ and configure it to your liking. Here are things that we've edited in the past:
ADMIN_EMAIL = hosting@iqnection.com, rkennedy@iqnection.com
BLOCK_SERVICE = ALL
SYNC_SERVER = http://xmlrpc.denyhosts.net:9911
SYNC_INTERVAL = 1h
SYNC_UPLOAD = yes
SYNC_DOWNLOAD = yes
DENY_THRESHOLD_ROOT = 3


Edit the WORK_DIR/allowed-hosts file and add these lines:
(WORK_DIR is sometimes /var/lib/denyhosts/)
# Don't block office Fios or comcast lines
72.xx.xx.xx
71.xx.xx.xx
# Don't block nagios box
209.xx.xx.xx
# Don't block keyserver
209.xx.xx.xx


Ok, now configure it to run on startup:
chkconfig denyhosts on


Start denyhosts:
service denyhosts start

Install DenyHosts on a CentOS box



Install DenyHosts on a CentOS box


 

 


The world is full of bad people trying to get into your Linux server (type lastb as root to find out a little more.. it may take a while, but it'll give you a list of bad logins.. the usernames they tried, the ips they're coming from, etc..).

So - you need to catch and block these people, then let others know about it. While we're at it, we'll download a list of ips that others have found trying to log into their servers.. install DenyHosts.
yum install denyhosts

 

If yum can't find it, install the epel repo:
rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm

Then use yum to install denyhosts as shown above..

After it's installed, add your ip address to /etc/hosts.allow so we don't get locked out
ALL: 209.xx.xx.xx
ALL: 209.xx.xx.xx
ALL: 72.xx.xx.xx
ALL: 71.xx.xx.xx

Edit the denyhosts.cfg located in /etc/denyhosts/ and configure it to your liking. Here are things that we've edited in the past:
ADMIN_EMAIL = hosting@iqnection.com, rkennedy@iqnection.com
BLOCK_SERVICE = ALL
SYNC_SERVER = http://xmlrpc.denyhosts.net:9911
SYNC_INTERVAL = 1h
SYNC_UPLOAD = yes
SYNC_DOWNLOAD = yes
DENY_THRESHOLD_ROOT = 3

Edit the WORK_DIR/allowed-hosts file and add these lines:
(WORK_DIR is sometimes /var/lib/denyhosts/)
# Don't block office Fios or comcast lines
72.xx.xx.xx
71.xx.xx.xx
# Don't block nagios box
209.xx.xx.xx
# Don't block keyserver
209.xx.xx.xx

Ok, now configure it to run on startup:
chkconfig denyhosts on

Start denyhosts:
service denyhosts start

Install DenyHosts on a CentOS box



Install DenyHosts on a CentOS box


 

 


The world is full of bad people trying to get into your Linux server (type lastb as root to find out a little more.. it may take a while, but it'll give you a list of bad logins.. the usernames they tried, the ips they're coming from, etc..).

So - you need to catch and block these people, then let others know about it. While we're at it, we'll download a list of ips that others have found trying to log into their servers.. install DenyHosts.
yum install denyhosts

 

If yum can't find it, install the epel repo:
rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm

Then use yum to install denyhosts as shown above..

After it's installed, add your ip address to /etc/hosts.allow so we don't get locked out
ALL: 209.xx.xx.xx
ALL: 209.xx.xx.xx
ALL: 72.xx.xx.xx
ALL: 71.xx.xx.xx

Edit the denyhosts.cfg located in /etc/denyhosts/ and configure it to your liking. Here are things that we've edited in the past:
ADMIN_EMAIL = hosting@iqnection.com, rkennedy@iqnection.com
BLOCK_SERVICE = ALL
SYNC_SERVER = http://xmlrpc.denyhosts.net:9911
SYNC_INTERVAL = 1h
SYNC_UPLOAD = yes
SYNC_DOWNLOAD = yes
DENY_THRESHOLD_ROOT = 3

Edit the WORK_DIR/allowed-hosts file and add these lines:
(WORK_DIR is sometimes /var/lib/denyhosts/)
# Don't block office Fios or comcast lines
72.xx.xx.xx
71.xx.xx.xx
# Don't block nagios box
209.xx.xx.xx
# Don't block keyserver
209.xx.xx.xx

Ok, now configure it to run on startup:
chkconfig denyhosts on

Start denyhosts:
service denyhosts start

Wednesday, March 3, 2010

check banned ip address in Linux



check banned ip address in Linux




How do I find or check IP's that are currently banned using iptables command in Linux? How do I verify that IP address 1.2.3.4 is banned or not in Linux?

The correct syntax to block an IP address under Linux using iptables is as follows:
 
/sbin/iptables -A INPUT -s BAN-IP-ADDRESS -j DROP
/sbin/iptables -A INPUT -s BAN-IP-ADDRESS/MASK -j DROP

Open a command-line terminal (select Applications > Accessories > Terminal), or login to remote server using the ssh and then type the following command block an ip address 1.2.3.4 as follows:

# /sbin/iptables -A INPUT -s 65.55.44.100 -j DROP

To view blocked IP address, enter:

# iptables -L INPUT -v -n

OR

# iptables -L INPUT -v -n | less

Task: Check Banned IP's Linux


Use the grep command as follows to verify that an IP address 1.2.3.4 is blocked or not:

# iptables -L INPUT -v -n | grep "1.2.3.4"

How Do I Delete or Unblock IP Address 1.2.3.4?


Use the following syntax to delete or unblock an IP address under Linux, enter:

# iptables -D INPUT -s 1.2.3.4 -j DROP

Finally, make sure you save the firewall:

# service iptables save

check banned ip address in Linux



check banned ip address in Linux




How do I find or check IP's that are currently banned using iptables command in Linux? How do I verify that IP address 1.2.3.4 is banned or not in Linux?

The correct syntax to block an IP address under Linux using iptables is as follows:
 
/sbin/iptables -A INPUT -s BAN-IP-ADDRESS -j DROP
/sbin/iptables -A INPUT -s BAN-IP-ADDRESS/MASK -j DROP

Open a command-line terminal (select Applications > Accessories > Terminal), or login to remote server using the ssh and then type the following command block an ip address 1.2.3.4 as follows:

# /sbin/iptables -A INPUT -s 65.55.44.100 -j DROP

To view blocked IP address, enter:

# iptables -L INPUT -v -n

OR

# iptables -L INPUT -v -n | less

Task: Check Banned IP's Linux


Use the grep command as follows to verify that an IP address 1.2.3.4 is blocked or not:

# iptables -L INPUT -v -n | grep "1.2.3.4"

How Do I Delete or Unblock IP Address 1.2.3.4?


Use the following syntax to delete or unblock an IP address under Linux, enter:

# iptables -D INPUT -s 1.2.3.4 -j DROP

Finally, make sure you save the firewall:

# service iptables save