<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Devon Hillard&#039;s Digital Sanctuary &#187; linux</title>
	<atom:link href="http://www.digitalsanctuary.com/tech-blog/tag/linux/feed" rel="self" type="application/rss+xml" />
	<link>http://www.digitalsanctuary.com/tech-blog</link>
	<description>Java, ATG, Seam, and related Technologies</description>
	<lastBuildDate>Mon, 30 Jan 2012 23:04:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Automated ClamAV Virus Scanning</title>
		<link>http://www.digitalsanctuary.com/tech-blog/debian/automated-clamav-virus-scanning.html</link>
		<comments>http://www.digitalsanctuary.com/tech-blog/debian/automated-clamav-virus-scanning.html#comments</comments>
		<pubDate>Wed, 27 Jan 2010 00:07:57 +0000</pubDate>
		<dc:creator>Devon</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[RedHat]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://www.digitalsanctuary.com/tech-blog/?p=531</guid>
		<description><![CDATA[Automating Linux Anti-Virus Using ClamAV and Cron Thankfully Linux isn&#8217;t a platform which has a significant problem with Viruses, however it is always better to be safe than sorry. Luckily ClamAV is an excellent free anti-virus solution for Linux servers. &#8230; <a href="http://www.digitalsanctuary.com/tech-blog/debian/automated-clamav-virus-scanning.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h1>Automating Linux Anti-Virus Using ClamAV and Cron</h1>
<p>Thankfully Linux isn&#8217;t a platform which has a significant problem with Viruses, however it is always better to be safe than sorry.  Luckily ClamAV is an excellent free anti-virus solution for Linux servers.  However, at least on RedHat Enterprise 5 (RHEL5) the default install doesn&#8217;t offer any automated scanning and alerting.  So here is what I&#8217;ve done:</p>
<p>The following steps assume you are using RHEL5, but should apply to other Linux distributions as well.</p>
<h2>First, you&#8217;ll want to install ClamAV:</h2>
<pre class="brush: bash; light: true; title: ; notranslate">
yum install clamav clamav-db clamd
/etc/init.d/clamd start
</pre>
<p>On RHEL5 at least this automatically sets up a daily cron job that uses freshclam to update the virus definitions, so that&#8217;s good.</p>
<p>Next I recommend removing the test virus files, although you can save this until after you test the rest of the setup:</p>
<pre class="brush: bash; light: true; title: ; notranslate">
rm -rf /usr/share/doc/clamav-0.95.3/test/
</pre>
<p>Now we want to setup our automation.  I have a daily cron job that scans the entire server which can take several minutes, and then an hourly cron job that only scans files which were created or modified within the last hour.  This should provide rapid notification of any infection without bogging your server down for 5 minutes every hour.  The hourly scans run in a couple of seconds.</p>
<p>Each scanning script then checks the scan logs to see if there were any infected files found, and if so immediately sends you a notification e-mail (you could set this address to your mobile phone&#8217;s SMS account if you wanted).</p>
<h2>The Daily Scan:</h2>
<pre class="brush: bash; light: true; title: ; notranslate">
emacs /etc/cron.daily/clamscan_daily
</pre>
<p>Paste in:</p>
<pre class="brush: bash; title: ; notranslate">
#!/bin/bash

# email subject
SUBJECT=&quot;VIRUS DETECTED ON `hostname`!!!&quot;
# Email To ?
EMAIL=&quot;me@domain.com&quot;
# Log location
LOG=/var/log/clamav/scan.log

check_scan () {

	# Check the last set of results. If there are any &quot;Infected&quot; counts that aren't zero, we have a problem.
	if [ `tail -n 12 ${LOG}  | grep Infected | grep -v 0 | wc -l` != 0 ]
	then
		EMAILMESSAGE=`mktemp /tmp/virus-alert.XXXXX`
		echo &quot;To: ${EMAIL}&quot; &gt;&gt;  ${EMAILMESSAGE}
		echo &quot;From: alert@domain.com&quot; &gt;&gt;  ${EMAILMESSAGE}
		echo &quot;Subject: ${SUBJECT}&quot; &gt;&gt;  ${EMAILMESSAGE}
		echo &quot;Importance: High&quot; &gt;&gt; ${EMAILMESSAGE}
		echo &quot;X-Priority: 1&quot; &gt;&gt; ${EMAILMESSAGE}
		echo &quot;`tail -n 50 ${LOG}`&quot; &gt;&gt; ${EMAILMESSAGE}
		sendmail -t &lt; ${EMAILMESSAGE}
	fi

}

clamscan -r / --exclude-dir=/sys/ --quiet --infected --log=${LOG}

check_scan
</pre>
<pre class="brush: bash; light: true; title: ; notranslate">
chmod +x /etc/cron.daily/clamscan_daily
</pre>
<h2>The Hourly Scan:</h2>
<pre class="brush: bash; light: true; title: ; notranslate">
emacs /etc/cron.hourly/clamscan_hourly
</pre>
<p>Paste in:</p>
<pre class="brush: bash; title: ; notranslate">
#!/bin/bash

# email subject
SUBJECT=&quot;VIRUS DETECTED ON `hostname`!!!&quot;
# Email To ?
EMAIL=&quot;me@domain.com&quot;
# Log location
LOG=/var/log/clamav/scan.log

check_scan () {

	# Check the last set of results. If there are any &quot;Infected&quot; counts that aren't zero, we have a problem.
	if [ `tail -n 12 ${LOG}  | grep Infected | grep -v 0 | wc -l` != 0 ]
	then
		EMAILMESSAGE=`mktemp /tmp/virus-alert.XXXXX`
		echo &quot;To: ${EMAIL}&quot; &gt;&gt;  ${EMAILMESSAGE}
		echo &quot;From: alert@domain.com&quot; &gt;&gt;  ${EMAILMESSAGE}
		echo &quot;Subject: ${SUBJECT}&quot; &gt;&gt;  ${EMAILMESSAGE}
		echo &quot;Importance: High&quot; &gt;&gt; ${EMAILMESSAGE}
		echo &quot;X-Priority: 1&quot; &gt;&gt; ${EMAILMESSAGE}
		echo &quot;`tail -n 50 ${LOG}`&quot; &gt;&gt; ${EMAILMESSAGE}
		sendmail -t &lt; ${EMAILMESSAGE}
	fi

}

find / -not -wholename '/sys/*' -and -not -wholename '/proc/*' -mmin -61 -type f -print0 | xargs -0 -r clamscan --exclude-dir=/proc/ --exclude-dir=/sys/ --quiet --infected --log=${LOG}
check_scan

find / -not -wholename '/sys/*' -and -not -wholename '/proc/*' -cmin -61 -type f -print0 | xargs -0 -r clamscan --exclude-dir=/proc/ --exclude-dir=/sys/ --quiet --infected --log=${LOG}
check_scan
</pre>
<pre class="brush: bash; light: true; title: ; notranslate">
chmod +x /etc/cron.hourly/clamscan_hourly
</pre>
<h2>Protected System</h2>
<p>You should now have a well protected system with low impact to system performance and rapid alerting.  Anti-Virus is only one piece of protecting a server, but hopefully this makes it easy to implement for everyone.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.digitalsanctuary.com/tech-blog/debian/automated-clamav-virus-scanning.html/feed</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>Setting Up SPF, SenderId, Domain Keys, and DKIM</title>
		<link>http://www.digitalsanctuary.com/tech-blog/debian/setting-up-spf-senderid-domain-keys-and-dkim.html</link>
		<comments>http://www.digitalsanctuary.com/tech-blog/debian/setting-up-spf-senderid-domain-keys-and-dkim.html#comments</comments>
		<pubDate>Tue, 24 Feb 2009 06:20:11 +0000</pubDate>
		<dc:creator>Devon</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Spam]]></category>
		<category><![CDATA[DKIM]]></category>
		<category><![CDATA[DomainKeys]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[SenderId]]></category>
		<category><![CDATA[SPF]]></category>

		<guid isPermaLink="false">http://www.digitalsanctuary.com/tech-blog/?p=281</guid>
		<description><![CDATA[If you run a mail server, and if you hate spam, you should setup your mail server to make use of all the best anti-spam tools available. There are two sides to spam, sending and receiving. On the receiving side, &#8230; <a href="http://www.digitalsanctuary.com/tech-blog/debian/setting-up-spf-senderid-domain-keys-and-dkim.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.digitalsanctuary.com/tech-blog/wp-content/uploads/2009/02/519906069_de5953764a_m.jpg" alt="" title="519906069_de5953764a_m" width="240" height="196" class="alignright size-full wp-image-841" />If you run a mail server, and if you hate spam, you should setup your mail server to make use of all the best anti-spam tools available.  There are two sides to spam, sending and receiving.   </p>
<p>On the receiving side, you have things like blacklists, spamassassin, bayesian filtering, and lots more.  I&#8217;ll probably cover this side of things in greater depth in another post.  </p>
<p>On the sending side, first and foremost, you have to ensure your server is not acting as an open relay, and allowing spam to be sent through it.  After that&#8217;s done, you want to be sure that e-mail you send isn&#8217;t flagged as spam by people receiving it.  And, being a good e-mail citizen, you you want to support the anti-spam standards that are out there.</p>
<p>There are four primary standards for verifying senders and servers.  </p>
<p><strong><a href="http://www.openspf.org/">Sender Policy Framework (SPF)</a></strong> &#8211; from their FAQ:</p>
<blockquote><p>Sender Policy Framework (SPF) is an attempt to control forged e-mail. SPF is not directly about stopping spam – junk email. It is about giving domain owners a way to say which mail sources are legitimate for their domain and which ones aren&#8217;t. While not all spam is forged, virtually all forgeries are spam. SPF is not anti-spam in the same way that flour is not food: it is part of the solution.</p></blockquote>
<p><strong><a href="http://www.microsoft.com/mscorp/safety/technologies/senderid/default.mspx">SenderId</a></strong> &#8211; a Microsoft technology which is very similar to SPF:</p>
<blockquote><p>The Sender ID framework, developed jointly by Microsoft and industry partners, addresses a key part of the spam problem: the difficulty of verifying a sender&#8217;s identity.</p></blockquote>
<p><strong><a href="http://en.wikipedia.org/wiki/DomainKeys">DomainKeys</a></strong> &#8211; from Wikipedia:</p>
<blockquote><p>DomainKeys is an e-mail authentication system designed to verify the DNS domain of an e-mail sender and the message integrity.</p></blockquote>
<p><strong><a href="http://en.wikipedia.org/wiki/DomainKeys">DKIM</a></strong> &#8211; an evolved form of DomainKeys, from Wikipedia:</p>
<blockquote><p>DKIM uses public-key cryptography to allow the sender to electronically sign legitimate emails in a way that can be verified by recipients. Prominent email service providers implementing DKIM (or its slightly different predecessor, DomainKeys) include Yahoo and Gmail. Any mail from these domains should carry a DKIM signature, and if the recipient knows this, they can discard mail that hasn&#8217;t been signed, or that has an invalid signature.</p></blockquote>
<p>SenderId is primarily used by Microsoft mail services like Hotmail/MSN, while DomainKeys and DKIM are primarily used by Yahoo.  SPF is used by many mail services.</p>
<p>I&#8217;m going to walk you through setting up these anti-spam technologies.  I will be setting them up for my domain, digitalsanctuary.com, and using my mail server, which is postfix running on Debian.  Your setup and requirements may vary.<br />
<span id="more-281"></span></p>
<p>Let&#8217;s start with SPF.  First, you need generate an SPF record for your domain(s), that essentially lists what mail servers are allowed to send mail from that domain.  The easiest way to set up the SPF record is with a tool, like this <a href="http://old.openspf.org/wizard.html?mydomain=example.com&#038;submit=Go%21">online wizard</a>.</p>
<p>First, I type in my domain name, and press the &#8220;Begin&#8221; button.  The setup for digitalsanctuary.com is actually very simple.  I only run one mail server.  It runs on the same IP as my DNS A record for digitalsanctuary.com, and it&#8217;s the MX record for the domain as well.  I don&#8217;t send e-mail through other mail servers.  So my SPF record looks like this:</p>
<blockquote><p>&#8220;v=spf1 a mx ~all&#8221;</p></blockquote>
<p>Which says that mail from @digitalsanctuary.com can only come from the A or MX record IP addresses for the digitalsanctuary.com domain.  Using the wizard you can setup your own domain SPF tuned to your needs.  Once you have the record, you need to add it as a TXT entry in your DNS.  Instructions are on the lower part of the SPF wizard I pointed you to.  I use SoftLayer&#8217;s DNS servers, and on their web admin, I had to enter a &#8220;@&#8221; in the NAME field for the record for it to work correctly.  Once that&#8217;s done, you can verify that it shows up correctly using a DNS query:</p>
<blockquote><p>
Motoko:~ modoc$ dig digitalsanctuary.com TXT</p>
<p>; <<>> DiG 9.4.2-P2 <<>> digitalsanctuary.com TXT<br />
;; global options:  printcmd<br />
;; Got answer:<br />
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 36859<br />
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0</p>
<p>;; QUESTION SECTION:<br />
;digitalsanctuary.com.		IN	TXT</p>
<p>;; ANSWER SECTION:<br />
digitalsanctuary.com.	796	IN	TXT	"v=spf1 a mx -all"</p>
<p>;; Query time: 8 msec<br />
;; SERVER: 192.168.1.1#53(192.168.1.1)<br />
;; WHEN: Sun Feb 22 22:40:48 2009<br />
;; MSG SIZE  rcvd: 67
</p></blockquote>
<p>If you see your SPF record showing up in the Answer Section, then it should be working.</p>
<p>You can further test this by sending e-mail to <a href="mailto:check-auth@verifier.port25.com">check-auth@verifier.port25.com</a> which will send you a reply with a detailed breakdown of various spam checks.</p>
<p>The reply at this point, should look like this:</p>
<blockquote><p>Summary of Results<br />
==========================================================<br />
SPF check:          pass<br />
DomainKeys check:   neutral<br />
DKIM check:         neutral<br />
Sender-ID check:    pass<br />
SpamAssassin check: ham</p></blockquote>
<p>There&#8217;s the SPF check pass, and wait!  There&#8217;s also a Sender-ID check pass.  How did that happen?  SenderId is very similar to SPF.  You can read about the differences <a href="http://www.openspf.org/SPF_vs_Sender_ID">here</a> (be aware that the openspf folks have a very specific view point on the topic).  Essentially they use the same DNS record syntax, and both systems are used to check the validity of the sending server based on who&#8217;s sending it, however they match who&#8217;s sending the mail at different layers of the SMTP stack.  SPF uses the &#8220;MAIL FROM&#8221; data from the &#8220;envelope&#8221; layer which is passed as a header value during the SMTP communication.  SenderId instead uses the &#8220;best&#8221; address from the list of address headers in the message itself.  If you aren&#8217;t a SMTP expert, that sounds pretty confusing.  Luckily for most of you, the difference really doesn&#8217;t matter.  Your MAIL FROM envelope value, and the From address header, will typically be the same.  If your outgoing mail system is more complex than this, then you&#8217;re likely enough of an SMTP expert to understand the difference, and setup a separate SenderId DNS record.  For the rest of us, we&#8217;ve just killed two birds with one stone.</p>
<p>At this point you&#8217;ll probably want to register your SPF record as your SenderId record with Microsoft.  You can do that here:  <a href="https://support.msn.com/eform.aspx?productKey=senderid&#038;page=support_senderid_options_form_byemail&#038;ct=eformts&#038;scrx=1">https://support.msn.com/eform.aspx?productKey=senderid&#038;page=support_senderid_options_form_byemail&#038;ct=eformts&#038;scrx=1</a>.</p>
<p>Next, let&#8217;s tackle DKIM.  We get another two for one deal here, since DKIM is the evolution of DomainKeys.  I recommend using this <a href="http://dkimproxy.sourceforge.net/" target="_new">guide to install DKIMProxy</a>.  You need to install a number of Perl modules, listed on that page, and I suggest using CPAN to do so.  While CPAN isn&#8217;t perfect, it does handle a lot of the dependancies for you.</p>
<p>You basically need to install the following Perl modules:</p>
<ul>
<li>Crypt::OpenSSL::RSA</li>
<li>Digest::SHA</li>
<li>Digest::SHA1</li>
<li>Error</li>
<li>Mail::Address</li>
<li>MIME::Base64</li>
<li>Net::DNS</li>
<li>Net::Server</li>
<li>Mail::DKIM</li>
</ul>
<p>Then you&#8217;ll need to download the DKIMProxy software, I used version 1.1.  Follow the build instructions in the guide I linked to above.  Once it&#8217;s built, you continue to follow the guide and create your public and private keys.  Then add the public key into the DNS for your domain.  Then, instead of passing everything in as arguments to dkimproxy.out, I go into this directory (assuming you used the install location in the guide): /usr/local/dkimproxy/etc/ and copy dkimproxy_out.conf.example to dkimproxy_out.conf.  Then edit that file and setup your keyfile location, domain, and other changes if needed.</p>
<p>Assuming you copied over the example control script into /etc/init.d/, you can test your setup and start dkimproxy, by typing:  /etc/init.d/dkimproxy start</p>
<p>Assuming it starts up cleanly, you&#8217;re ready to configure Postfix to use dkimproxy to sign outgoing messages.  You may currently be sending mail to your mail sever on port 25, but we can&#8217;t simply sign all messages delivered to port 25, since that&#8217;s where all your incoming mail arrives as well.  So we&#8217;re going to setup postfix to listen of port 587 as well.  When we send outgoing e-mail, it will go to port 587, and then will be run through the dkimproxy filter to be signed, before being sent out.</p>
<p>Use this guide: <a href="http://dkimproxy.sourceforge.net/postfix-outbound-howto.html" target="_new">Setting up the outbound proxy with Postfix</a> to set things up.  Once you&#8217;ve configured postfix, reload the postfix configuration.</p>
<p>Now you&#8217;ll want to ensure that your mail client is pointed to port 587 instead of port 25.</p>
<p>Next, send another test e-mail to  <a href="mailto:check-auth@verifier.port25.com">check-auth@verifier.port25.com</a>.  Your reply should look like this:</p>
<blockquote><p>Summary of Results<br />
==========================================================<br />
SPF check:          pass<br />
DomainKeys check:   pass<br />
DKIM check:         pass<br />
Sender-ID check:    pass<br />
SpamAssassin check: ham</p></blockquote>
<p>If it looks like that, then you&#8217;re all set!  You&#8217;ve successfully implemented the four major anti-spam mail sending standards.  Congratulations!!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.digitalsanctuary.com/tech-blog/debian/setting-up-spf-senderid-domain-keys-and-dkim.html/feed</wfw:commentRss>
		<slash:comments>36</slash:comments>
		</item>
		<item>
		<title>Why I love Debian (and PostgreSQL)</title>
		<link>http://www.digitalsanctuary.com/tech-blog/debian/why-i-love-debian-and-postgresql.html</link>
		<comments>http://www.digitalsanctuary.com/tech-blog/debian/why-i-love-debian-and-postgresql.html#comments</comments>
		<pubDate>Wed, 18 Jun 2008 00:53:39 +0000</pubDate>
		<dc:creator>Devon</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[postgres]]></category>

		<guid isPermaLink="false">http://www.digitalsanctuary.com/tech-blog/?p=131</guid>
		<description><![CDATA[I woke up this morning, got online through my new UMTS/HSPDA modem, and discovered that one of my servers had a load average of 239+ Not the best way to start the day. Turns out an rsync backup job between &#8230; <a href="http://www.digitalsanctuary.com/tech-blog/debian/why-i-love-debian-and-postgresql.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I woke up this morning, got online through my new UMTS/HSPDA modem, and discovered that one of my servers had a load average of 239+</p>
<p><img src="http://www.digitalsanctuary.com/tech-blog/wp-content/uploads/2008/06/picture-1.jpg" alt="" title="picture-1" width="462" height="44" class="alignnone size-full wp-image-132" /></p>
<p>Not the best way to start the day.  </p>
<p>Turns out an rsync backup job between two servers had gone nuts and was spinning them up through the roof.  A couple
<pre>sudo killall rsync</pre>
<p> commands, and everything started settling down.  </p>
<p>What&#8217;s important to note is that while the CPU was pegged, and the load average was over 200, I was still able ssh in, run top, ps, netstat, and navigate around looking at log files, with very little delay.  It was just a little slow, but no more than a second wait for anything.  </p>
<p>Also, all of my apps which used MySQL as their backend were all dead, with &#8220;database refused connection&#8221; errors.  All of my apps which used PostgreSQL as their backend were a little slow, but were all still up and functioning without errors.</p>
<p>So, Debian and PostgreSQL for the win!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.digitalsanctuary.com/tech-blog/debian/why-i-love-debian-and-postgresql.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using IPTables to Prevent SSH Brute Force Attacks</title>
		<link>http://www.digitalsanctuary.com/tech-blog/debian/using-iptables-to-prevent-ssh-brute-force-attacks.html</link>
		<comments>http://www.digitalsanctuary.com/tech-blog/debian/using-iptables-to-prevent-ssh-brute-force-attacks.html#comments</comments>
		<pubDate>Sun, 25 May 2008 06:11:28 +0000</pubDate>
		<dc:creator>Devon</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://www.digitalsanctuary.com/tech-blog/?p=119</guid>
		<description><![CDATA[If you have a server with a world facing ssh server, you&#8217;ve probably seen brute force attacks in your logs. Some machine starts hammering your ssh server, trying all sorts of logins (staff, root, a, admin, etc&#8230;) over and over &#8230; <a href="http://www.digitalsanctuary.com/tech-blog/debian/using-iptables-to-prevent-ssh-brute-force-attacks.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you have a server with a world facing ssh server, you&#8217;ve probably seen brute force attacks in your logs.  Some machine starts hammering your ssh server, trying all sorts of logins (staff, root, a, admin, etc&#8230;) over and over and over again.</p>
<p>This is bad on a lot of fronts.</p>
<p>I use two simple iptables rules to block any IP address who has made more than 3 ssh connections or attempted connections within the past 3 minutes.  So your would-be brute force attacker, gets three tries, and then is locked out for a minimum of three minutes.  However, since 99% of the attacks are run by an automated bot, it will either: give up after the connection is refused multiple times, or it will keep hammering away on the closed door, which keeps the running count of attempted connections in the past 3 minutes over 3, keeping the door closed.</p>
<p>First:</p>
<p><code>iptables -I INPUT -i eth1 -p tcp -m tcp --dport 22 -m state --state NEW -m recent --set --name DEFAULT --rsource</code></p>
<p>Then run:</p>
<p><code>iptables -I INPUT -i eth1 -p tcp -m tcp --dport 22 -m state --state NEW -m recent --update --seconds 180 --hitcount 4 --name DEFAULT --rsource -j DROP</code></p>
<p>I&#8217;d also recommend using the script in my post on <a href="http://www.digitalsanctuary.com/tech-blog/debian/how-to-block-an-ip-in-linux.html" target="_new">blocking IP addresses using iptables </a>to deal with any persistent folks, or people poking too hard on your web site, or other services.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.digitalsanctuary.com/tech-blog/debian/using-iptables-to-prevent-ssh-brute-force-attacks.html/feed</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>How to block an IP in Linux</title>
		<link>http://www.digitalsanctuary.com/tech-blog/debian/how-to-block-an-ip-in-linux.html</link>
		<comments>http://www.digitalsanctuary.com/tech-blog/debian/how-to-block-an-ip-in-linux.html#comments</comments>
		<pubDate>Mon, 17 Sep 2007 06:20:48 +0000</pubDate>
		<dc:creator>Devon</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://www.digitalsanctuary.com/tech-blog/security/how-to-block-an-ip-in-linux.html</guid>
		<description><![CDATA[I run Debian on my server, and I often find that my server is being attacked by other computers. Brute force SSH attacks, viruses scanning for the ability to spread, things like that. I&#8217;ll go into the SSH brute force &#8230; <a href="http://www.digitalsanctuary.com/tech-blog/debian/how-to-block-an-ip-in-linux.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I run Debian on my server, and I often find that my server is being attacked by other computers.  Brute force SSH attacks, viruses scanning for the ability to spread, things like that.  I&#8217;ll go into the SSH brute force defenses in a later post, but for now I&#8217;ll cover how to easily block an IP address.</p>
<p>First, I&#8217;ll assume you are already using iptables.  If you need help setting that up, use Google, Debian comes with it out of the box.</p>
<p>I have a small script called &#8220;block&#8221; which looks like this:</p>
<pre class="brush: plain; title: ; notranslate">
#!/bin/bash
sudo iptables -I INPUT -s $1 -j DROP
sudo bash -c &quot;iptables-save &gt; /etc/network/iptables.save&quot;
</pre>
<p>Whenever I find a &#8220;bad&#8221; IP in my logs or notifications, I just run:</p>
<pre class="brush: plain; title: ; notranslate">block bad.ip.add.18</pre>
<p>Substituting the bad ip for that nonesense above.  This adds it to the list of IP address which iptables will simply drop any incoming packets from, and saves the in memory iptables configuration, so that it is preserved through reboots.</p>
<p>Then in your /etc/network/interfaces file, just add this at the bottom:</p>
<pre class="brush: plain; title: ; notranslate">post-up iptables-restore /etc/network/iptables.save</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.digitalsanctuary.com/tech-blog/debian/how-to-block-an-ip-in-linux.html/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 1/23 queries in 0.005 seconds using disk: basic
Object Caching 492/547 objects using disk: basic

Served from: www.digitalsanctuary.com @ 2012-02-06 23:52:35 -->
