<?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>An It-Slave in the digital saltmine &#187; bash</title>
	<atom:link href="http://www.it-slav.net/blogs/category/bash/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.it-slav.net/blogs</link>
	<description>Another Blog from a Geek that has no life</description>
	<lastBuildDate>Tue, 10 Jan 2012 20:27:48 +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>Anonymise a network segment using TOR and OpenBSD</title>
		<link>http://www.it-slav.net/blogs/2012/01/10/anonymise-a-network-segment-using-tor-and-openbsd/</link>
		<comments>http://www.it-slav.net/blogs/2012/01/10/anonymise-a-network-segment-using-tor-and-openbsd/#comments</comments>
		<pubDate>Tue, 10 Jan 2012 20:27:48 +0000</pubDate>
		<dc:creator>peter</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[Cool things]]></category>
		<category><![CDATA[Fon]]></category>
		<category><![CDATA[Geek stuff]]></category>
		<category><![CDATA[Hints]]></category>
		<category><![CDATA[it-slav.net]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[The Onion Router]]></category>
		<category><![CDATA[Tor]]></category>

		<guid isPermaLink="false">http://www.it-slav.net/blogs/?p=2067</guid>
		<description><![CDATA[Background I&#160;have a FON&#160;router which allow anyone to connect to Intenet via my network connection. I&#160;like the openess and idea behind FON but I&#160;do not want to get in trouble if someone do bad things and using my network connection. One solution is to connect the FON&#160;accesspoint to a separate network segment and let all [...]]]></description>
			<content:encoded><![CDATA[<h2>Background</h2>
<p>I&nbsp;have a FON&nbsp;router which allow anyone to connect to Intenet via my network connection. I&nbsp;like the openess and idea behind FON but I&nbsp;do not want to get in trouble if someone do bad things and using my network connection.</p>
<p>One solution is to connect the FON&nbsp;accesspoint to a separate network segment and let all traffic from that network go through TOR, the onion router.&nbsp;</p>
<p>Another feature is when I want to be anonymous on Internet I plugin my computer to that network segment.</p>
<p><span id="more-2067"></span></p>
<h2>Setup</h2>
<p>I use OpenBSD as my firewall and the first step is to download, compile and configure TOR.&nbsp;I&nbsp;downloaded the tarball from https://www.torproject.org and used the normal procedure:</p>
<pre># wget https://www.torproject.org/dist/tor-0.2.2.35.tar.gz

# tar xzvf tor-0.2.2.35.tar.gz 

# cd tor-0.2.2.35                                                                                                                                                                

# ./configure&amp;&amp;make&amp;&amp;make install</pre>
<p>&nbsp;</p>
<h2>Configure pf</h2>
<p>I use a specific ethernet interface, fxp0, which will route all traffic into tor.&nbsp;</p>
<p>&nbsp;</p>
<pre>--cut from /etc/pf.conf--

#Tor traffic

tor_if =&quot;fxp0&quot;

# Tor&#39;s TransPort

trans_port = &quot;9040&quot;

pass in quick on $tor_if inet proto udp to port domain rdr-to 127.0.0.1 port 5300 

pass in quick on $tor_if inet proto { tcp udp } to !($tor_if) rdr-to 127.0.0.1 port $trans_port

--end cut--</pre>
<h2>&nbsp;</h2>
<h2>Configure tor</h2>
<p>&nbsp;</p>
<pre># cat /usr/local/etc/tor/torrc

VirtualAddrNetwork 10.192.0.0/10

AutomapHostsOnResolve 1

TransPort 9040

DNSPort 5300

Log notice syslog

#Log debug stderr

RunAsDaemon 1</pre>
<p>&nbsp;</p>
<p>Note: I know that best practice is to let the tor process run as non root user. That requires read access to /dev/pf and I did not bother to get it working.</p>
<p>&nbsp;</p>
<h2>Dhcpd config</h2>
<p>I assume that a OpenBSD sysadmin knows how to setup dhcpd so I will just show the config addon I did to /etc/dhcpd.conf.</p>
<p>&nbsp;</p>
<pre>shared-network tor-net {

        option  domain-name &quot;it-slav-tor-net&quot;;

        option  domain-name-servers 10.1.2.1;

        option  ntp-servers 10.1.2.1;

        subnet 10.1.2.0 netmask 255.255.255.0 {

                option routers 10.1.2.1;

                range 10.1.2.100 10.1.2.200;

        }</pre>
<p>&nbsp;</p>
<p>The ip-adress of the fxp0 interface is 10.1.2.1</p>
<p>&nbsp;</p>
<h2>Start tor</h2>
<p>&nbsp;</p>
<pre># /usr/local/bin/tor

Jan 10 20:52:48.880 [notice] Tor v0.2.2.35 (git-b04388f9e7546a9f). This is experimental software. Do not rely on it for strong anonymity. (Running on OpenBSD i386)

Jan 10 20:52:48.885 [warn] It&#39;s a little hard to tell, but you seem to have Libevent 1.4.0-beta header files, whereas you have linked against Libevent 1.4.14b-stable.  This will probably make Tor crash.

Jan 10 20:52:48.886 [notice] Initialized libevent version 1.4.14b-stable using method kqueue. Good.

Jan 10 20:52:48.886 [notice] Opening Socks listener on 127.0.0.1:9050

Jan 10 20:52:48.887 [notice] Opening Transparent pf/netfilter listener on 127.0.0.1:9040

Jan 10 20:52:48.887 [notice] Opening DNS listener on 127.0.0.1:5300</pre>
<p>&nbsp;</p>
<h2>Final step</h2>
<p>Plugin your fon router and enjoy!</p>
<p>&nbsp;</p>
<h2>Links</h2>
<p>The hints to this article was found at:</p>
<ul>
<li><a href="https://trac.torproject.org/projects/tor/wiki/TheOnionRouter/TransparentProxy " target="_blank">&nbsp;https://trac.torproject.org/projects/tor/wiki/TheOnionRouter/TransparentProxy&nbsp;</a></li>
</ul>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.it-slav.net%2Fblogs%2F2012%2F01%2F10%2Fanonymise-a-network-segment-using-tor-and-openbsd%2F&amp;title=Anonymise%20a%20network%20segment%20using%20TOR%20and%20OpenBSD" id="wpa2a_2"><img src="http://www.it-slav.net/blogs/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.it-slav.net/blogs/2012/01/10/anonymise-a-network-segment-using-tor-and-openbsd/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>KVM virtualization, some best practice, part 2</title>
		<link>http://www.it-slav.net/blogs/2012/01/08/kvm-virtualization-some-best-practice-part-2/</link>
		<comments>http://www.it-slav.net/blogs/2012/01/08/kvm-virtualization-some-best-practice-part-2/#comments</comments>
		<pubDate>Sun, 08 Jan 2012 11:30:19 +0000</pubDate>
		<dc:creator>peter</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[Cool things]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[Geek stuff]]></category>
		<category><![CDATA[graph]]></category>
		<category><![CDATA[KVM]]></category>
		<category><![CDATA[op5]]></category>
		<category><![CDATA[op5 Monitor]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[Virtualization]]></category>

		<guid isPermaLink="false">http://www.it-slav.net/blogs/?p=2201</guid>
		<description><![CDATA[Background It really annoyed me that the iowait at the cpu on the Dom 0 system was approximatly 50% when the 4 virtual system was doing more or less nothing. I showed my earlier blogpost about VM virtualization to our sysadmin at op5. He gave me a couple of more hints that really make a [...]]]></description>
			<content:encoded><![CDATA[<h2>Background</h2>
<p>It really annoyed me that the iowait at the cpu on the Dom 0 system was approximatly 50% when the 4 virtual system was doing more or less nothing.</p>
<p>I showed my<a href="http://www.it-slav.net/blogs/2012/01/01/kvm-virtualization-some-best-practice/" target="_blank"> earlier blogpost</a> about VM virtualization to our sysadmin at op5. He gave me a couple of more hints that really make a big difference, the best part is that they are real simple to implement.</p>
<p>I also noticed that I forgot some parts in the previous article that was obvius to me.</p>
<p><span id="more-2201"></span></p>
<h3>&nbsp;</h3>
<h3>#1 use virtio drivers if possible</h3>
<p>This is probably the single most important step to get the most out of the hardware.</p>
<p>When the virtual systems wants to communicate with the hardware it uses drivers, if the drivers are simulating hardware to give a service to the virtual operating system it adds alot of overhed. A simple example:</p>
<ul>
<li>The virtual system wants to access the disk</li>
<li>The virtual system communicates via the driver to the hardware</li>
<li>The hardware is not real hardware, it is emulated hardware in sofware&nbsp;</li>
<li>The software that emulates the hardware sends the I/O to the Dom 0 virtualization engine</li>
<li>The Virtualization engine verifies that the access is ok, translate it to real hardware call via its driver</li>
<li>The hardware do the operation and send the result back up via all the steps to the virtual operating system</li>
</ul>
<p>All this transalations and software calls take alot of resources from the machine.</p>
<p>By using virtual drivers, so that there is no need to emulate hardware, many of the steps can be skipped or done with much less penalty. However not all operating system have virtio drivers.</p>
<h3>&nbsp;</h3>
<h3>#2 load the virtio modules in Dom 0</h3>
<p>This is a real god hint I got from our sysadmin, load the virtual drivers in the Dom 0 system asweell. According to him, the virtual drivers in the Dom 0 and Dom U:s communicate and makes the I/O much more effective. I have not found any information about this at any place so I was sceptical but I tried it.</p>
<pre># modprobe virtio_balloon
# modprobe virtio_blk
# modprobe virtio_net
# modprobe virtio_pci</pre>
<p>The virtual systems need to be rebooted as far as I know before the loaded drivers will have any effect.</p>
<p>At first no change at all, but after few hours I noticed that CPU idle raized and the iowait went from at least 50% down to below 5%.</p>
<p>A nice graph, created by <a href="http://www.op5.com/network-monitoring/op5-monitor/" target="_blank">op5 Monitor</a> showing the difference:</p>
<p><img alt="" height="505" src="http://www.it-slav.net/blogs/wp-content/uploads/Screen Shot 2012-01-05 at 10_24_45 AM.png" width="604" /></p>
<p>I loaded the virtual drivers approximately 4 pm, and it took until 10 pm before the performance boost showed up.</p>
<p>The correct way of making sure that the drivers are loaded directly would be to remake the kernel but I&#39;m lazy so I have just added the module load to /etc/rc.local</p>
<h2>&nbsp;</h2>
<h2>Conclusions</h2>
<p>It is always important to monitor systems. When doing changes it is not possible know if the changes do have any impact if you do not monitor and follow up how and if the changes does anything.</p>
<p>My former statement that KVM is not mature is more true then I have thought. The knowledge how to tune and maintain KVM systems seems to be like black art where the knowledge is not documented and well spread. I have read the RedHat virtualization and I have not found anything about that the virtual drivers should be loaded on the Dom0 system.</p>
<p>If there is anyone out there that has some documentation or more hints, please send me the link or comment this blogpost.</p>
<p>Links:</p>
<ul>
<li><a href="http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Virtualization_Host_Configuration_and_Guest_Installation_Guide/index.html" target="_blank">RedHa</a>t virtualization doc</li>
<li><a href="http://www.op5.com/network-monitoring/op5-monitor/" target="_blank">op5 Monitor</a> that monitor and creates nice graphs</li>
<li><a href="http://exchange.nagios.org/directory/Plugins/System-Metrics/CPU-Usage-and-Load/check_cpu_stats-2Esh/details" style="color: rgb(200, 0, 0); font-family: arial, verdana, sans-serif; text-align: justify; " target="_blank">check_cpu_stats</a>&nbsp;Nagios plugin to monitor cpustat</li>
</ul>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.it-slav.net%2Fblogs%2F2012%2F01%2F08%2Fkvm-virtualization-some-best-practice-part-2%2F&amp;title=KVM%20virtualization%2C%20some%20best%20practice%2C%20part%202" id="wpa2a_4"><img src="http://www.it-slav.net/blogs/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.it-slav.net/blogs/2012/01/08/kvm-virtualization-some-best-practice-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>KVM virtualization, some best practice, part 1</title>
		<link>http://www.it-slav.net/blogs/2012/01/01/kvm-virtualization-some-best-practice/</link>
		<comments>http://www.it-slav.net/blogs/2012/01/01/kvm-virtualization-some-best-practice/#comments</comments>
		<pubDate>Sun, 01 Jan 2012 20:02:05 +0000</pubDate>
		<dc:creator>peter</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[Cool things]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[Geek stuff]]></category>
		<category><![CDATA[Hints]]></category>
		<category><![CDATA[it-slav.net]]></category>
		<category><![CDATA[Links]]></category>
		<category><![CDATA[Nagios]]></category>
		<category><![CDATA[op5]]></category>
		<category><![CDATA[op5 Monitor]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://www.it-slav.net/blogs/?p=2181</guid>
		<description><![CDATA[Background As an it slave, I have the same problems as most datacenters: Running out of space because of more and more machines get into the datacenter Overheating Powerconsumption Added to the &#34;normal&#34; datacenter problems, I also have to deal with: Wife acceptance Noice, my neighbours has complained about the noice outside my basement. To [...]]]></description>
			<content:encoded><![CDATA[<h2>Background</h2>
<p>As an it slave, I have the same problems as most datacenters:</p>
<ul>
<li>Running out of space because of more and more machines get into the datacenter</li>
<li>Overheating</li>
<li>Powerconsumption</li>
</ul>
<p>Added to the &quot;normal&quot; datacenter problems, I also have to deal with:</p>
<ul>
<li>Wife acceptance</li>
<li>Noice, my neighbours has complained about the noice outside my basement.</li>
</ul>
<p>To address this issues I will run a consolidation project to get fewer machines by using virtualization. As virtualization engine, KVM is choosed.</p>
<p>This article will describe some pitfalls I run into and how I solved them.</p>
<p><span id="more-2181"></span></p>
<h2>&nbsp;</h2>
<h2>&nbsp;</h2>
<h2>KVM plattform</h2>
<p>KVM seems to be the future for virtualization within the Linux area since Xen has done some mistakes.</p>
<p>As I have good experience of running CentOS and has KVM included I decided to use CentOS as the plattform for my virtualization.</p>
<p>&nbsp;</p>
<h2>Issues</h2>
<h3>Bridge network</h3>
<p>To let the virtual boxes has full access to the network you need create a network bridge, it is rather straightforward and well documented so I will skip this part. I used the documentation on Red Hat customer support. Why KVM requires a bridge instead of a normal NIC is another question <img src='http://www.it-slav.net/blogs/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<h3>&nbsp;</h3>
<h3>Snapshots</h3>
<p>One handy feature with virtualization is that the virtual systems can be one big fat file at the physical host, this gives the possibility to make full backups without turning the system down a.k.a snapshots.</p>
<p>However to get snapshot to work the filetype must be qcow2 and raw is the default format.</p>
<p>It is possible to convert from raw to qcow2 format by running the command:</p>
<pre>qemu-img convert -f raw -O qcow2 &lt;virtualhost&gt;.img &lt;virtualhost&gt;.img.qcow2</pre>
<p>Remember to turn of your virtual system by running:</p>
<pre>virsh shutdown &lt;virtualhost&gt;
</pre>
<p>After the conversion:</p>
<pre>virsh edit &lt;virtualhost&gt;
</pre>
<p>modify the type and path, i.e.</p>
<pre>      &lt;driver name=&#39;qemu&#39; type=&#39;qcow2&#39; cache=&#39;none&#39;/&gt;
      &lt;source file=&#39;/var/lib/libvirt/images/web.img.qcow2&#39;/&gt;
</pre>
<p>Start your virtual system:</p>
<pre>virsh start &lt;virtualhost&gt;</pre>
<p>&nbsp;</p>
<p>Take a snapshot with:</p>
<pre>qemu-img snapshot -c &lt;snapshotname&gt; &lt;virtualhost&gt;.img.preallc.qcow2</pre>
<p>&nbsp;</p>
<p>To create a full image of your snapshot you need to compile a more resent version of qemu-img then shipped with CentOS 6.2, I download a later version and compiled it from <a href="http://git.qemu.org/qemu.git/commit/?id=51ef67270b1d10e1fcf3de7368dccad1ba0bf9d1" target="_blank">here</a>, i renamed the new to qemu.img2 and copied it to /usr/local/bin</p>
<pre>qemu-img2 convert -p -f qcow2 -O qcow2 -s &lt;snapshotname&gt; &lt;virtualhost&gt;.img.preallc.qcow2 &lt;targetpath&gt;
</pre>
<p>Beware: This command can use all your resources and may affect all your virtual systems, use nice and ionice to prevent it.</p>
<h3>&nbsp;</h3>
<h3>Disk I/O</h3>
<p>After installing just a few virtual system I noticed that my physical host got alot of I/O wait, it can be seen by using tools like top.</p>
<p>To monitor this I installed the nagios plugins:</p>
<ul>
<li>check disk io, can be found <a href="https://trac.id.ethz.ch/projects/nagios_plugins/wiki/check_diskio" target="_blank">here</a></li>
<li>check cpu stats, can be found <a href="http://exchange.nagios.org/directory/Plugins/System-Metrics/CPU-Usage-and-Load/check_cpu_stats-2Esh/details" target="_blank">here</a></li>
<li>check_libvirt, developed by <a href="http://www.op5.com" target="_blank">op5</a> and an <a href="http://www.op5.com/how-to/how-to-monitor-kvm-installation/" target="_blank">Howto </a></li>
</ul>
<p>However it seems like that though my virtual systems did more or less nothing they caused alot of disk I/O on the physical system.</p>
<p>I did some investigations and read quite many articles, fiddled and tested. The following is what worked for me in my setup.</p>
<h4>#1 Change disk scheduler</h4>
<p>The disk scheduler can be changed on runtime by modify the file:</p>
<pre>/sys/block/sda/queue/scheduler</pre>
<p>to see what scheduler you use now:</p>
<pre>cat /sys/block/sda/queue/scheduler</pre>
<p>Change sda to the device you have.</p>
<p>The scheduler that worked best for me is deadline</p>
<pre>echo deadline &gt; /sys/block/sda/queue/scheduler</pre>
<p>&nbsp;</p>
<h4>#2 Mount with noatime</h4>
<p>A feature in Unix and other Unixlike systems like Linux is that it normaly stores when a file is accessed. So one read always produce a write and if you are using raid like morroring this get worse, one reade always generate several writes. This creates alot of overhead for a feature soldom used.</p>
<p>So change /etc/fstab so it will mount the file systems with noatime.<br />
	An axample:</p>
<pre>UUID=a290aa4b-635c-45fa-b144-1fbef90b3735 /                       ext4    defaults,noatime        1 1</pre>
<p>&nbsp;</p>
<h4>#3 Preallocation disk images</h4>
<p>A real boost that is hidden in the featureset and not shown in the virtualmachine gui is using preallocation disk images. They cannot be created from the GUI so I install the virtual machine, turn it of and convert it afterwards.</p>
<pre>qemu-img convert -f qcow2 -O qcow2 -o preallocation=metadata &lt;virtualhost&gt;.img.qcow2 &lt;virtualhost&gt;.img.preallc.qcow2</pre>
<p>Change the path to new image name by editing the virtual machine settings</p>
<pre>virsh edit &lt;virtualhost&gt;</pre>
<p>&nbsp;</p>
<h2>Conclusions</h2>
<p>In my opinion it seems like KVM is still a little bit immature or at least the tools to handle it. Maybe it would be a good idea to have one linux distro focusing on beeing the best platform for virtualization.</p>
<p>I am convinced that I can get even more bang for the bucks out of my installation if I learn how to tweak it even more, so if you have any hints, do not hesitate to contact me. Preferably as a comment to this blogpost.</p>
<p>&nbsp;</p>
<h2>Referenses:</h2>
<ul>
<li><a href="http://www.op5.com/network-monitoring/op5-monitor/" target="_blank">op5 Monitor</a>, a nagios based enterprise monitor tool to monitor my environment</li>
<li><a href="http://www.op5.com/how-to/how-to-monitor-kvm-installation/" target="_blank">check_libvirt</a>, a nagios plugin done by op5 to monitor KVM</li>
<li><a href="https://trac.id.ethz.ch/projects/nagios_plugins/wiki/check_diskio" target="_blank">check_diskio</a>, a nagios plugin to monitor disk I/O</li>
<li><a href="http://exchange.nagios.org/directory/Plugins/System-Metrics/CPU-Usage-and-Load/check_cpu_stats-2Esh/details" target="_blank">check_cpu_stats</a>, a nagios plugin to monitor cpu usage rather detailed</li>
<li>Another <a href="http://itscblog.tamu.edu/improve-disk-io-performance-in-kvm/" target="_blank">blogpost</a> which helped me</li>
<li><a href="http://www.google.se/url?sa=t&amp;rct=j&amp;q=redhat%206%20kvm%20howto&amp;source=web&amp;cd=6&amp;ved=0CE0QFjAF&amp;url=http%3A%2F%2Fwww.redhat.com%2Fsummit%2F2011%2Fpresentations%2Fsummit%2Fdecoding_the_code%2Fwednesday%2Fwagner_w_420_kvm_performance_improvements_and_optimizations.pdf&amp;ei=qzT-TtvGBsyB4AS8xNmkDg&amp;usg=AFQjCNEK6OMSA4WtSs7NYj6n-jsmauwcnw&amp;cad=rja" target="_blank">KVM performance improvements and optimizations</a> &#8211; Red Hat presentation</li>
</ul>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.it-slav.net%2Fblogs%2F2012%2F01%2F01%2Fkvm-virtualization-some-best-practice%2F&amp;title=KVM%20virtualization%2C%20some%20best%20practice%2C%20part%201" id="wpa2a_6"><img src="http://www.it-slav.net/blogs/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.it-slav.net/blogs/2012/01/01/kvm-virtualization-some-best-practice/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Open ssh on the WAN inteface in OpenWRT</title>
		<link>http://www.it-slav.net/blogs/2011/04/02/open-ssh-on-the-wan-inteface-openwrt/</link>
		<comments>http://www.it-slav.net/blogs/2011/04/02/open-ssh-on-the-wan-inteface-openwrt/#comments</comments>
		<pubDate>Sat, 02 Apr 2011 08:10:53 +0000</pubDate>
		<dc:creator>peter</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[Cool things]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[Geek stuff]]></category>
		<category><![CDATA[openwrt]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://www.it-slav.net/blogs/?p=2037</guid>
		<description><![CDATA[To be able to administrate my OpenWRT&#160;router from Internet I&#160;need to open the ssh port on the Wan interface. &#160; It is real simple, just add to following to /etc/config/firewall: #open ssh on wan interface config rule&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160; option src&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; wan &#160;&#160;&#160;&#160;&#160;&#160;&#160; option dest_port&#160;&#160;&#160;&#160;&#160;&#160;&#160; 22 &#160;&#160;&#160;&#160;&#160;&#160;&#160; option target&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ACCEPT&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160; option proto&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; tcp&#160; And restart [...]]]></description>
			<content:encoded><![CDATA[<p>To be able to administrate my OpenWRT&nbsp;router from Internet I&nbsp;need to open the ssh port on the Wan interface.</p>
<p>&nbsp;</p>
<p>It is real simple, just add to following to /etc/config/firewall:</p>
<p><code>#open ssh on wan interface<br />
config rule&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; option src&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; wan<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; option dest_port&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 22<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; option target&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ACCEPT&nbsp;&nbsp;&nbsp;&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; option proto&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tcp&nbsp; </code></p>
<p>And restart the firewall:</p>
<p><code>#/etc/init.d/firewall restart</code></p>
<p>&nbsp;</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.it-slav.net%2Fblogs%2F2011%2F04%2F02%2Fopen-ssh-on-the-wan-inteface-openwrt%2F&amp;title=Open%20ssh%20on%20the%20WAN%20inteface%20in%20OpenWRT" id="wpa2a_8"><img src="http://www.it-slav.net/blogs/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.it-slav.net/blogs/2011/04/02/open-ssh-on-the-wan-inteface-openwrt/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Enable Huawei E1750 in Ubuntu 10.04</title>
		<link>http://www.it-slav.net/blogs/2010/05/23/enable-huawei-e1750-in-ubuntu-10-04/</link>
		<comments>http://www.it-slav.net/blogs/2010/05/23/enable-huawei-e1750-in-ubuntu-10-04/#comments</comments>
		<pubDate>Sun, 23 May 2010 07:10:27 +0000</pubDate>
		<dc:creator>peter</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[Cool things]]></category>
		<category><![CDATA[Geek stuff]]></category>
		<category><![CDATA[Hints]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[Huawei]]></category>

		<guid isPermaLink="false">http://www.it-slav.net/blogs/?p=1792</guid>
		<description><![CDATA[&#160; I&#8217;m the happay owner of a Huawei E1750 modem and it is real easy to get it running in Ubuntu. This guide will probably work with many other 3G USB&#160;modems. Just type from the command line: sudo apt-get install usb-modeswitch Plug in the modem Go to the Network manager and enter your Mobile Broadband [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p>I&#8217;m the happay owner of a Huawei E1750 modem and it is real easy to get it running in Ubuntu. This guide will probably work with many other 3G USB&nbsp;modems.</p>
<p>Just type from the command line:</p>
<pre>
sudo apt-get install usb-modeswitch
</pre>
<p>Plug in the modem</p>
<p>Go to the Network manager and enter your Mobile Broadband credentials and now it works!</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.it-slav.net%2Fblogs%2F2010%2F05%2F23%2Fenable-huawei-e1750-in-ubuntu-10-04%2F&amp;title=Enable%20Huawei%20E1750%20in%20Ubuntu%2010.04" id="wpa2a_10"><img src="http://www.it-slav.net/blogs/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.it-slav.net/blogs/2010/05/23/enable-huawei-e1750-in-ubuntu-10-04/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Share your internet connection</title>
		<link>http://www.it-slav.net/blogs/2010/02/12/share-your-internet-connection/</link>
		<comments>http://www.it-slav.net/blogs/2010/02/12/share-your-internet-connection/#comments</comments>
		<pubDate>Fri, 12 Feb 2010 18:32:06 +0000</pubDate>
		<dc:creator>peter</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[Cool things]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[Geek stuff]]></category>
		<category><![CDATA[Hints]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.it-slav.net/blogs/?p=1592</guid>
		<description><![CDATA[&#160; Background I&#160;was with my geekfriends at a ski resort and I&#160;managed to get an Internet connection using a cellphone. Of course I&#160;wanted to share it with my friends. As geeks we brought a switch and a couple of ethernetcables. &#160; Solution Using this script on a Ubuntu 9.10 I&#160;managed to share my connection: sudo [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<h2>Background</h2>
<p>I&nbsp;was with my geekfriends at a ski resort and I&nbsp;managed to get an Internet connection using a cellphone. Of course I&nbsp;wanted to share it with my friends. As geeks we brought a switch and a couple of ethernetcables.</p>
<p>&nbsp;</p>
<h2>Solution</h2>
<p>Using this script on a Ubuntu 9.10 I&nbsp;managed to share my connection:</p>
<pre>
sudo ifconfig eth0 10.8.16.1
sudo sysctl -w net.ipv4.ip_forward=1
sudo sysctl -w net.ipv4.conf.default.forwarding=1
sudo sysctl -w net.ipv4.conf.all.forwarding=1
sudo iptables -P FORWARD ACCEPT
sudo iptables --table nat -A POSTROUTING -o ppp0 -j MASQUERADE</pre>
<p>Conmnect everymachine with the switch and the clients just needed to use a 10.0.0.0/8 network adress and add 10.8.16.1 as default gateway and it works!</p>
<p>&nbsp;</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.it-slav.net%2Fblogs%2F2010%2F02%2F12%2Fshare-your-internet-connection%2F&amp;title=Share%20your%20internet%20connection" id="wpa2a_12"><img src="http://www.it-slav.net/blogs/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.it-slav.net/blogs/2010/02/12/share-your-internet-connection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Use Bluetooth phone to connect to Internet on Linux</title>
		<link>http://www.it-slav.net/blogs/2010/01/31/use-bluetooth-phone-to-connect-to-internet-on-linux/</link>
		<comments>http://www.it-slav.net/blogs/2010/01/31/use-bluetooth-phone-to-connect-to-internet-on-linux/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 18:50:52 +0000</pubDate>
		<dc:creator>peter</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[Cool things]]></category>
		<category><![CDATA[Geek stuff]]></category>
		<category><![CDATA[Hints]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[Bluetoth]]></category>
		<category><![CDATA[Cell Phone]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[Phone]]></category>

		<guid isPermaLink="false">http://www.it-slav.net/blogs/?p=1567</guid>
		<description><![CDATA[My laptop and cellular phone has both Bluetooth and it has annoyed me for a while that I have not managed to get a working Internet connection using Bluetooth. I have only managed to get it working with a USB&#160;cable between my phone and laptop. &#160; After some Google search and reading of man pages [...]]]></description>
			<content:encoded><![CDATA[<p>My laptop and cellular phone has both Bluetooth and it has annoyed me for a while that I have not managed to get a working Internet connection using Bluetooth. I have only managed to get it working with a USB&nbsp;cable between my phone and laptop.</p>
<p>&nbsp;</p>
<p>After some Google search and reading of man pages I finally get it working.</p>
<p><span id="more-1567"></span></p>
<p>&nbsp;</p>
<p>My setup is a <a href="http://www.it-slav.net/blogs/2009/11/19/review-nokia-e52/" target="_blank">Nokia E52</a> and a IBM T60 laptop running Ubuntu 9.10. I have tested it with a Ericsson P1i and a Dell D630 aswell and I think the guidlines below will work with many other setups. One exception is probably iPhone <img src='http://www.it-slav.net/blogs/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>&nbsp;</p>
<p>From a bash shell run:</p>
<pre>
peter@svarten:~$ sdptool search DUN
Inquiring ...
Searching for DUN on A8:7E:33:20:40:0F ...
Service Name: Dial-Up Networking
Service RecHandle: 0x10030
Service Class ID List:
  &quot;Dialup Networking&quot; (0x1103)
Protocol Descriptor List:
  &quot;L2CAP&quot; (0x0100)
  &quot;RFCOMM&quot; (0x0003)
    Channel: 5
Language Base Attr List:
  code_ISO639: 0x454e
  encoding:    0x6a
  base_offset: 0x100
Profile Descriptor List:
  &quot;Dialup Networking&quot; (0x1103)
    Version: 0x0100

peter@svarten:~$ sudo rfcomm connect 1 A8:7E:33:20:40:0F 5
[sudo] password for peter:
Connected /dev/rfcomm1 to A8:7E:33:20:40:0F on channel 5
Press CTRL-C for hangup
</pre>
<p>Now my phone asks if I accept the connection and I choose &quot;yes&quot;.</p>
<p>&nbsp;</p>
<p>And now the networkmanager has a new &quot;Mobile Broadband connection&quot;. Just choose your operator and it will work.</p>
<p>&nbsp;</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.it-slav.net%2Fblogs%2F2010%2F01%2F31%2Fuse-bluetooth-phone-to-connect-to-internet-on-linux%2F&amp;title=Use%20Bluetooth%20phone%20to%20connect%20to%20Internet%20on%20Linux" id="wpa2a_14"><img src="http://www.it-slav.net/blogs/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.it-slav.net/blogs/2010/01/31/use-bluetooth-phone-to-connect-to-internet-on-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Nagios or op5 Monitor eventhandler to start a service that has stopped</title>
		<link>http://www.it-slav.net/blogs/2009/06/15/using-nagios-or-op5-monitor-eventhandler-to-start-a-service-that-has-stopped/</link>
		<comments>http://www.it-slav.net/blogs/2009/06/15/using-nagios-or-op5-monitor-eventhandler-to-start-a-service-that-has-stopped/#comments</comments>
		<pubDate>Mon, 15 Jun 2009 19:03:01 +0000</pubDate>
		<dc:creator>peter</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[Cool things]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[Geek stuff]]></category>
		<category><![CDATA[Hints]]></category>
		<category><![CDATA[MythTV]]></category>
		<category><![CDATA[Nagios]]></category>
		<category><![CDATA[op5 Monitor]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://www.it-slav.net/blogs/?p=1138</guid>
		<description><![CDATA[Background I use MythTV quite frequently and noticed that it is instable when using sasc-ng as a decoder to decrypt encrypted DVB-T channels. So approximatly every third day the MythTVbackend server stops and need to be started again. I have wriiten an earlier article about howto monitor MythTV with Nagios or op5 Monitor so I [...]]]></description>
			<content:encoded><![CDATA[<h2>Background</h2>
<p>I use MythTV quite frequently and noticed that it is instable when using <a target="_blank" href="https://opensvn.csie.org/traccgi/sascng/">sasc-ng</a> as a decoder to decrypt encrypted DVB-T channels. So approximatly every third day the MythTVbackend server stops and need to be started again. I have wriiten an <a target="_blank" href="http://www.it-slav.net/blogs/?p=651">earlier article</a> about howto monitor MythTV with Nagios or op5 Monitor so I get noticed that it has stopped. But I need to manually start it again. This article describe howto make Nagios or op5 Monitor to start a stopped MythTVbackend. It can be used for starting almost any service.</p>
<p>I have used the examples provided by Ethan at <a target="_blank" href="http://support.nagios.com/knowledge-base/official-documentation">Nagios official documentation</a> describing <a target="_blank" href="http://nagios.sourceforge.net/docs/3_0/eventhandlers.html">eventhandlers</a>.</p>
<p>Normally it is not recommended to let a tool like Nagios or op5 Monitor start a service that has stopped, because it is probably a reason why the service has stopped and the correct procedure is to fix the root cause of the problem, not the symptom.</p>
<p>The MythTV backend runs on one machine called lala (after a character in Teletubbies) which is not the same as the Nagios or op5 Monitor server. I use nrpe to run the start script i.e.</p>
<pre>
 /etc/init.d/mythtv-backend start
</pre>
<p>There is several options here but I already setup the nrpe agent and it is simple to make Nagios or op5 Monitor to use nrpe to run a script.<span id="more-1138"></span></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h2>Implementation</h2>
<p>I used the script I found at Nagios documentation about <a target="_blank" href="http://nagios.sourceforge.net/docs/3_0/eventhandlers.html">eventhandlers</a> as a base and modiied it slightly.</p>
<p>&nbsp;</p>
<h3>At my op5 Monitor machine</h3>
<pre>
/opt/plugins/custom/restart-mythtv-lala.sh
</pre>
<pre>
#!/bin/sh
#
# Event handler script for restarting the mythTVbackend server on lala
#
# Note: This script will only restart the mythtvbackend if the service is
#       retried 2 times (in a &quot;soft&quot; state) or if the service somehow
#       manages to fall into a &quot;hard&quot; error state.
#

# What state is the mythbackend service in?
case &quot;$1&quot; in
OK)
	# The service just came back up, so don't do anything...
	;;
WARNING)
	# We don't really care about warning states, since the service is probably still running...
	;;
UNKNOWN)
	# We don't know what might be causing an unknown error, so don't do anything...
	;;
CRITICAL)
	# Aha!  The HTTP service appears to have a problem - perhaps we should restart the server...

	# Is this a &quot;soft&quot; or a &quot;hard&quot; state?
	case &quot;$2&quot; in

	# We're in a &quot;soft&quot; state, meaning that Nagios is in the middle of retrying the
	# check before it turns into a &quot;hard&quot; state and contacts get notified...
	SOFT)

		# What check attempt are we on?  We don't want to restart the web server on the first
		# check, because it may just be a fluke!
		case &quot;$3&quot; in

		# Wait until the check has been tried 3 times before restarting the web server.
		# If the check fails on the 4th time (after we restart the web server), the state
		# type will turn to &quot;hard&quot; and contacts will be notified of the problem.
		# Hopefully this will restart the web server successfully, so the 4th check will
		# result in a &quot;soft&quot; recovery.  If that happens no one gets notified because we
		# fixed the problem!
		2)
			echo &quot;`date` Restarting mythtv service (2rd soft critical state)...&quot; &gt;&gt; /tmp/mythtvstart
			# Call the init script to restart the mythbackend server
			#/etc/rc.d/init.d/httpd restart
			#date &gt;&gt; /tmp/mythtvstart
			/opt/plugins/check_nrpe -H lala -c start_mythtvbackend
			;;
			esac
		;;

	# The mythtvbackend service somehow managed to turn into a hard error without getting fixed.
	# It should have been restarted by the code above, but for some reason it didn't.
	# Let's give it one last try, shall we?
	# Note: Contacts have already been notified of a problem with the service at this
	# point (unless you disabled notifications for this service)
	HARD)
		echo &quot;`date` Restarting mythtv service (hard state)...&quot; &gt;&gt; /tmp/mythtvstart
		# Call the init script to restart the HTTPD server
		#/etc/rc.d/init.d/httpd restart
		#date &gt;&gt; /tmp/mythtvstart
		/opt/plugins/check_nrpe -H lala -c start_mythtvbackend
		;;
	esac
	;;
esac
exit 0
</pre>
<p>&nbsp;</p>
<p>&nbsp;</p>
<pre>
/opt/monitor/misccomands.cfg</pre>
<pre>
# command 'restart-mythtv-lala'
define command{
    command_name                   restart-mythtv-lala
    command_line                   /opt/plugins/custom/start-mythtv-lala.sh $SERVICESTATE$ $SERVICESTATETYPE$ $SERVICEATTEMPT$
    }
</pre>
<p>&nbsp;</p>
<pre>
/opt/monitor/etc/services.cfg

# service 'Mythbackend'
define service{
    use                            default-service
    host_name                      lala
    service_description            Mythbackend
    check_command                  check_tcp!6543
    servicegroups                  MythTV,it-slav
    event_handler                  restart-mythtv-lala!$SERVICESTATE$ $SERVICESTATETYPE$ $SERVICEATTEMPT$
    contact_groups                 it-slav_sms,it-slav_jabber,it_slav_mail
    }
</pre>
<h3>At my mythbackend machine lala</h3>
<pre>
/etc/nrpe.d/mycommands.cfg
command[start_mythtvbackend]=/usr/bin/sudo /etc/init.d/mythtv-backend start

/etc/sudoers
nobody ALL= (root) NOPASSWD:/etc/init.d/mythtv-backend start
</pre>
<address>Notice that my nrpe agent run as user nobody</address>
<address>&nbsp;</address>
<address>&nbsp;</address>
<address>&nbsp;</address>
<address>&nbsp;</address>
<h2>Test</h2>
<p>I stopped the mythtvbackend by running:</p>
<pre>
peter@lala:/etc/nrpe.d$ date
Mon Jun 15 20:40:55 CEST 2009
peter@lala:/etc/nrpe.d$ sudo /etc/init.d/mythtv-backend stop
 * Stopping MythTV server: mythbackend
</pre>
<p>And run</p>
<pre>
[root@op5 ~]# tail -f /tmp/mythtvstart
Mon Jun 15 20:47:09 CEST 2009 Restarting mythtv service (2rd soft critical state)...
</pre>
<p>YES it works!</p>
<p>&nbsp;</p>
<h2>Links:</h2>
<ul>
<li><a target="_blank" href="http://www.op5.com/op5/products/monitor">op5 Monitor</a> a Nagios based supported enterprise Monitoring software.</li>
<li><a target="_blank" href="http://www.mythtv.org">MythTV</a> a free OpenSource Digital Video Recorder</li>
<li><a href="http://www.nagios.org">Nagios</a> Open Source Monitoring</li>
</ul>
<p>&nbsp;</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.it-slav.net%2Fblogs%2F2009%2F06%2F15%2Fusing-nagios-or-op5-monitor-eventhandler-to-start-a-service-that-has-stopped%2F&amp;title=Using%20Nagios%20or%20op5%20Monitor%20eventhandler%20to%20start%20a%20service%20that%20has%20stopped" id="wpa2a_16"><img src="http://www.it-slav.net/blogs/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.it-slav.net/blogs/2009/06/15/using-nagios-or-op5-monitor-eventhandler-to-start-a-service-that-has-stopped/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Ssh blocker OpenBSD</title>
		<link>http://www.it-slav.net/blogs/2009/02/09/ssh-blocker-openbsd/</link>
		<comments>http://www.it-slav.net/blogs/2009/02/09/ssh-blocker-openbsd/#comments</comments>
		<pubDate>Mon, 09 Feb 2009 19:36:53 +0000</pubDate>
		<dc:creator>peter</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[Geek stuff]]></category>
		<category><![CDATA[it-slav.net]]></category>
		<category><![CDATA[OpenBSD]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[firewall]]></category>
		<category><![CDATA[packetfilter]]></category>

		<guid isPermaLink="false">http://www.it-slav.net/blogs/?p=183</guid>
		<description><![CDATA[My firewall get alot of failed ssh logins. This is a typical log message in /var/log/authlog Feb  9 20:15:49 pedro sshd[30934]: Failed password for root from 67.205.85.119 port 35603 ssh2 Feb  9 20:15:49 pedro sshd[2656]: Received disconnect from 67.205.85.119: 11: Bye Bye Feb  9 20:15:51 pedro sshd[15299]: Failed password for root from 67.205.85.119 port 35753 [...]]]></description>
			<content:encoded><![CDATA[<p>My firewall get alot of failed ssh logins.</p>
<p>This is a typical log message in /var/log/authlog</p>
<pre>Feb  9 20:15:49 pedro sshd[30934]: Failed password for root from 67.205.85.119 port 35603 ssh2
Feb  9 20:15:49 pedro sshd[2656]: Received disconnect from 67.205.85.119: 11: Bye Bye
Feb  9 20:15:51 pedro sshd[15299]: Failed password for root from 67.205.85.119 port 35753 ssh2
Feb  9 20:15:51 pedro sshd[15791]: Received disconnect from 67.205.85.119: 11: Bye Bye
Feb  9 20:15:53 pedro sshd[9043]: Failed password for root from 67.205.85.119 port 35882 ssh2
Feb  9 20:15:53 pedro sshd[31484]: Received disconnect from 67.205.85.119: 11: Bye Bye
Feb  9 20:15:54 pedro sshd[27717]: Failed password for root from 67.205.85.119 port 36030 ssh2
Feb  9 20:15:55 pedro sshd[30185]: Received disconnect from 67.205.85.119: 11: Bye Bye
Feb  9 20:15:56 pedro sshd[27718]: Failed password for root from 67.205.85.119 port 36164 ssh2
Feb  9 20:15:56 pedro sshd[28005]: Received disconnect from 67.205.85.119: 11: Bye Bye
Feb  9 20:15:58 pedro sshd[30648]: Failed password for root from 67.205.85.119 port 36314 ssh2
Feb  9 20:15:58 pedro sshd[21087]: Received disconnect from 67.205.85.119: 11: Bye Bye
</pre>
<p>Of course this is a script kiddie that tries to break into my firewall just because it answers on port 22 and it is annoying. One way of make it a little harder to break in is by let the packetfilter drop all packages that comes from an ip-address that did this.</p>
<p>This one way of doing it.</p>
<p><span id="more-183"></span></p>
<p><br class="spacer_" /></p>
<h3>Create a pf blacklist /etc/pf.conf<br />
</h3>
<p>&#8211;snipp&#8211;</p>
<pre>table &lt;ssh_blacklist&gt; persist file "/var/pf/ssh_blacklist"
...</pre>
<pre>block in quick log on $ext_if from &lt;ssh_blacklist&gt; to any</pre>
<p>&#8211;snipp&#8211;</p>
<p><br class="spacer_" /></p>
<h3>Create a script that detects failed ssh breakin attempts and updates the blacklist</h3>
<pre>root@pedro:/var/log# cat /root/scripts/blockbadssh.sh
#!/bin/sh
logger "Check for bad ssh behavior"
PATH=/bin:/usr/bin
BL=/var/pf/ssh_blacklist
TEMPFILE=$(mktemp /tmp/bl_XXXXXX) || exit 1
TEMPFILE2=$(mktemp /tmp/bl2_XXXXXX) || exit 1

#cp $BL $TEMPFILE
grep "Invalid user" /var/log/authlog | awk '{print $10}' | sort | uniq &gt; $TEMPFILE2
grep "Failed password for invalid" /var/log/authlog | awk '{print $13}' | sort | uniq  &gt;&gt; $TEMPFILE2
grep "Failed password for root" /var/log/authlog | awk '{print $11}' | sort | uniq  &gt;&gt; $TEMPFILE2

sort $TEMPFILE2 |uniq &gt; $TEMPFILE
#echo "Nu är TEMPFILE"
#cat $TEMPFILE

#cat $BL &gt;&gt; $TEMPFILE
for i in `cat $TEMPFILE`
do
  grep $i $BL&gt;/dev/null
  if [ "$?" == "1" ]
  then
    logger "Added $i to ssh-blacklist"
    echo "Added $i to ssh-blacklist"
  fi
done

cat $BL &gt;&gt; $TEMPFILE
sort $TEMPFILE | uniq &gt; $BL

rm $TEMPFILE
rm $TEMPFILE2

/sbin/pfctl -t ssh_blacklist -Treplace -f $BL 2&gt;&amp;1 | grep -v "no changes"
</pre>
<h3>Make it run every minute</h3>
<pre>root@pedro:/var/log# crontab -l </pre>
<pre>*     *       *       *       *       /root/scripts/blockbadssh.sh
</pre>
<p>I know this is a dirty way of doing it and it is a good idea to have another pf rule that accept traffic from well known hosts so you do not get blocked because you failed a login.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.it-slav.net%2Fblogs%2F2009%2F02%2F09%2Fssh-blocker-openbsd%2F&amp;title=Ssh%20blocker%20OpenBSD" id="wpa2a_18"><img src="http://www.it-slav.net/blogs/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.it-slav.net/blogs/2009/02/09/ssh-blocker-openbsd/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HowTo using passive checks with Nagios or op5 Monitor</title>
		<link>http://www.it-slav.net/blogs/2008/12/10/howto-using-passive-checks-with-nagios-or-op5-monitor/</link>
		<comments>http://www.it-slav.net/blogs/2008/12/10/howto-using-passive-checks-with-nagios-or-op5-monitor/#comments</comments>
		<pubDate>Wed, 10 Dec 2008 18:49:30 +0000</pubDate>
		<dc:creator>peter</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[Cool things]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[graph]]></category>
		<category><![CDATA[Hints]]></category>
		<category><![CDATA[Links]]></category>
		<category><![CDATA[Nagios]]></category>
		<category><![CDATA[op5 Monitor]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[nsca]]></category>
		<category><![CDATA[passive]]></category>
		<category><![CDATA[passive checks]]></category>
		<category><![CDATA[send_nsca]]></category>

		<guid isPermaLink="false">http://www.it-slav.net/blogs/?p=392</guid>
		<description><![CDATA[In some cases the &#34;Normal&#34; way of running checks does not work, passive checks might do the job. I have a script the runs every night that backup my MySQL database. If this script fails I would like op5 Monitor or Nagios to send a notification. An active check will not work in this case [...]]]></description>
			<content:encoded><![CDATA[<p>In some cases the &quot;Normal&quot; way of running checks does not work, passive checks might do the job. I have a script the runs every night that backup my MySQL database. If this script fails I would like op5 Monitor or Nagios to send a notification. An active check will not work in this case or is very cumbersome to get it to work. A more elegant solution is to let the backup script send in the result to op5 Monitor or Nagios. This is where passive checks is handy. A passive check trust that some external program will send in the result. It is possible to set check_freshness so if nothing has been sent in to op5 Monitor or Nagios it will react, typically set the status to UNKOWN or CRITICAL.</p>
<p><span id="more-392"></span></p>
<p>In my case the backup script is started on another host then op5 Monitor or Nagios server, so I also will need a way of sending the data from the passive check over the network, the recommended way is to use nsca. Read the theory at <a target="_blank" href="http://nagios.sourceforge.net/docs/3_0/addons.html#nsca">http://nagios.sourceforge.net/docs/3_0/addons.html#nsca</a></p>
<p>In my op5 Monitor system the nsca daemon to recieve nsca information was installed so I only had to start it:</p>
<p>/etc/init.d/nsca start</p>
<p>This is the steps I did to install it on the client:</p>
<p>1. Download nsca from <a target="_blank" href="http://sourceforge.net/project/showfiles.php?group_id=26589&amp;package_id=40242">here</a>.</p>
<p>&nbsp;</p>
<p>2. Untar and compile nsca</p>
<p>&nbsp;</p>
<p>3. Create a ncsa config file i.e. send_nsca.cfg</p>
<pre>
encryption_method=0
</pre>
<p>Now the data will be transmitted unencrypted over the network, this might not be what you want. Make sure that the corresponding nsca config file on the Nagios or op5 Monitor host has the same encryption method.</p>
<p>4. Create a passive check for testing.</p>
<pre>
# service 'Passive check test'</pre>
<pre>
define service{</pre>
<pre>
    use                            default-service</pre>
<pre>
    host_name                      dull</pre>
<pre>
    service_description            Passive check test</pre>
<pre>
    check_command                  check_dummy!3 &quot;No Data from passive check&quot;</pre>
<pre>
    max_check_attempts             1</pre>
<pre>
    active_checks_enabled          0</pre>
<pre>
    check_freshness                1</pre>
<pre>
    freshness_threshold            300</pre>
<pre>
    flap_detection_options         n</pre>
<pre>
    contact_groups                 it-slav_mail,call_it-slav,it-slav_msn</pre>
<pre>
    stalking_options               n</pre>
<pre>
    }</pre>
<p>Explanation:</p>
<p>The check_dummy command will be run if no passive check has been recieved within 5 minutes (300 seconds).</p>
<p>4. test</p>
<p>-First test, wait 5 minutes and your service &quot;Passive check test&quot; should be in status UNKNOWN</p>
<p>-Second test, create  a file passive_file_test_critical (the separator is TAB):</p>
<pre>
dull    Passive check test      2       CRITICAL:test critical</pre>
<p>run command:</p>
<pre>
send_nsca -H nagios_host  -c  send_nsca.cfg &lt; passive_check_data_critical</pre>
<p>and the status should change to CRITICAL</p>
<p>-Third test, create a file passive_check_data_ok (the separator is TAB):</p>
<pre>
dull    Passive check test      0       OK: test ok</pre>
<p>Run the command</p>
<pre>
send_nsca -H  nagios_host -c  send_nsca.cfg &lt; passive_check_data_ok</pre>
<p>And the status should change to OK</p>
<p>&nbsp;</p>
<p>Now you can set the status of a Nagios or op5 Monitor service by using commands that can be used in scripts. I will in a later article describe how I use it in my MySQL backup script.</p>
<p>Links:</p>
<ul>
<li><a target="_blank" href="http://nagios.sourceforge.net/docs/3_0/addons.html#nsca">NSCA</a></li>
<li>Nagios <a href="http://nagios.sourceforge.net/docs/3_0/passivechecks.html">passive check</a> theory</li>
<li><a target="_blank" href="http://www.op5.com/op5/products/monitor">op5 Monitor</a></li>
<li>An <a target="_blank" href="http://www.it-slav.net/blogs/?p=319">article</a> about monitor automysqlbackup with passive checks</li>
</ul>
<p>Troubleshooting hint:</p>
<p>If it does not work, a good hint is to take a look into nagios.log</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.it-slav.net%2Fblogs%2F2008%2F12%2F10%2Fhowto-using-passive-checks-with-nagios-or-op5-monitor%2F&amp;title=HowTo%20using%20passive%20checks%20with%20Nagios%20or%20op5%20Monitor" id="wpa2a_20"><img src="http://www.it-slav.net/blogs/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.it-slav.net/blogs/2008/12/10/howto-using-passive-checks-with-nagios-or-op5-monitor/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>MySQL database backup automysqlbackup</title>
		<link>http://www.it-slav.net/blogs/2008/11/17/mysql-database-backup-automysqlbackup/</link>
		<comments>http://www.it-slav.net/blogs/2008/11/17/mysql-database-backup-automysqlbackup/#comments</comments>
		<pubDate>Mon, 17 Nov 2008 08:04:08 +0000</pubDate>
		<dc:creator>peter</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[Hints]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.it-slav.net/blogs/?p=305</guid>
		<description><![CDATA[Now when my blog is growing a need for backup is growing. After a short google search I found exactly what I want, automysqlbackup. It is a shell script that has very modest requirements list: mysqldump, included in mysql client gzip or bzip2 if you want it compressed. mail if you want the status of [...]]]></description>
			<content:encoded><![CDATA[<p>Now when my blog is growing a need for backup is growing. After a short google search I found exactly what I want, <a href="http://members.lycos.co.uk/wipe_out/automysqlbackup/" target="_blank">automysqlbackup</a>.</p>
<p>It is a shell script that has very modest requirements list:</p>
<ul>
<li>mysqldump, included in mysql client</li>
<li>gzip or bzip2 if you want it compressed.</li>
<li>mail if you want the status of the script to be emailed.</li>
</ul>
<p>Features:</p>
<ul>
<li>Backup mutiple MySQL databases with one script. (Now able to backup ALL databases on a server easily. no longer need to specify each database seperately)</li>
<li>Backup all databases to a single backup file or to a seperate directory and file for each database. </li>
<li>Automatically compress the backup files to save disk space using either gzip or bzip2 compression. </li>
<li>Can backup remote MySQL servers to a central server. </li>
<li>Runs automatically using cron or can be run manually. </li>
<li>Can e-mail the backup log to any specified e-mail address instead of &#8220;root&#8221;. (Great for hosted websites and databases). </li>
<li>Can email the compressed database backup files to the specified email address. </li>
<li>Can specify maximun size backup to email. </li>
<li>Can be set to run PRE and POST backup commands. </li>
<li>Choose which day of the week to run weekly backups.</li>
</ul>
<p>Download it, modify some parameters and put in /etc/cron.daily and now your database is backuped.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.it-slav.net%2Fblogs%2F2008%2F11%2F17%2Fmysql-database-backup-automysqlbackup%2F&amp;title=MySQL%20database%20backup%20automysqlbackup" id="wpa2a_22"><img src="http://www.it-slav.net/blogs/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.it-slav.net/blogs/2008/11/17/mysql-database-backup-automysqlbackup/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>check_mounts plugin for op5 Monitor or Nagios</title>
		<link>http://www.it-slav.net/blogs/2008/11/07/check_mounts-plugin-for-op5-monitor-or-nagios/</link>
		<comments>http://www.it-slav.net/blogs/2008/11/07/check_mounts-plugin-for-op5-monitor-or-nagios/#comments</comments>
		<pubDate>Fri, 07 Nov 2008 20:16:17 +0000</pubDate>
		<dc:creator>peter</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[Nagios]]></category>
		<category><![CDATA[op5 Monitor]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[kernel]]></category>
		<category><![CDATA[xfs]]></category>

		<guid isPermaLink="false">http://www.it-slav.net/blogs/?p=184</guid>
		<description><![CDATA[When I updated my CentOS system and could not mount XFS file system and my op5 Monitor did not react. I even run check_disk on these mount points but op5 Monitor did not tell me that anything was wrong. So when I managed to get the system to boot and my monitoring system tell me [...]]]></description>
			<content:encoded><![CDATA[<p>When I updated my CentOS system and could not mount XFS file system and my op5 Monitor did not react. I even run check_disk on these mount points but op5 Monitor did not tell me that anything was wrong. So when I managed to get the system to boot and my monitoring system tell me everything was alright I went to bed.<br />
When I checked my email this morning I noticed that my backup script had failed and complained &#8220;file does not exist&#8221; and so on. I investigated this and found that my XFS file system was not mounted because of the missing XFS kernel module. I also looked in to why my monitor system has not warned me and figured out that check_disk check the file system you point it to and if that is not mounted it will take the parent and the thresholds for that was not reached.<br />
After taken a look at http://www.nagiosexchange.org and found a ruby script that probably would do the job. But I do not want to install ruby on all my monitored systems, so I decided to write my own. It is written in bash and works on CentOS, and probably on most *nix systems.</p>
<p>The script looks in /etc/fstab and compares it with the file systems mounted. If anything is missing, return CRITICAL and the name of the missed mountpoint. The script does not check that some system file systems are mounted i.e. /proc</p>
<p>I have uploaded this script to nagios exchange.</p>
<pre>#!/bin/sh
#By peter@it-slav.net
#GPLv2

RESULT=0
TMPFILE=`mktemp /tmp/mount.XXXXXXXXXX`
FSTABMOUNTS=`grep -e '^#' -v /etc/fstab|grep -v  tmpfs |grep -v devpts|grep -v sysfs|grep -v proc|grep -v swap| awk '{print $2}'`
for i in $FSTABMOUNTS
do
        mountpoint $i &gt; /dev/null
        if [ $? != "0" ]
        then
                echo -n "$i " &gt;&gt;$TMPFILE
                RESULT=2
        fi

done
#echo $RESULT
if [ $RESULT != "0" ]
then
        echo "is not mounted" &gt;&gt; $TMPFILE
        echo -n "CRITICAL: "
        cat $TMPFILE
else
        echo "OK: All disks mounted"
fi
rm $TMPFILE
exit $RESULT</pre>
<p>Links:</p>
<ul>
<li><a href="http://www.nagiosexchange.org/cgi-bin/page.cgi?g=Detailed%2F2792.html;d=1" target="_blank">check_mounts.sh</a> at <a href="http://www.nagiosexchange.org" target="_blank">Nagiosexchange</a></li>
<li><a href="http://www.op5.com/op5/products/monitor" target="_blank">op5 Monitor </a></li>
<li>My <a href="http://www.it-slav.net/blogs/?p=179" target="_blank">other</a> blog about the problems when I did a kernel upgrade</li>
</ul>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.it-slav.net%2Fblogs%2F2008%2F11%2F07%2Fcheck_mounts-plugin-for-op5-monitor-or-nagios%2F&amp;title=check_mounts%20plugin%20for%20op5%20Monitor%20or%20Nagios" id="wpa2a_24"><img src="http://www.it-slav.net/blogs/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.it-slav.net/blogs/2008/11/07/check_mounts-plugin-for-op5-monitor-or-nagios/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

