<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.10.0">Jekyll</generator><link href="https://bkraft.fr/feed.xml" rel="self" type="application/atom+xml" /><link href="https://bkraft.fr/" rel="alternate" type="text/html" /><updated>2026-02-25T13:37:44+00:00</updated><id>https://bkraft.fr/feed.xml</id><title type="html">Ben’s website</title><subtitle>This is my personal website. It&apos;s mostly a braindump for things I&apos;d like to remember, things I want to read, did read and so on. Nothing thrilling really, but if anything is good for your, cheers.</subtitle><entry><title type="html">GitHub pages</title><link href="https://bkraft.fr/code/2024/06/09/github-pages.html" rel="alternate" type="text/html" title="GitHub pages" /><published>2024-06-09T19:00:00+00:00</published><updated>2024-06-09T19:00:00+00:00</updated><id>https://bkraft.fr/code/2024/06/09/github-pages</id><content type="html" xml:base="https://bkraft.fr/code/2024/06/09/github-pages.html"><![CDATA[<p>This website existed a long time ago, and was composed by the following elements:</p>

<ul>
  <li>Twitter bootstrap</li>
  <li><a href="https://nanoc.app/">nanoc</a> static website generator</li>
</ul>

<p>Well, at some point you have to keep your components updated and the obvious happened … I didn’t and wasn’t able to publish easily contents as I was using the first bootstrap version and updating was something I didn’t want to do, for no valid reason.</p>

<p>Also, I would need to have nanoc site content generator installed to publish something new.</p>

<p>I left it rotting for years because of it and at some point my VPS disappeared and so did the code. Well, I searched for a quite convenient solution and doing so, stubled on <a href="https://pages.github.com/">GitHub Pages</a>. Here’s what I did to get this site running again, without much hassle.</p>

<p><em>This is going to be inspired by documentation pages</em></p>

<h1 id="basic-hosting">Basic hosting</h1>

<ol>
  <li>Head over to GitHub and create a new public repository named username.github.io, where username is your username (or organization name) on GitHub.</li>
  <li></li>
</ol>
<figure class="highlight"><pre><code class="language-bash" data-lang="bash">git clone https://github.com/username/username.github.io</code></pre></figure>

<ol>
  <li>Add some content and push it there with the first commit:</li>
</ol>

<figure class="highlight"><pre><code class="language-bash" data-lang="bash">git add <span class="nt">--all</span>
git commit <span class="nt">-m</span> <span class="s2">"Initial commit"</span>
git push <span class="nt">-u</span> origin main</code></pre></figure>

<p>You’ll get your content available directly at <em>username.github.io</em>. That’s it.</p>

<p>Adding content isn’t harder than a commit.</p>

<h1 id="using-a-custom-domain">Using a custom domain</h1>

<p>Well, I wouldn’t mind using a github.io fqdn, but I own a domain name so, let’s use it.</p>

<p>Go to your domain registrar (I use <a href="https://www.eurodns.com">EuroDNS</a>) and configure the following records:</p>

<figure class="highlight"><pre><code class="language-dns" data-lang="dns">* in CNAME b3nj.github.io.

@ in CNAME b3nj.github.io.</code></pre></figure>

<p>I would rather recommand this option instead of configuring A and AAAA records, at least the records will be updated.</p>

<p>Then:</p>

<ul>
  <li>On GitHub, navigate to your site’s repository.</li>
  <li>Under your repository name, click  Settings. If you cannot see the “Settings” tab, select the  dropdown menu, then click Settings.</li>
  <li>Screenshot of a repository header showing the tabs. The “Settings” tab is highlighted by a dark orange outline. In the “Code and automation” section of the sidebar, click  Pages.</li>
  <li>Under “Custom domain”, type your custom domain, then click Save.</li>
</ul>

<h1 id="securing-pages-with-https">Securing pages with HTTPS</h1>

<p>That’s easy:</p>
<ul>
  <li>On GitHub, navigate to your site’s repository.</li>
  <li>Under your repository name, click  Settings. If you cannot see the “Settings” tab, select the  dropdown menu, then click Settings.</li>
  <li>Screenshot of a repository header showing the tabs. The “Settings” tab is highlighted by a dark orange outline.</li>
  <li>In the “Code and automation” section of the sidebar, click  Pages.</li>
  <li>Under “GitHub Pages,” select Enforce HTTPS.</li>
</ul>

<h1 id="jekyll">Jekyll</h1>

<p>What’s awesome is that you can use <a href="https://jekyllrb.com/">Jekyll</a> static website generator in your website and GitHub will automatically build it using GitHub actions and represent it … it’s quite <a href="https://docs.github.com/en/pages/setting-up-a-github-pages-site-with-jekyll/about-github-pages-and-jekyll">well documented</a>.</p>

<p>In your local repository, launch the Jekyll init command:</p>

<figure class="highlight"><pre><code class="language-bash" data-lang="bash">jekyll new <span class="nt">--skip-bundle</span> .</code></pre></figure>

<p>Then:</p>
<ul>
  <li>Open the Gemfile that Jekyll created.</li>
  <li>Add “#” to the beginning of the line that starts with gem “jekyll” to comment out this line.</li>
  <li>Add the github-pages gem by editing the line starting with # gem “github-pages”. Change this line to:</li>
</ul>

<figure class="highlight"><pre><code class="language-bash" data-lang="bash">gem <span class="s2">"github-pages"</span>, <span class="s2">"~&gt; GITHUB-PAGES-VERSION"</span>, group: :jekyll_plugins</code></pre></figure>

<ul>
  <li>Replace GITHUB-PAGES-VERSION with the latest supported version of the github-pages gem. You can find this version here: “Dependency versions.”
The correct version Jekyll will be installed as a dependency of the github-pages gem.</li>
  <li>Save and close the Gemfile.</li>
  <li>From the command line, run bundle install.</li>
</ul>

<p>Then you’re good to go … Have fun learning how to use <a href="https://jekyllrb.com/">Jekyll</a>.</p>]]></content><author><name></name></author><category term="code" /><summary type="html"><![CDATA[This website existed a long time ago, and was composed by the following elements:]]></summary></entry><entry><title type="html">nocodb, spreadsheets on steroids</title><link href="https://bkraft.fr/code/2024/05/28/nocodb-spreadsheets-on-steroids.html" rel="alternate" type="text/html" title="nocodb, spreadsheets on steroids" /><published>2024-05-28T19:00:00+00:00</published><updated>2024-05-28T19:00:00+00:00</updated><id>https://bkraft.fr/code/2024/05/28/nocodb-spreadsheets-on-steroids</id><content type="html" xml:base="https://bkraft.fr/code/2024/05/28/nocodb-spreadsheets-on-steroids.html"><![CDATA[<p>Searching to migrate a complex excel workbook with loads of intelligence to something web based, easily developpable …
Asked a colleague what he thought might be a good candidate to do this and pointed me out to <a href="https://nocodb.com/">nocodb</a>.</p>

<p>Here’s how they sell it:</p>
<h1 id="build-databases-as-spreadsheets--no-coding-required">Build Databases As Spreadsheets : No-Coding Required</h1>
<p>NocoDB allows building no-code database solutions with ease of spreadsheets.
Bring your own database or choose ours! Millions of rows? Not a problem.
Your Data. Your rules. You are in control.</p>

<p>Wow.</p>

<p>I did a crash course using their <a href="https://docs.nocodb.com/getting-started/self-hosted/installation/">documentation</a> for a brainless setup using docker and a SQLite backend.</p>

<p>Basically it’s this :</p>

<figure class="highlight"><pre><code class="language-bash" data-lang="bash">docker run <span class="nt">-d</span> <span class="nt">--name</span> nocodb <span class="se">\</span>
<span class="nt">-v</span> <span class="s2">"</span><span class="si">$(</span><span class="nb">pwd</span><span class="si">)</span><span class="s2">"</span>/nocodb:/usr/app/data/ <span class="se">\</span>
<span class="nt">-p</span> 8080:8080 <span class="se">\</span>
nocodb/nocodb:latest</code></pre></figure>

<p>Then fired my browser to localhost on port 8080.</p>

<p>Created a database, several tables and linked them very easily in a super neat interface.
Then well, realized that I can’t do automatic calculation and behavioral as I’d like.
However it has awesome “views” that actually present the spreadsheets in a different way, making them less annoying and probably motivating people to fill them. They can be presented as <a href="https://docs.nocodb.com/views/view-types/grid">Grids</a>, <a href="https://docs.nocodb.com/views/view-types/form">Forms</a>, <a href="https://docs.nocodb.com/views/view-types/gallery">Gallery</a>, <a href="https://docs.nocodb.com/views/view-types/kanban">kanban</a> and <a href="https://docs.nocodb.com/views/view-types/calendar">calendar</a>.</p>

<p>It’s freaking awesome.</p>]]></content><author><name></name></author><category term="code" /><summary type="html"><![CDATA[Searching to migrate a complex excel workbook with loads of intelligence to something web based, easily developpable … Asked a colleague what he thought might be a good candidate to do this and pointed me out to nocodb.]]></summary></entry><entry><title type="html">Setup RPM build environment</title><link href="https://bkraft.fr/system/2014/06/02/setup-rpm-build-environment.html" rel="alternate" type="text/html" title="Setup RPM build environment" /><published>2014-06-02T19:00:00+00:00</published><updated>2014-06-02T19:00:00+00:00</updated><id>https://bkraft.fr/system/2014/06/02/setup-rpm-build-environment</id><content type="html" xml:base="https://bkraft.fr/system/2014/06/02/setup-rpm-build-environment.html"><![CDATA[<ul id="markdown-toc">
  <li><a href="#on-redhat-based-systems" id="markdown-toc-on-redhat-based-systems">On RedHat based systems</a>    <ul>
      <li><a href="#foreword" id="markdown-toc-foreword">Foreword</a></li>
      <li><a href="#installing-prerequisites" id="markdown-toc-installing-prerequisites">Installing prerequisites</a></li>
      <li><a href="#creating-a-gpg-key" id="markdown-toc-creating-a-gpg-key">Creating a GPG key</a></li>
      <li><a href="#note-regarding-entropy" id="markdown-toc-note-regarding-entropy">Note regarding entropy</a></li>
      <li><a href="#setting-up-the-environment" id="markdown-toc-setting-up-the-environment">Setting up the environment</a></li>
      <li><a href="#examples" id="markdown-toc-examples">Examples</a></li>
    </ul>
  </li>
</ul>

<h1 id="on-redhat-based-systems">On RedHat based systems</h1>

<p>To build a RPM, you need to prepare your system with packages, libraries a specific configuration file and optionally a way to sign created packets. We’re going through all these as quickly as possible.</p>

<h2 id="foreword">Foreword</h2>

<p>Building packets doesn’t require you any specific rights - just a plain user account. In fact, it’s really really a good idea to build packets under an unprivileged user as you won’t be able to do any damage on the system itself if you’re doing something wrong.</p>

<blockquote>
  <p>[!CAUTION] TL;DR; : don’t use root to build packages ! NEVER !</p>
</blockquote>

<h2 id="installing-prerequisites">Installing prerequisites</h2>

<p>In order to be ready to build a package, your system needs to have some packages and libraries installed. We are going to install the most common ones; if your package requires one, just install it. (This should be done as root)</p>

<blockquote>
  <p>[!NOTE] Note: We are going to install a lot of packages containing scripts and pieces coming providing help for setuping and maintaining build environments from the sister distribution, Fedora.</p>
</blockquote>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>yum <span class="nb">install </span>glibc rpmbuild rpmdevtools yum-utils make
yum groupinstall <span class="s2">"Fedora Packager"</span> <span class="c">#Contains a bunch of scripts and tools</span>
</code></pre></div></div>

<h2 id="creating-a-gpg-key">Creating a GPG key</h2>

<blockquote>
  <p>[!NOTE] Note: This step is optional, if you don’t want having your packets signed, then just skip this part.</p>
</blockquote>

<p>What we are going to do here, is create a GPG private/public key pair in order to sign your packets. The interrest of this is that there is a guarantee for the people that are usually installing your packets that the packet hasn’t been modified, otherwise a GPG error would just pop up. Doing this is pretty straight as it’s just firing one command.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>gpg <span class="nt">--gen-key</span>
<span class="o">=&gt;</span>	gpg <span class="o">(</span>GnuPG<span class="o">)</span> 2.0.14<span class="p">;</span> Copyright <span class="o">(</span>C<span class="o">)</span> 2009 Free Software Foundation, Inc.
	This is free software: you are free to change and redistribute it.
	There is NO WARRANTY, to the extent permitted by law.

	gpg: répertoire <span class="sb">`</span>/home/bkraft/.gnupg<span class="s1">' créé
	gpg:  nouveau fichier de configuration `/home/bkraft/.gnupg/gpg.conf'</span> créé
	gpg: AVERTISSEMENT: les options de <span class="sb">`</span>/home/bkraft/.gnupg/gpg.conf<span class="s1">' ne sont pas encore actives cette fois
	gpg: le porte-clés `/home/bkraft/.gnupg/secring.gpg` a été créé
	gpg: le porte-clés `/home/bkraft/.gnupg/pubring.gpg` a été créé
	Sélectionnez le type de clé désiré:
	   (1) RSA and RSA (default) # This is what we are going to pick
	   (2) DSA and Elgamal
	   (3) DSA (signature seule)
	   (4) RSA (signature seule)
	Votre choix ? 1
	les clés RSA peuvent faire entre 1024 et 4096 bits de longueur.
	Quelle taille de clé désirez-vous ? (2048) 4096 # Make it big
	La taille demandée est 4096 bits
	Spécifiez combien de temps cette clé devrait être valide.
	         0 = la clé n'</span>expire pas
	      &lt;n&gt;  <span class="o">=</span> la clé expire dans n jours
	      &lt;n&gt;w <span class="o">=</span> la clé expire dans n semaines
	      &lt;n&gt;m <span class="o">=</span> la clé expire dans n mois
	      &lt;n&gt;y <span class="o">=</span> la clé expire dans n années
	La clé est valide pour ? <span class="o">(</span>0<span class="o">)</span> <span class="c"># Make it never expires ... don't do this.</span>
	La clé n<span class="s1">'expire pas du tout
	Est-ce correct ? (o/N) o

	You need a user ID to identify your key; the software constructs the user ID
	from the Real Name, Comment and Email Address in this form:
	    "Heinrich Heine (Der Dichter) &lt;heinrichh@duesseldorf.de&gt;"

	Nom réel: Benjamin KRAFT
	Adresse e-mail: benj@bkraft.fr
	Commentaire: RPM build purposes
	Vous avez sélectionné ce nom d'</span>utilisateur:
	    <span class="s2">"Benjamin KRAFT (RPM build purposes) &lt;benj@bkraft.fr&gt;"</span>

	Changer le <span class="o">(</span>N<span class="o">)</span>om, le <span class="o">(</span>C<span class="o">)</span>ommentaire, l<span class="s1">'(E)-mail ou (O)K/(Q)uitter ? O
	Vous avez besoin d'</span>une phrase de passe pour protéger votre clé
	secrète.

	can<span class="s1">'t connect to `/home/bkraft/.gnupg/S.gpg-agent'</span>: Aucun fichier ou dossier de ce <span class="nb">type
	</span>gpg-agent[21736]: répertoire <span class="sb">`</span>/home/bkraft/.gnupg/private-keys-v1.d<span class="s1">' créé
	Un grand nombre d'</span>octets aléatoires doit être généré. Vous devriez faire
	autre-chose <span class="o">(</span>taper au clavier, déplacer la souris, utiliser les disques<span class="o">)</span>
	pendant la génération de nombres premiers<span class="p">;</span> cela donne au générateur de
	nombres aléatoires une meilleure chance d<span class="s1">'avoir assez d'</span>entropie.
	gpg: /home/bkraft/.gnupg/trustdb.gpg: base de confiance créée
	gpg: clé 7AC6E47B marquée comme ayant une confiance ultime.
	les clés publique et secrète ont été créées et signées.

	gpg: vérifier la base de confiance
	gpg: 3 marginale<span class="o">(</span>s<span class="o">)</span> nécessaires, 1 complète<span class="o">(</span>s<span class="o">)</span> nécessaires, modèle
	de confiance PGP
	gpg: profondeur: 0  valide:   1  signé:   0
	confiance: 0-. 0g. 0n. 0m. 0f. 1u
	pub   4096R/7AC6E47B 2012-02-04
	    Empreinte de la clé <span class="o">=</span> 38E9 4639 75BD 4715 55DD  28E5 178A 4B6C 7AC6 E47B
	uid                  Benjamin KRAFT <span class="o">(</span>RPM build purposes<span class="o">)</span> &lt;benj@bkraft.fr&gt;
	sub   4096R/379A3BD3 2012-02-04
</code></pre></div></div>

<h2 id="note-regarding-entropy">Note regarding entropy</h2>

<p>Entropy on a virtual machine like on the one I did this HOWTO was really low and I was stuck with GnuPG waiting for more of it. Here is what I used as a solution to get it finished :</p>

<blockquote>
  <p>#notetoself when gpg –gen-key on vm with low entropy (35) install rng-tools and use /dev/urandom as rng device for rngd.
— Benjamin KRAFT (@b3nj) https://twitter.com/b3nj/status/165715474963902464 (February 4, 2012)</p>
</blockquote>

<p>Well, it seems that it really wasn’t the best solution available, as said @digdns responded :</p>

<blockquote>
  <p>@b3nj I recommendhaveged https://issihosts.com/haveged/ (see also: https://web.archive.org/web/20201029110552/http://t.co/UFfD0nO7)
— JP’s DNS cache (@digdns) https://web.archive.org/web/20201029110552/https://twitter.com/digdns/status/165716319021445120 (February 4, 2012)</p>
</blockquote>

<p>We’ll use what we did in a further module, but you should already do the two following things :</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># Export your public key to let systems recognize your signature</span>
gpg <span class="nt">--export</span> <span class="nt">--armor</span> <span class="o">&gt;</span>RPM-GPG-KEY-benjaminkraft
<span class="c"># Import it in your own system</span>
rpm <span class="nt">--import</span> /home/bkraft/RPM-GPG-KEY-benjaminkraft
</code></pre></div></div>

<h2 id="setting-up-the-environment">Setting up the environment</h2>

<p>Fire up the appropriate command that will create eveything that is necessary for your build environment</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>rpmdev-setuptree <span class="c"># Yeah. that's it.</span>
<span class="nb">ls</span> <span class="nt">-l</span> 
<span class="o">=&gt;</span>	drwxrwxr-x 7 bkraft bkraft 4096  4 févr. 09:07 rpmbuild
<span class="nb">ls</span> <span class="nt">-l</span> rpmbuild/
total 20
<span class="o">=&gt;</span>	drwxrwxr-x 2 bkraft bkraft 4096  4 févr. 09:07 BUILD
	drwxrwxr-x 2 bkraft bkraft 4096  4 févr. 09:07 RPMS
	drwxrwxr-x 2 bkraft bkraft 4096  4 févr. 09:07 SOURCES
	drwxrwxr-x 2 bkraft bkraft 4096  4 févr. 09:07 SPECS
	drwxrwxr-x 2 bkraft bkraft 4096  4 févr. 09:07 SRPMS
<span class="nb">cat</span> .rpmmacros 
<span class="o">=&gt;</span>	%_topdir      %<span class="o">(</span><span class="nb">echo</span> <span class="nv">$HOME</span><span class="o">)</span>/rpmbuild
	%_smp_mflags  <span class="nt">-j3</span>
	%__arch_install_post   /usr/lib/rpm/check-rpaths   /usr/lib/rpm/check-buildroot

Now, add the GnuPG related stuff <span class="k">in </span>order to sign your packages :

	%_topdir      %<span class="o">(</span><span class="nb">echo</span> <span class="nv">$HOME</span><span class="o">)</span>/rpmbuild
	%_smp_mflags  <span class="nt">-j3</span>
	%__arch_install_post   /usr/lib/rpm/check-rpaths   /usr/lib/rpm/check-buildroot
	%_signature             gpg
	%_gpg_name              Benjamin KRAFT
	%_gpg_path              %<span class="o">(</span><span class="nb">echo</span> <span class="nv">$HOME</span><span class="o">)</span>/.gnupg
</code></pre></div></div>

<h2 id="examples">Examples</h2>

<p>Now that you’re ready, here is some common things that you’ll like to do:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># Fedora has more recent packets than CentOS, that's a fact.</span>
<span class="c"># Sometimes, I do backport a package from there to here, by downloading</span>
<span class="c"># a package in src.rpm format and just rebuild it.</span>

<span class="c"># This can be done on one single command line to simply build it</span>
rpmbuild <span class="nt">--rebuild</span> package.src.rpm

<span class="c"># Or, install the src.rpm (as the building user), modify the spec, and build</span>
rpm <span class="nt">-ivh</span> package.src.rpm
vim rpmbuild/SPEC/package.spec
rpmbuild <span class="nt">-bb</span> /rpmbuild/SPEC/package.spec

<span class="c"># Add a GnuPG signature on the created packet</span>
rpmsign <span class="nt">--addsign</span> package.el6.noarch.rpm

<span class="c"># Check a GnuPG signature</span>
rpmsign <span class="nt">--checksig</span> rpmbuild/RPMS/noarch/package.el6.noarch.rpm 
<span class="o">=&gt;</span>	rpmbuild/RPMS/noarch/package.el6.noarch.rpm: rsa sha1 <span class="o">(</span>md5<span class="o">)</span> pgp md5 OK
</code></pre></div></div>]]></content><author><name></name></author><category term="system" /><summary type="html"><![CDATA[]]></summary></entry><entry><title type="html">Using LVM Snapshots</title><link href="https://bkraft.fr/system/2014/06/02/using-lvm-snapshots.html" rel="alternate" type="text/html" title="Using LVM Snapshots" /><published>2014-06-02T19:00:00+00:00</published><updated>2014-06-02T19:00:00+00:00</updated><id>https://bkraft.fr/system/2014/06/02/using-lvm-snapshots</id><content type="html" xml:base="https://bkraft.fr/system/2014/06/02/using-lvm-snapshots.html"><![CDATA[<ul id="markdown-toc">
  <li><a href="#a-not-so-known-feature-that-really-is-useful" id="markdown-toc-a-not-so-known-feature-that-really-is-useful">A not so known feature that really is useful.</a>    <ul>
      <li><a href="#creating-a-1gb-volume-called-productiondata" id="markdown-toc-creating-a-1gb-volume-called-productiondata">Creating a 1GB volume called “productiondata”</a></li>
      <li><a href="#creating-some-important-data-inside-it" id="markdown-toc-creating-some-important-data-inside-it">Creating some important data inside it</a></li>
      <li><a href="#creating-a-snapshot-and-working-with-it" id="markdown-toc-creating-a-snapshot-and-working-with-it">Creating a snapshot and working with it</a></li>
      <li><a href="#rollback-in-case-of-somethings-wrong" id="markdown-toc-rollback-in-case-of-somethings-wrong">Rollback in case of somethings wrong</a></li>
    </ul>
  </li>
</ul>

<h1 id="a-not-so-known-feature-that-really-is-useful">A not so known feature that really is useful.</h1>

<p>As a system administrator, I daily use snapshots, either for backing up or to ensure a way to rollback when things might go nasty.</p>

<p>The system on which we will run the following things has some free space in the volgroup Volgroup.
Now we’ll create a specific logical volume called productiondata in which we’ll add some very important data:</p>

<h2 id="creating-a-1gb-volume-called-productiondata">Creating a 1GB volume called “productiondata”</h2>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>lvcreate <span class="nt">-L1G</span> <span class="nt">-n</span> productiondata VolGroup
	  Logical volume <span class="s2">"productiondata"</span> created
mkfs.ext3 /dev/mapper/VolGroup-productiondata
	mke2fs 1.41.12 <span class="o">(</span>17-May-2010<span class="o">)</span>
	Filesystem <span class="nv">label</span><span class="o">=</span>
	OS <span class="nb">type</span>: Linux
	Block <span class="nv">size</span><span class="o">=</span>4096 <span class="o">(</span><span class="nv">log</span><span class="o">=</span>2<span class="o">)</span>
	Fragment <span class="nv">size</span><span class="o">=</span>4096 <span class="o">(</span><span class="nv">log</span><span class="o">=</span>2<span class="o">)</span>
	<span class="nv">Stride</span><span class="o">=</span>0 blocks, Stripe <span class="nv">width</span><span class="o">=</span>0 blocks
	65536 inodes, 262144 blocks
	13107 blocks <span class="o">(</span>5.00%<span class="o">)</span> reserved <span class="k">for </span>the super user
	First data <span class="nv">block</span><span class="o">=</span>0
	Maximum filesystem <span class="nv">blocks</span><span class="o">=</span>268435456
	8 block <span class="nb">groups
	</span>32768 blocks per group, 32768 fragments per group
	8192 inodes per group
	Superblock backups stored on blocks:
		32768, 98304, 163840, 229376

	Writing inode tables: <span class="k">done
	</span>Creating journal <span class="o">(</span>8192 blocks<span class="o">)</span>: <span class="k">done
	</span>Writing superblocks and filesystem accounting information: <span class="k">done

	</span>This filesystem will be automatically checked every 21 mounts or
	180 days, whichever comes first.  Use tune2fs <span class="nt">-c</span> or <span class="nt">-i</span> to override.
<span class="nb">mkdir</span> /mnt/productiondata
mount /dev/mapper/VolGroup-productiondata /mnt/productiondata/
</code></pre></div></div>

<h2 id="creating-some-important-data-inside-it">Creating some important data inside it</h2>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">cd</span> /mnt/productiondata/
<span class="k">for </span>i <span class="k">in</span> <span class="o">{</span>1..10<span class="o">}</span><span class="p">;</span> <span class="k">do </span><span class="nb">date</span> <span class="o">&gt;</span> <span class="nv">$i</span>.txt<span class="p">;</span> <span class="k">done
</span>ll
	total 56
	<span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 10.txt
	<span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 1.txt
	<span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 2.txt
	<span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 3.txt
	<span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 4.txt
	<span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 5.txt
	<span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 6.txt
	<span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 7.txt
	<span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 8.txt
	<span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 9.txt
	drwx------. 2 root root 16384 May 23 15:29 lost+found
</code></pre></div></div>

<h2 id="creating-a-snapshot-and-working-with-it">Creating a snapshot and working with it</h2>

<p>Now, create a snapshot of 512MB size</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>lvcreate <span class="nt">-L512M</span> <span class="nt">-s</span> <span class="nt">-n</span> productiondatabackup /dev/mapper/VolGroup-productiondata
  Logical volume <span class="s2">"productiondatabackup"</span> created
lvdisplay
  <span class="nt">---</span> Logical volume <span class="nt">---</span>
  LV Path                /dev/VolGroup/productiondata
  LV Name                productiondata
  VG Name                VolGroup
  LV UUID                BLcHEd-kjde-BpOq-IbOT-1rBc-1B7t-SeNUUa
  LV Write Access        <span class="nb">read</span>/write
  LV Creation host, <span class="nb">time </span>localhost.localdomain, 2014-05-23 15:28:33 +0200
  LV snapshot status     <span class="nb">source </span>of
                         productiondatabackup <span class="o">[</span>active]
  LV Status              available
  <span class="c"># open                 1</span>
  LV Size                1.00 GiB
  Current LE             256
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently <span class="nb">set </span>to     256
  Block device           253:2

  <span class="nt">---</span> Logical volume <span class="nt">---</span>
  LV Path                /dev/VolGroup/productiondatabackup
  LV Name                productiondatabackup
  VG Name                VolGroup
  LV UUID                O3dFho-eFIc-GfV1-MIgP-CryF-JKwp-tmzY1r
  LV Write Access        <span class="nb">read</span>/write
  LV Creation host, <span class="nb">time </span>localhost.localdomain, 2014-05-23 15:33:11 +0200
  LV snapshot status     active destination <span class="k">for </span>productiondata
  LV Status              available
  <span class="c"># open                 0</span>
  LV Size                1.00 GiB
  Current LE             256
  COW-table size         512.00 MiB
  COW-table LE           128
  Allocated to snapshot  0.00%
  Snapshot chunk size    4.00 KiB
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently <span class="nb">set </span>to     256
  Block device           253:3
</code></pre></div></div>

<p>Add some more data to productiondata</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">for </span>i <span class="k">in</span> <span class="o">{</span>100..110<span class="o">}</span><span class="p">;</span> <span class="k">do </span><span class="nb">date</span> <span class="o">&gt;</span> <span class="nv">$i</span>.txt<span class="p">;</span> <span class="k">done
</span>ll
	total 100
	<span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:34 100.txt
	<span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:34 101.txt
	<span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:34 102.txt
	<span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:34 103.txt
	<span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:34 104.txt
	<span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:34 105.txt
	<span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:34 106.txt
	<span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:34 107.txt
	<span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:34 108.txt
	<span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:34 109.txt
	<span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 10.txt
	<span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:34 110.txt
	<span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 1.txt
	<span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 2.txt
	<span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 3.txt
	<span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 4.txt
	<span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 5.txt
	<span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 6.txt
	<span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 7.txt
	<span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 8.txt
	<span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 9.txt
	drwx------. 2 root root 16384 May 23 15:29 lost+found
</code></pre></div></div>

<p>Let’s mount the snapshot to see what’s inside</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>mount /dev/mapper/VolGroup-productiondatabackup /mnt/productiondatabackup/
ll /mnt/productiondatabackup/
total 56
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 10.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 1.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 2.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 3.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 4.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 5.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 6.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 7.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 8.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 9.txt
drwx------. 2 root root 16384 May 23 15:29 lost+found
</code></pre></div></div>

<p>Everything’s fine so we’re going to delete the snapshot</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>umount /mnt/productiondatabackup
lvremove /dev/mapper/VolGroup-productiondatabackup
Do you really want to remove active logical volume productiondatabackup? <span class="o">[</span>y/n]: y
  Logical volume <span class="s2">"productiondatabackup"</span> successfully removed
ll /mnt/productiondata
total 100
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:34 100.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:34 101.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:34 102.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:34 103.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:34 104.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:34 105.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:34 106.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:34 107.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:34 108.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:34 109.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 10.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:34 110.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 1.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 2.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 3.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 4.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 5.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 6.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 7.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 8.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 9.txt
drwx------. 2 root root 16384 May 23 15:29 lost+found
</code></pre></div></div>

<h2 id="rollback-in-case-of-somethings-wrong">Rollback in case of somethings wrong</h2>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>lvcreate <span class="nt">-L512M</span> <span class="nt">-s</span> <span class="nt">-n</span> productiondatabackup /dev/mapper/VolGroup-productiondata
<span class="k">for </span>i <span class="k">in</span> <span class="k">*</span>.txt<span class="p">;</span> <span class="k">do </span><span class="nb">echo</span> <span class="s2">"major fuckup"</span> <span class="o">&gt;</span> <span class="nv">$i</span><span class="p">;</span> <span class="k">done
</span>lvconvert <span class="nt">--merge</span> /dev/VolGroup/productiondatabackup
  Cannot merge over open origin volume
  Merging of snapshot productiondatabackup will start next activation.
<span class="nb">cd
</span>umount /dev/VolGroup/productiondata
lvchange <span class="nt">-an</span> /dev/VolGroup/productiondata
lvchange <span class="nt">-ay</span> /dev/VolGroup/productiondata
mount /dev/VolGroup/productiondata /mnt/productiondata
ll /mnt/productiondata
total 100
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:34 100.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:34 101.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:34 102.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:34 103.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:34 104.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:34 105.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:34 106.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:34 107.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:34 108.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:34 109.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 10.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:34 110.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 1.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 2.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 3.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 4.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 5.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 6.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 7.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 8.txt
- <span class="nt">-rw-r--r--</span><span class="nb">.</span> 1 root root    30 May 23 15:31 9.txt
drwx------. 2 root root 16384 May 23 15:29 lost+found
<span class="nb">cat</span> /mnt/productiondata/1.txt
Fri May 23 15:31:51 CEST 2014
</code></pre></div></div>

<p>Reverted ! Please note that the snapshot is GONE, before doing crap again, please create another</p>

<p>What happens if we allocate more than the snapshot size ? (512MB here)</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">dd </span><span class="k">if</span><span class="o">=</span>/dev/zero <span class="nv">of</span><span class="o">=</span>/mnt/productiondata/fat.file <span class="nv">bs</span><span class="o">=</span>1M <span class="nv">count</span><span class="o">=</span>513
513+0 records <span class="k">in
</span>513+0 records out
537919488 bytes <span class="o">(</span>538 MB<span class="o">)</span> copied, 8.83559 s, 60.9 MB/s
</code></pre></div></div>

<p>Here’s the extract of the logs:</p>

<pre><code class="language-log">/dev/VolGroup/productiondatabackup: read failed after 0 of 4096 at 1073676288: Input/output error
/dev/VolGroup/productiondatabackup: read failed after 0 of 4096 at 1073733632: Input/output error
/dev/VolGroup/productiondatabackup: read failed after 0 of 4096 at 0: Input/output error
/dev/VolGroup/productiondatabackup: read failed after 0 of 4096 at 4096: Input/output error
</code></pre>

<p>Don’t worry, you are still able to write on your original volume</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">touch test</span>
</code></pre></div></div>

<p>But the snapshot is unusable</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>mount /dev/mapper/VolGroup-productiondatabackup /mnt/productiondatabackup/
mount: you must specify the filesystem <span class="nb">type
</span>lvremove /dev/mapper/VolGroup-productiondatabackup
  /dev/VolGroup/productiondatabackup: <span class="nb">read </span>failed after 0 of 4096 at 1073676288: Input/output error
  /dev/VolGroup/productiondatabackup: <span class="nb">read </span>failed after 0 of 4096 at 1073733632: Input/output error
  /dev/VolGroup/productiondatabackup: <span class="nb">read </span>failed after 0 of 4096 at 0: Input/output error
  /dev/VolGroup/productiondatabackup: <span class="nb">read </span>failed after 0 of 4096 at 4096: Input/output error
Do you really want to remove active logical volume productiondatabackup? <span class="o">[</span>y/n]: y
  Logical volume <span class="s2">"productiondatabackup"</span> successfully removed
</code></pre></div></div>

<p>To avoid getting in this situation (not being able to rollback), please make sure that you have enough space for what you intend to do. You should monitor the snapshot usage rate by looking at the ‘Allocated to snapshot’ line in lvdisplay output.</p>]]></content><author><name></name></author><category term="system" /><summary type="html"><![CDATA[]]></summary></entry><entry><title type="html">Debugging DNSSEC with delv</title><link href="https://bkraft.fr/system/2014/04/29/debugging-dnssec-with-delv.html" rel="alternate" type="text/html" title="Debugging DNSSEC with delv" /><published>2014-04-29T19:00:00+00:00</published><updated>2014-04-29T19:00:00+00:00</updated><id>https://bkraft.fr/system/2014/04/29/debugging-dnssec-with-delv</id><content type="html" xml:base="https://bkraft.fr/system/2014/04/29/debugging-dnssec-with-delv.html"><![CDATA[<ul id="markdown-toc">
  <li><a href="#introduced-with-bind-910rc1" id="markdown-toc-introduced-with-bind-910rc1">Introduced with bind 9.10rc1</a></li>
</ul>

<h1 id="introduced-with-bind-910rc1">Introduced with bind 9.10rc1</h1>

<p>Because <code class="language-plaintext highlighter-rouge">dig</code> is not so self-explanatory, here’s something more useful.</p>

<p>Since <code class="language-plaintext highlighter-rouge">bind 9.10rc1</code>, the ISC team introduced a new team to help with the debug of <code class="language-plaintext highlighter-rouge">DNSSEC</code> eventual problems. Initially called <code class="language-plaintext highlighter-rouge">delve</code>, but changed to <code class="language-plaintext highlighter-rouge">delv</code>.</p>

<p>This is what a standard dns query (using a non-validating resolver) shows:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>dig ANY +dnssec +nocrypto dnssec-failed.org

	<span class="p">;</span> &lt;&lt;<span class="o">&gt;&gt;</span> DiG 9.10.0rc1 &lt;&lt;<span class="o">&gt;&gt;</span> ANY +dnssec +nocrypto dnssec-failed.org
	<span class="p">;;</span> global options: +cmd
	<span class="p">;;</span> Got answer:
	<span class="p">;;</span> -&gt;&gt;HEADER<span class="o">&lt;&lt;-</span> <span class="no">opcode</span><span class="sh">: QUERY, status: NOERROR, id: 31994
	;; flags: qr rd ra; QUERY: 1, ANSWER: 14, AUTHORITY: 0, ADDITIONAL: 1

	;; OPT PSEUDOSECTION:
	; EDNS: version: 0, flags: do; udp: 4096
	;; QUESTION SECTION:
	;dnssec-failed.org.		IN	ANY

	;; ANSWER SECTION:
	dnssec-failed.org.	85942	IN	SOA	dns101.comcast.org. dnsadmin.comcast.net. 2010101630 900 180 604800 7200
	dnssec-failed.org.	85942	IN	RRSIG	SOA 5 2 86400 20140505165107 20140428134607 28833 dnssec-failed.org. [omitted]
	dnssec-failed.org.	6742	IN	NSEC	www.dnssec-failed.org. NS SOA RRSIG NSEC DNSKEY
	dnssec-failed.org.	6742	IN	RRSIG	NSEC 5 2 7200 20140505165107 20140428134607 28833 dnssec-failed.org. [omitted]
	dnssec-failed.org.	6742	IN	NS	dns101.comcast.net.
	dnssec-failed.org.	6742	IN	NS	dns102.comcast.net.
	dnssec-failed.org.	6742	IN	NS	dns103.comcast.net.
	dnssec-failed.org.	6742	IN	NS	dns104.comcast.net.
	dnssec-failed.org.	6742	IN	NS	dns105.comcast.net.
	dnssec-failed.org.	6742	IN	RRSIG	NS 5 2 7200 20140505165107 20140428134607 28833 dnssec-failed.org. [omitted]
	dnssec-failed.org.	3142	IN	DNSKEY	256 3 5 [key id = 28833]
	dnssec-failed.org.	3142	IN	DNSKEY	257 3 5 [key id = 29521]
	dnssec-failed.org.	3142	IN	RRSIG	DNSKEY 5 2 3600 20140624135107 20140224095107 29521 dnssec-failed.org. [omitted]
	dnssec-failed.org.	3142	IN	RRSIG	DNSKEY 5 2 3600 20140505165107 20140428134607 28833 dnssec-failed.org. [omitted]

	;; Query time: 718 msec
	;; SERVER: 10.211.55.1#53(10.211.55.1)
	;; WHEN: Mon Apr 28 21:29:25 CEST 2014
	;; MSG SIZE  rcvd: 1703
</span></code></pre></div></div>

<p>Let’s try to debug a bit what’s wrong on this domain with <code class="language-plaintext highlighter-rouge">dig</code>:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>dig +sigchase dnssec-failed.org. A
	<span class="p">;;</span> NO ANSWERS: no more
	We want to prove the non-existence of a <span class="nb">type </span>of rdata 1 or of the zone:
	<span class="p">;;</span> nothing <span class="k">in </span>authority section : impossible to validate the non-existence : FAILED

	<span class="p">;;</span> Impossible to verify the Non-existence, the NSEC RRset can<span class="s1">'t be validated: FAILED
</span></code></pre></div></div>

<p>And this is the basic output of delv:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>delv ANY dnssec-failed.org
	<span class="p">;;</span> validating dnssec-failed.org/DNSKEY: no valid signature found <span class="o">(</span>DS<span class="o">)</span>
	<span class="p">;;</span> no valid RRSIG resolving <span class="s1">'dnssec-failed.org/DNSKEY/IN'</span>: 10.211.55.1#53
	<span class="p">;;</span> broken trust chain resolving <span class="s1">'dnssec-failed.org/ANY/IN'</span>: 10.211.55.1#53
	<span class="p">;;</span> validating dnssec-failed.org/NSEC: bad cache hit <span class="o">(</span>dnssec-failed.org/DNSKEY<span class="o">)</span>
	<span class="p">;;</span> validating dnssec-failed.org/NS: bad cache hit <span class="o">(</span>dnssec-failed.org/DNSKEY<span class="o">)</span>
	<span class="p">;;</span> validating dnssec-failed.org/DNSKEY: no valid signature found <span class="o">(</span>DS<span class="o">)</span>
	<span class="p">;;</span> resolution failed: no valid RRSIG
</code></pre></div></div>

<p>Quite better ! and it can even be better by tracing validation process:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>delv +vtrace ANY dnssec-failed.org
	<span class="p">;;</span> fetch: dnssec-failed.org/ANY
	<span class="p">;;</span> validating dnssec-failed.org/SOA: starting
	<span class="p">;;</span> validating dnssec-failed.org/SOA: attempting positive response validation
	<span class="p">;;</span> fetch: dnssec-failed.org/DNSKEY
	<span class="p">;;</span> validating dnssec-failed.org/DNSKEY: starting
	<span class="p">;;</span> validating dnssec-failed.org/DNSKEY: attempting positive response validation
	<span class="p">;;</span> fetch: dnssec-failed.org/DS
	<span class="p">;;</span> validating dnssec-failed.org/DS: starting
	<span class="p">;;</span> validating dnssec-failed.org/DS: attempting positive response validation
	<span class="p">;;</span> fetch: org/DNSKEY
	<span class="p">;;</span> validating org/DNSKEY: starting
	<span class="p">;;</span> validating org/DNSKEY: attempting positive response validation
	<span class="p">;;</span> fetch: org/DS
	<span class="p">;;</span> validating org/DS: starting
	<span class="p">;;</span> validating org/DS: attempting positive response validation
	<span class="p">;;</span> fetch: ./DNSKEY
	<span class="p">;;</span> validating ./DNSKEY: starting
	<span class="p">;;</span> validating ./DNSKEY: attempting positive response validation
	<span class="p">;;</span> validating ./DNSKEY: verify rdataset <span class="o">(</span><span class="nv">keyid</span><span class="o">=</span>19036<span class="o">)</span>: success
	<span class="p">;;</span> validating ./DNSKEY: signed by trusted key<span class="p">;</span> marking as secure
	<span class="p">;;</span> validating org/DS: <span class="k">in </span>fetch_callback_validator
	<span class="p">;;</span> validating org/DS: keyset with trust secure
	<span class="p">;;</span> validating org/DS: resuming validate
	<span class="p">;;</span> validating org/DS: verify rdataset <span class="o">(</span><span class="nv">keyid</span><span class="o">=</span>40926<span class="o">)</span>: success
	<span class="p">;;</span> validating org/DS: marking as secure, noqname proof not needed
	<span class="p">;;</span> validating org/DNSKEY: <span class="k">in </span>dsfetched
	<span class="p">;;</span> validating org/DNSKEY: dsset with trust secure
	<span class="p">;;</span> validating org/DNSKEY: verify rdataset <span class="o">(</span><span class="nv">keyid</span><span class="o">=</span>21366<span class="o">)</span>: success
	<span class="p">;;</span> validating org/DNSKEY: marking as secure <span class="o">(</span>DS<span class="o">)</span>
	<span class="p">;;</span> validating dnssec-failed.org/DS: <span class="k">in </span>fetch_callback_validator
	<span class="p">;;</span> validating dnssec-failed.org/DS: keyset with trust secure
	<span class="p">;;</span> validating dnssec-failed.org/DS: resuming validate
	<span class="p">;;</span> validating dnssec-failed.org/DS: verify rdataset <span class="o">(</span><span class="nv">keyid</span><span class="o">=</span>28794<span class="o">)</span>: success
	<span class="p">;;</span> validating dnssec-failed.org/DS: marking as secure, noqname proof not needed
	<span class="p">;;</span> validating dnssec-failed.org/DNSKEY: <span class="k">in </span>dsfetched
	<span class="p">;;</span> validating dnssec-failed.org/DNSKEY: dsset with trust secure
	<span class="p">;;</span> validating dnssec-failed.org/DNSKEY: no DNSKEY matching DS
	<span class="p">;;</span> validating dnssec-failed.org/DNSKEY: no valid signature found <span class="o">(</span>DS<span class="o">)</span>
	<span class="p">;;</span> no valid RRSIG resolving <span class="s1">'dnssec-failed.org/DNSKEY/IN'</span>: 10.211.55.1#53
	<span class="p">;;</span> validating dnssec-failed.org/SOA: <span class="k">in </span>fetch_callback_validator
	<span class="p">;;</span> validating dnssec-failed.org/SOA: fetch_callback_validator: got failure
	<span class="p">;;</span> broken trust chain resolving <span class="s1">'dnssec-failed.org/ANY/IN'</span>: 10.211.55.1#53
	<span class="p">;;</span> validating dnssec-failed.org/NSEC: starting
	<span class="p">;;</span> validating dnssec-failed.org/NSEC: attempting positive response validation
	<span class="p">;;</span> validating dnssec-failed.org/NSEC: bad cache hit <span class="o">(</span>dnssec-failed.org/DNSKEY<span class="o">)</span>
	<span class="p">;;</span> validating dnssec-failed.org/NS: starting
	<span class="p">;;</span> validating dnssec-failed.org/NS: attempting positive response validation
	<span class="p">;;</span> validating dnssec-failed.org/NS: bad cache hit <span class="o">(</span>dnssec-failed.org/DNSKEY<span class="o">)</span>
	<span class="p">;;</span> validating dnssec-failed.org/DNSKEY: starting
	<span class="p">;;</span> validating dnssec-failed.org/DNSKEY: attempting positive response validation
	<span class="p">;;</span> validating dnssec-failed.org/DNSKEY: no DNSKEY matching DS
	<span class="p">;;</span> validating dnssec-failed.org/DNSKEY: no valid signature found <span class="o">(</span>DS<span class="o">)</span>
	<span class="p">;;</span> validating dnssec-failed.org/DNSKEY: falling back to insecurity proof
	<span class="p">;;</span> validating dnssec-failed.org/DNSKEY: checking existence of DS at <span class="s1">'org'</span>
	<span class="p">;;</span> validating dnssec-failed.org/DNSKEY: checking existence of DS at <span class="s1">'dnssec-failed.org'</span>
	<span class="p">;;</span> validating dnssec-failed.org/DNSKEY: insecurity proof failed
	<span class="p">;;</span> resolution failed: no valid RRSIG
</code></pre></div></div>

<p>And this is when everything works fine:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>delv bkraft.fr
	<span class="p">;</span> fully validated
	bkraft.fr.		1715	IN	A	88.190.215.226
	bkraft.fr.		1715	IN	RRSIG	A 8 2 3600 20140517114420 20140417110001 17781 bkraft.fr. tpKCap/U35Al0wplUXg4t91X/8IuuF1lLQE5+cefGoymgmMdXXRVewb9 nuL2k+v4SaodwHzF/prDeLVOtuEw/Rd8ACKZc38aU9ZUigUNU0BkTMxe FeasgXOaQwr5WN8MlzTjW2IWRx8VH1A+YHlf2wzPRQAE8HCvJXdM+61m Ojj+T4Eu5nVm0dU7ROSMuRtPlMnoquYOni7fg9Cmkn62wqaGNaFZu7iy 1dio5ByH3XQWJAZDTh72RWuNJtOyQPFn2J/WAvid/PScyLxYNy7SiIZ1 qhPgMWBezxBzdmds/ZlM8TvKy0gFELMoYoHc5L6l6C+iul1Byel57Alf <span class="nv">jguDxw</span><span class="o">==</span>
</code></pre></div></div>

<p>I can bet that in the next weeks/months/years, we will need to use such kind of tool more and more often as <code class="language-plaintext highlighter-rouge">DNSSEC</code> spreads. Please also note that the <code class="language-plaintext highlighter-rouge">+sigchase</code> and <code class="language-plaintext highlighter-rouge">+topdown</code> switches have been removed from <code class="language-plaintext highlighter-rouge">dig</code>, starting with <code class="language-plaintext highlighter-rouge">bind 9.10</code>.</p>]]></content><author><name></name></author><category term="system" /><summary type="html"><![CDATA[]]></summary></entry><entry><title type="html">Setup Bind as DNSSEC validating resolver</title><link href="https://bkraft.fr/system/2014/04/12/bind-dnssec-validating-resolver.html" rel="alternate" type="text/html" title="Setup Bind as DNSSEC validating resolver" /><published>2014-04-12T19:00:00+00:00</published><updated>2014-04-12T19:00:00+00:00</updated><id>https://bkraft.fr/system/2014/04/12/bind-dnssec-validating-resolver</id><content type="html" xml:base="https://bkraft.fr/system/2014/04/12/bind-dnssec-validating-resolver.html"><![CDATA[<ul id="markdown-toc">
  <li><a href="#add-some-security-to-the-most-important-service" id="markdown-toc-add-some-security-to-the-most-important-service">Add some security to the most important service</a>    <ul>
      <li><a href="#installation" id="markdown-toc-installation">Installation</a></li>
      <li><a href="#configuration" id="markdown-toc-configuration">Configuration</a></li>
      <li><a href="#testing" id="markdown-toc-testing">Testing</a></li>
    </ul>
  </li>
</ul>

<h1 id="add-some-security-to-the-most-important-service">Add some security to the most important service</h1>

<p>The sooner or the later, <code class="language-plaintext highlighter-rouge">DNSSEC</code> will be deployed globally (although I don’t think this will be an easy story, we’ll need to see the evolutions of related software) and you’ll be in the need to have a <code class="language-plaintext highlighter-rouge">DNSSEC</code> enabled validating nameserver that will do the checks for you. This is a very small and simple tutorial to deploy one of those.</p>

<p>Last day’s <a href="http://jpmens.net/2012/04/19/dnssec-training/">post</a> from Jan-Piet Mens about the great <a href="http://www.dnsseccourse.nl/">SIDN DNSSEC</a> training made me think that it would be nice to show how to setup a basic validating <code class="language-plaintext highlighter-rouge">DNSSEC</code> resolver based on the packages that I’m providing on this very website (Bind 9.9.0 and Bind 9.8.2).</p>

<h2 id="installation">Installation</h2>

<p>It’s pretty straight forward, just install bind. (in fact, <code class="language-plaintext highlighter-rouge">bind-chroot</code> won’t be needed here)</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>rpm <span class="nt">-Uvh</span> noarch/bind-license-9.8.1-2.el6.noarch.rpm 
	Preparing...             <span class="c">############################### [100%]</span>
   	1:bind-license           <span class="c">############################### [100%]</span>
rpm <span class="nt">-Uvh</span> bind-chroot-9.8.1-2.el6.x86_64.rpm bind-9.8.1-2.el6.x86_64.rpm bind-libs-9.8.1-2.el6.x86_64.rpm bind-utils-9.8.1-2.el6.x86_64.rpm 
	Preparing...             <span class="c">############################### [100%]</span>
   	1:bind-libs              <span class="c">############################### [ 25%]</span>
   	2:bind                   <span class="c">############################### [ 50%]</span>
   	3:bind-chroot            <span class="c">############################### [ 75%]</span>
   	4:bind-utils             <span class="c">############################### [100%]</span>
</code></pre></div></div>

<h2 id="configuration">Configuration</h2>

<pre><code class="language-bind">options {
	listen-on port 53 { any; };
	listen-on-v6 port 53 { ::1; };
	directory 	"/var/named";
	dump-file 	"/var/named/data/cache_dump.db";
	statistics-file "/var/named/data/named_stats.txt";
	memstatistics-file "/var/named/data/named_mem_stats.txt";
	allow-query     { any; };
	recursion yes;
    version "[Secured]";
	
/* Those are the values you should disable if you don't want DNSSEC enabled */
	dnssec-enable yes;
	dnssec-validation yes;
	dnssec-lookaside auto;

/* Path to ISC DLV key */
	bindkeys-file "/etc/named.iscdlv.key";

	managed-keys-directory "/var/named/dynamic";
};

logging {
        channel default_debug {
                file "data/named.run";
                severity dynamic;
        };
};

zone "." IN {
	type hint;
	file "named.ca";
};

include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";
</code></pre>

<h2 id="testing">Testing</h2>

<p>Once configured and started, let’s query the resolver without asking for <code class="language-plaintext highlighter-rouge">DNSSEC</code> validation.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>dig bkraft.fr @localhost

	<span class="p">;</span> &lt;&lt;<span class="o">&gt;&gt;</span> DiG 9.8.2-RedHat-9.8.2-0.el6 &lt;&lt;<span class="o">&gt;&gt;</span> bkraft.fr @localhost
	<span class="p">;;</span> global options: +cmd
	<span class="p">;;</span> Got answer:
	<span class="p">;;</span> -&gt;&gt;HEADER<span class="o">&lt;&lt;-</span> <span class="no">opcode</span><span class="sh">: QUERY, status: NOERROR, id: 3408
	;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 2, ADDITIONAL: 0

	;; QUESTION SECTION:
	;bkraft.fr.			IN	A

	;; ANSWER SECTION:
	bkraft.fr.		300	IN	A	173.245.61.141
	bkraft.fr.		300	IN	A	173.245.61.54

	;; AUTHORITY SECTION:
	bkraft.fr.		172799	IN	NS	kara.ns.cloudflare.com.
	bkraft.fr.		172799	IN	NS	greg.ns.cloudflare.com.

	;; Query time: 958 msec
	;; SERVER: 127.0.0.1#53(127.0.0.1)
	;; WHEN: Sun Feb 19 16:36:11 2012
	;; MSG SIZE  rcvd: 114
</span></code></pre></div></div>

<p>Fine, now query with validation enabled :</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>dig +dnssec dns.be @localhost

	<span class="p">;</span> &lt;&lt;<span class="o">&gt;&gt;</span> DiG 9.8.2-RedHat-9.8.2-0.el6 &lt;&lt;<span class="o">&gt;&gt;</span> +dnssec dns.be @localhost
	<span class="p">;;</span> global options: +cmd
	<span class="p">;;</span> Got answer:
	<span class="p">;;</span> -&gt;&gt;HEADER<span class="o">&lt;&lt;-</span> <span class="no">opcode</span><span class="sh">: QUERY, status: NOERROR, id: 42709
	;; flags: qr rd ra ad; QUERY: 1, ANSWER: 3, AUTHORITY: 7, ADDITIONAL: 13

	;; OPT PSEUDOSECTION:
	; EDNS: version: 0, flags: do; udp: 4096
	;; QUESTION SECTION:
	;dns.be.				IN	A

	;; ANSWER SECTION:
	dns.be.			3543	IN	A	149.126.56.7
	dns.be.			3543	IN	A	149.126.56.6
	dns.be.			3543	IN	RRSIG	A 8 2 3600 20120327144240 20120216135245 43356 dns.be. VUaS4KOKTXJAof7CbI/jz1StoEngTK5C5ldtgI534GWOJa4eqqkqCs2/ TRm7F7E/YO7cLLcBh+BJhsR9cb3zZq9e8RM5vc6nTI6s6NgIbWDGoZNl RkAeb5M4E7kjL6jGnyiT83bPEnbeJNXlHtFnrv/ZqT6RWv/zVGLHP/NN QX0=

	;; AUTHORITY SECTION:
	dns.be.			86342	IN	NS	brussels.ns.dns.be.
	dns.be.			86342	IN	NS	m.ns.dns.be.
	dns.be.			86342	IN	NS	prague.ns.dns.be.
	dns.be.			86342	IN	NS	c.ns.dns.be.
	dns.be.			86342	IN	NS	amsterdam.ns.dns.be.
	dns.be.			86342	IN	NS	london.ns.dns.be.
	dns.be.			86342	IN	RRSIG	NS 8 2 86400 20120327144240 20120216135245 43356 dns.be. hBRmAgH31yopygpKIlAeUwtwx4EXjPESJlbArjn+GgH1kkwyEB4SVBi6 Hrs8/XzGZXUHLB5jiCinvq9er2jST7xqJMzuqQXP3I8o6JiHmReYvX3+ KXhinSxDRFqwa77o5d3HZXZyag2XXlYkoRkQYVoOvxU3m2zF3fUKIPMQ 2hQ=

	;; ADDITIONAL SECTION:
	&lt;..snip..&gt;

	;; Query time: 0 msec
	;; SERVER: 127.0.0.1#53(127.0.0.1)
	;; WHEN: Sun Feb 19 16:38:44 2012
	;; MSG SIZE  rcvd: 1627
</span></code></pre></div></div>

<p>Great ! The <code class="language-plaintext highlighter-rouge">ad</code> flag means that the data displayed has been authenticated, the <code class="language-plaintext highlighter-rouge">OPT</code> pseudosection shows that our server used <code class="language-plaintext highlighter-rouge">EDNS0</code> to pass over the 512bits limit and finally we see all RRSIG for each displayed part of the response.</p>

<p>Using validation now is good, but the fact that all signing and key rollover management softwares are still pretty young, you should be warned that enabling <code class="language-plaintext highlighter-rouge">DNSSEC</code> might lead you to not see expected results where a standard resolver would respond. Also, it’s a good idea to limit the number of queries to this resolver as <code class="language-plaintext highlighter-rouge">DNSSEC</code> validation adds overhead on the server in comparison to standard resolution.</p>]]></content><author><name></name></author><category term="system" /><summary type="html"><![CDATA[]]></summary></entry><entry><title type="html">Securing CentOS 6 installation</title><link href="https://bkraft.fr/system/2012/03/18/securing-centos6-installation.html" rel="alternate" type="text/html" title="Securing CentOS 6 installation" /><published>2012-03-18T19:00:00+00:00</published><updated>2012-03-18T19:00:00+00:00</updated><id>https://bkraft.fr/system/2012/03/18/securing-centos6-installation</id><content type="html" xml:base="https://bkraft.fr/system/2012/03/18/securing-centos6-installation.html"><![CDATA[<ul id="markdown-toc">
  <li><a href="#activate-the-available-shields-to-protect-your-server" id="markdown-toc-activate-the-available-shields-to-protect-your-server">Activate the available shields to protect your server</a>    <ul>
      <li><a href="#prerequisites" id="markdown-toc-prerequisites">Prerequisites</a></li>
      <li><a href="#unnecessary-services" id="markdown-toc-unnecessary-services">Unnecessary services</a></li>
      <li><a href="#protecting-ssh-service" id="markdown-toc-protecting-ssh-service">Protecting SSH service</a></li>
      <li><a href="#small-things-that-matters" id="markdown-toc-small-things-that-matters">Small things that matters</a></li>
      <li><a href="#narrow-down-rights" id="markdown-toc-narrow-down-rights">Narrow down rights</a></li>
      <li><a href="#secure-network-via-sysctl" id="markdown-toc-secure-network-via-sysctl">Secure network via sysctl</a></li>
      <li><a href="#delete-unnecessary-users" id="markdown-toc-delete-unnecessary-users">Delete unnecessary users</a></li>
      <li><a href="#tuning-openssh" id="markdown-toc-tuning-openssh">Tuning OpenSSH</a></li>
      <li><a href="#removing-kernel-modules" id="markdown-toc-removing-kernel-modules">Removing kernel modules</a></li>
    </ul>
  </li>
</ul>

<h1 id="activate-the-available-shields-to-protect-your-server">Activate the available shields to protect your server</h1>

<p>The default CentOS installation provides many security features that are not enabled by default and that we all should take benefit of. Here are some to consider.</p>

<h2 id="prerequisites">Prerequisites</h2>

<p>The media used for this tutorial is the CentOS 6.2 minimal installation CD. There’s no way to make a mistake when choosing packages with this installation media, because you can’t. It just installs the minimal software. Make sure that you install the EPEL project repository.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>rpm <span class="nt">-Uvh</span> http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-5.noarch.rpm
   Retrieving http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-5.noarch.rpm
   warning: /var/tmp/rpm-tmp.VseyUg: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
   Preparing...                <span class="c">########################################### [100%]</span>
      1:epel-release           <span class="c">########################################### [100%]</span>
</code></pre></div></div>

<p>And make sure that your server is up to date.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>yum update <span class="nt">-y</span>
</code></pre></div></div>

<h2 id="unnecessary-services">Unnecessary services</h2>

<p>To limit the available attack surface available on the server, we’ll simply shut down the unnecessary services (well, those that I do think I don’t need for, let’s say, a webserver) and prevent them from starting at next reboot. These are the following services I’m going to disable :</p>

<ul>
  <li><strong>rpcbind</strong> The rpcbind utility is a server that converts RPC program numbers into universal addresses. It must be running on the host to be able to make RPC calls on a server on that machine.</li>
  <li><strong>nfslock</strong> Starts up the NFS file locking service</li>
  <li><strong>lldpad</strong> Link Layer Discovery Protocol Agent Daemon</li>
  <li><strong>fcoe</strong> Open-FCoE Initiator</li>
  <li><strong>rpdidmapd</strong> This deamon maps user names and groups to UID and GID numbers on NFSv4 mounts</li>
</ul>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">for </span>i <span class="k">in </span>rpcbind  nfslock  lldpad fcoe rpcidmapd<span class="p">;</span> <span class="k">do </span>service <span class="nv">$i</span> stop<span class="p">;</span> chkconfig <span class="nv">$i</span> off<span class="p">;</span> <span class="k">done
   </span>Stopping rpcbind:                                          <span class="o">[</span>  OK  <span class="o">]</span>
   Stopping NFS statd:                                        <span class="o">[</span>  OK  <span class="o">]</span>
   Stopping lldpad:                                           <span class="o">[</span>  OK  <span class="o">]</span>
   Stopping FCoE initiator service:                           <span class="o">[</span>  OK  <span class="o">]</span>
   Stopping RPC idmapd:                                       <span class="o">[</span>  OK  <span class="o">]</span>
</code></pre></div></div>

<h2 id="protecting-ssh-service">Protecting SSH service</h2>

<p>As this is one the core and mostly attacked services, we need to protect ourselves against one of the most common threats : brute force attacks. For this, we are going to set up Fail2ban that will account for us the number of times a server will occur with failed authentications attempts and add the corresponding ip address to iptables reject list (a specific iptables user chain that returns until the ip is listed in it, to be exact). The package file comes from the EPEL project, and I build a configuration file specifically for this simple purpose :</p>

<div class="language-ini highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nn">[DEFAULT]</span>
<span class="py">ignoreip</span> <span class="p">=</span> <span class="s">127.0.0.1</span>
<span class="c"># Block the attacking host for a day
</span><span class="py">bantime</span>  <span class="p">=</span> <span class="s">86400</span>
<span class="c"># If it appears in the watched log file for the last hour
</span><span class="py">findtime</span>  <span class="p">=</span> <span class="s">3600</span>
<span class="c"># And generated 3 error messages
</span><span class="py">maxretry</span> <span class="p">=</span> <span class="s">3</span>
<span class="py">backend</span> <span class="p">=</span> <span class="s">auto</span>

<span class="nn">[ssh-iptables]</span>

<span class="py">enabled</span>  <span class="p">=</span> <span class="s">true</span>
<span class="py">filter</span>   <span class="p">=</span> <span class="s">sshd</span>
<span class="py">action</span>   <span class="p">=</span> <span class="s">iptables[name=SSH, port=ssh, protocol=tcp]</span>
<span class="c"># Optionnal : sendmail-whois[name=SSH, dest=root, sender=fail2ban@mail.com]
</span><span class="py">logpath</span>  <span class="p">=</span> <span class="s">/var/log/secure</span>
<span class="py">maxretry</span> <span class="p">=</span> <span class="s">3</span>
</code></pre></div></div>

<p>So now, install it, configure it using the custom jail.conf and make the service start when the system boots.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>yum <span class="nb">install </span>fail2ban
curl http://bkraft.fr/files/Configurations/fail2ban/jail.conf <span class="nt">-o</span> /etc/fail2ban/jail.conf
chkconfig fail2ban on
service fail2ban start
   Starting fail2ban:                                          <span class="o">[</span>  OK  <span class="o">]</span>
</code></pre></div></div>

<p>We now can see that there is an iptables chain called fail2ban-SSH as you can see below.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>iptables-save 
   <span class="c"># Generated by iptables-save v1.4.7 on Sat Mar 10 22:09:08 2012</span>
   <span class="k">*</span>filter
   :INPUT ACCEPT <span class="o">[</span>0:0]
   :FORWARD ACCEPT <span class="o">[</span>0:0]
   :OUTPUT ACCEPT <span class="o">[</span>17:1492]
   :fail2ban-SSH - <span class="o">[</span>0:0]
   <span class="nt">-A</span> INPUT <span class="nt">-p</span> tcp <span class="nt">-m</span> tcp <span class="nt">--dport</span> 22 <span class="nt">-j</span> fail2ban-SSH 
   <span class="nt">-A</span> INPUT <span class="nt">-m</span> state <span class="nt">--state</span> RELATED,ESTABLISHED <span class="nt">-j</span> ACCEPT 
   <span class="nt">-A</span> INPUT <span class="nt">-p</span> icmp <span class="nt">-j</span> ACCEPT 
   <span class="nt">-A</span> INPUT <span class="nt">-i</span> lo <span class="nt">-j</span> ACCEPT 
   <span class="nt">-A</span> INPUT <span class="nt">-p</span> tcp <span class="nt">-m</span> state <span class="nt">--state</span> NEW <span class="nt">-m</span> tcp <span class="nt">--dport</span> 22 <span class="nt">-j</span> ACCEPT 
   <span class="nt">-A</span> INPUT <span class="nt">-j</span> REJECT <span class="nt">--reject-with</span> icmp-host-prohibited 
   <span class="nt">-A</span> FORWARD <span class="nt">-j</span> REJECT <span class="nt">--reject-with</span> icmp-host-prohibited 
   <span class="nt">-A</span> fail2ban-SSH <span class="nt">-j</span> RETURN 
   COMMIT
   <span class="c"># Completed on Sat Mar 10 22:09:08 2012</span>
</code></pre></div></div>

<h2 id="small-things-that-matters">Small things that matters</h2>

<p>In single user mode, ask for password</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>perl <span class="nt">-i</span> <span class="nt">-pe</span> <span class="s1">'s/sushell/sulogin/'</span> /etc/sysconfig/init
</code></pre></div></div>
<p>Change the number of available gettys as there is too much of them available by default.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>perl <span class="nt">-i</span> <span class="nt">-pe</span> <span class="s1">'s/1-6/1/'</span> /etc/sysconfig/init
perl <span class="nt">-i</span> <span class="nt">-pe</span> <span class="s1">'s/1-6/1/'</span> /etc/init/start-ttys.conf
</code></pre></div></div>
<p>Prevent prompting for interactive boot</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>perl <span class="nt">-i</span> <span class="nt">-pe</span> <span class="s1">'s/PROMPT=yes/PROMPT=no/'</span> /etc/sysconfig/init
</code></pre></div></div>
<p>Prevent rebooting when Control-Alt-Delete is being pressed on the console.</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>perl <span class="nt">-i</span> <span class="nt">-pe</span> <span class="s1">'s/exec.*/exec \/bin\/echo "Control-Alt-Delete pressed, but no action will be taken"/'</span> /etc/init/control-alt-delete.conf
</code></pre></div></div>
<p>Change the minimum password length from 5 to 9</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>perl <span class="nt">-i</span> <span class="nt">-pe</span> <span class="s1">'s/PASS_MIN_LEN\s+5/PASS_MIN_LEN  9/'</span> /etc/login.defs
</code></pre></div></div>
<p>Disconnect idle users after 15 minutes</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">cat</span> <span class="o">&gt;</span> /etc/profile.d/inactive-users-disconnect.sh <span class="o">&lt;&lt;</span> <span class="no">EOF</span><span class="sh">
readonly TMOUT=900
readonly HISTFILE
</span><span class="no">EOF 
</span><span class="nb">chmod</span> +x /etc/profile.d/inactive-users-disconnect.sh
</code></pre></div></div>
<p>Prevent anybody but root to run cron or at tasks</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">touch</span> /etc/cron.allow
<span class="nb">chmod </span>600 /etc/cron.allow
<span class="nb">awk</span> <span class="nt">-F</span>: <span class="s1">'{print $1}'</span> /etc/passwd | <span class="nb">grep</span> <span class="nt">-v</span> root <span class="o">&gt;</span> /etc/cron.deny
<span class="nb">touch</span> /etc/at.allow
<span class="nb">chmod </span>600 /etc/at.allow
<span class="nb">awk</span> <span class="nt">-F</span>: <span class="s1">'{print $1}'</span> /etc/passwd | <span class="nb">grep</span> <span class="nt">-v</span> root <span class="o">&gt;</span> /etc/at.deny
</code></pre></div></div>

<p>Be careful, consistency of <code class="language-plaintext highlighter-rouge">at.deny</code> and <code class="language-plaintext highlighter-rouge">cron.deny</code> is not guaranteed over time. you should care about it (rerun the awks by hand or by cron)</p>

<p>Change /etc/issue to something scary</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">cat</span> <span class="o">&gt;</span>/etc/issue <span class="o">&lt;&lt;</span> <span class="no">EOF</span><span class="sh">
USE OF THIS COMPUTER SYSTEM, AUTHORIZED OR UNAUTHORIZED, CONSTITUTES CONSENT TO MONITORING OF THIS SYSTEM.
UNAUTHORIZED USE MAY SUBJECT YOU TO CRIMINAL PROSECUTION.
EVIDENCE OF UNAUTHORIZED USE COLLECTED DURING MONITORING MAY BE USED FOR ADMINISTRATIVE, CRIMINAL, OR OTHER ADVERSE ACTION.
USE OF THIS SYSTEM CONSTITUTES CONSENT TO MONITORING FOR THESE PURPOSES.
</span><span class="no">EOF
</span></code></pre></div></div>

<h2 id="narrow-down-rights">Narrow down rights</h2>

<p>Many of the files have by default too wide rights that might led to disclose some important informations.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># Narrow down right on /root</span>
<span class="nb">chmod </span>700 /root

<span class="c"># Audit logs should be available only for root</span>
<span class="nb">chmod </span>700 /var/log/audit

<span class="c"># Remove too wide rights on iptables binary and init scripts</span>
<span class="nb">chmod </span>740 /etc/rc.d/init.d/iptables
<span class="nb">chmod </span>740 /sbin/iptables

<span class="c"># Change the rights of the default user skeleton</span>
<span class="nb">chmod</span> <span class="nt">-R</span> 700 /etc/skel

<span class="c"># Restrict access to rsyslog configuration to root</span>
<span class="nb">chmod </span>600 /etc/rsyslog.conf

<span class="c"># Locking down LNX00440</span>
<span class="nb">chmod </span>640 /etc/security/access.conf

<span class="c"># Sysctl configuration should only accessible to root</span>
<span class="nb">chmod </span>600 /etc/sysctl.conf
</code></pre></div></div>

<h2 id="secure-network-via-sysctl">Secure network via sysctl</h2>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">cat</span> <span class="o">&lt;&lt;</span> <span class="sh">'</span><span class="no">EOF</span><span class="sh">' &gt;&gt; /etc/sysctl.conf
	# disable packet forwarding
	net.ipv4.ip_forward = 0
	# drop icmp redirects
	net.ipv4.conf.all.send_redirects = 0
	net.ipv4.conf.default.send_redirects = 0
	net.ipv4.conf.all.accept_redirects = 0
	net.ipv4.conf.all.secure_redirects = 0
	net.ipv4.conf.default.accept_redirects = 0
	net.ipv4.conf.default.secure_redirects = 0
	# double the syn backlog size
	net.ipv4.tcp_max_syn_backlog = 2048
	# ignore ping broadcasts
	net.ipv4.icmp_echo_ignore_broadcasts = 1
	# drop the source routing ability
	net.ipv4.conf.all.accept_source_route = 0
	net.ipv4.conf.default.accept_source_route = 0
	# log packets destinated to impossible addresses
	net.ipv4.conf.all.log_martians = 1
	# ignore bogus icmp error responses
	net.ipv4.icmp_ignore_bogus_error_responses = 1
	# protect a bit from SYN flood attacks
	net.ipv4.tcp_syncookies = 1
	# drop packets that come in using a bad interface
	# (they will be logged as martian)
	net.ipv4.conf.all.rp_filter = 1
	net.ipv4.conf.default.rp_filter = 1
	# don't send timestamps
	net.ipv4.tcp_timestamps = 0
</span><span class="no">EOF
</span></code></pre></div></div>
<h2 id="delete-unnecessary-users">Delete unnecessary users</h2>

<p>By default many users are present that aren’t necessary, let’s just get rid of them.</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>/usr/sbin/userdel shutdown
/usr/sbin/userdel halt
/usr/sbin/userdel games
/usr/sbin/userdel operator
/usr/sbin/userdel ftp
/usr/sbin/userdel gopher
</code></pre></div></div>
<h2 id="tuning-openssh">Tuning OpenSSH</h2>

<p>As per this setup, the SSH service is opened on internet, and we need to make sure that it is secured. By default, it is already well secured, but there is some things we should change.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># Prevent ssh connections from root</span>
perl <span class="nt">-i</span> <span class="nt">-pe</span> <span class="s1">'s/#PermitRootLogin yes/PermitRootLogin no/'</span> /etc/ssh/sshd_config
<span class="c"># Set our scary issue message as ssh banner</span>
perl <span class="nt">-i</span> <span class="nt">-pe</span> <span class="s1">'s/#Banner.*/Banner \/etc\/issue/g'</span> /etc/ssh/sshd_config

<span class="c"># Make the server keys a bit bigger</span>
perl <span class="nt">-i</span> <span class="nt">-pe</span> <span class="s1">'s/^#ServerKeyBits 1024/ServerKeyBits 2048/g'</span> /etc/ssh/sshd_config
<span class="c"># We need now to drop previously created 1024 keys and regenerate them.</span>
<span class="nb">rm</span> <span class="nt">-vf</span> /etc/ssh/ssh_host<span class="k">*</span>
	removed <span class="sb">`</span>/etc/ssh/ssh_host_dsa_key<span class="s1">'
	removed `/etc/ssh/ssh_host_dsa_key.pub'</span>
	removed <span class="sb">`</span>/etc/ssh/ssh_host_key<span class="s1">'
	removed `/etc/ssh/ssh_host_key.pub'</span>
	removed <span class="sb">`</span>/etc/ssh/ssh_host_rsa_key<span class="s1">'
	removed `/etc/ssh/ssh_host_rsa_key.pub'</span>
/etc/init.d/sshd restart
	Stopping sshd:                                             <span class="o">[</span>  OK  <span class="o">]</span>
	Generating SSH1 RSA host key:                              <span class="o">[</span>  OK  <span class="o">]</span>
	Generating SSH2 RSA host key:                              <span class="o">[</span>  OK  <span class="o">]</span>
	Generating SSH2 DSA host key:                              <span class="o">[</span>  OK  <span class="o">]</span>
	Starting sshd:                                             <span class="o">[</span>  OK  <span class="o">]</span>

<span class="c"># Restrict max authentications</span>
perl <span class="nt">-i</span> <span class="nt">-pe</span> <span class="s1">'s/^#MaxAuthTries 6/MaxAuthTries 3/g'</span> /etc/ssh/sshd_config
</code></pre></div></div>

<h2 id="removing-kernel-modules">Removing kernel modules</h2>

<p>As the machine that I’m running is a virtual one, I don’t need wireless drivers to be loaded and neither do I need fcoe, so let’s just blacklist them.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">for </span>i <span class="k">in</span> <span class="si">$(</span>find /lib/modules/<span class="sb">`</span><span class="nb">uname</span> <span class="nt">-r</span><span class="sb">`</span>/kernel/drivers/net/wireless <span class="nt">-name</span> <span class="s2">"*.ko"</span> <span class="nt">-type</span> f<span class="si">)</span> <span class="p">;</span> <span class="k">do </span><span class="nb">echo </span>blacklist <span class="nv">$i</span> <span class="o">&gt;&gt;</span> /etc/modprobe.d/blacklist-wireless.conf <span class="p">;</span> <span class="k">done
for </span>i <span class="k">in</span> <span class="si">$(</span>find /lib/modules/<span class="sb">`</span><span class="nb">uname</span> <span class="nt">-r</span><span class="sb">`</span>/kernel/drivers/scsi/fcoe <span class="nt">-name</span> <span class="s2">"*.ko"</span> <span class="nt">-type</span> f<span class="si">)</span> <span class="p">;</span> <span class="k">do </span><span class="nb">echo </span>blacklist <span class="nv">$i</span> <span class="o">&gt;&gt;</span> /etc/modprobe.d/blacklist-fcoe.conf <span class="p">;</span> <span class="k">done</span>
</code></pre></div></div>]]></content><author><name></name></author><category term="system" /><summary type="html"><![CDATA[]]></summary></entry><entry><title type="html">Tunneling connections with Putty</title><link href="https://bkraft.fr/system/2009/12/03/tunneling-connections-with-putty.html" rel="alternate" type="text/html" title="Tunneling connections with Putty" /><published>2009-12-03T19:00:00+00:00</published><updated>2009-12-03T19:00:00+00:00</updated><id>https://bkraft.fr/system/2009/12/03/tunneling-connections-with-putty</id><content type="html" xml:base="https://bkraft.fr/system/2009/12/03/tunneling-connections-with-putty.html"><![CDATA[<ul id="markdown-toc">
  <li><a href="#how-to-use-the-ssh-protocol-to-encapsulate-traffic-on-windows" id="markdown-toc-how-to-use-the-ssh-protocol-to-encapsulate-traffic-on-windows">How to use the SSH protocol to encapsulate traffic on Windows</a>    <ul>
      <li><a href="#howto" id="markdown-toc-howto">Howto</a></li>
    </ul>
  </li>
</ul>

<h1 id="how-to-use-the-ssh-protocol-to-encapsulate-traffic-on-windows">How to use the SSH protocol to encapsulate traffic on Windows</h1>

<p>Let’s say, you want to access a remote server on ports TCP 7333 and 809, but they are closed by your network administrator and you just can connect via SSH to the remote server (this howto works with a third server that could be used to tunnel connections). This is far enough, you can use PuTTY to forward the connections from your local machine to the remote ports via a SSH connection.</p>

<h2 id="howto">Howto</h2>

<p>To do this, open PuTTY, and enter the hostname on which you are able to connect :</p>

<p><img src="/assets/images/tunneling-connections-with-putty/01.jpg" alt="01" /></p>

<p>Then, go to Connection, SSH and Tunnels</p>

<p><img src="/assets/images/tunneling-connections-with-putty/02.jpg" alt="02" /></p>

<p>Here, add source port 802 and destination server.domain.tld:802</p>

<p><img src="/assets/images/tunneling-connections-with-putty/03.jpg" alt="03" /></p>

<p>Click add, and then add source port 7333 and destination server.domain.tld:7333</p>

<p><img src="/assets/images/tunneling-connections-with-putty/04.jpg" alt="04" /></p>

<p>Then finally, click add and open</p>

<p><img src="/assets/images/tunneling-connections-with-putty/05.jpg" alt="05" /></p>

<p>Now, if you connect to localhost at port 7333 or 802, your connections will be forwarded from your local machine to the remote server.</p>

<blockquote>
  <p>[!NOTE] If you close PuTTY, your tunnels will be closed too.</p>
</blockquote>]]></content><author><name></name></author><category term="system" /><summary type="html"><![CDATA[]]></summary></entry><entry><title type="html">Loadbalancing your servers with LVS using connmark</title><link href="https://bkraft.fr/system/2009/11/28/loadbalancing-your-servers-with-LVS-using-connmark.html" rel="alternate" type="text/html" title="Loadbalancing your servers with LVS using connmark" /><published>2009-11-28T19:00:00+00:00</published><updated>2009-11-28T19:00:00+00:00</updated><id>https://bkraft.fr/system/2009/11/28/loadbalancing-your-servers-with-LVS-using-connmark</id><content type="html" xml:base="https://bkraft.fr/system/2009/11/28/loadbalancing-your-servers-with-LVS-using-connmark.html"><![CDATA[<ul id="markdown-toc">
  <li><a href="#face-the-load" id="markdown-toc-face-the-load">Face the load</a>    <ul>
      <li><a href="#foreword" id="markdown-toc-foreword">Foreword</a></li>
      <li><a href="#installing-necessary-packages" id="markdown-toc-installing-necessary-packages">Installing necessary packages</a></li>
      <li><a href="#network-configuration" id="markdown-toc-network-configuration">Network configuration</a></li>
      <li><a href="#prevent-arp-problems" id="markdown-toc-prevent-arp-problems">Prevent ARP problems</a></li>
      <li><a href="#let-packets-go-through-the-load-balancer" id="markdown-toc-let-packets-go-through-the-load-balancer">Let packets go through the load balancer</a></li>
      <li><a href="#marking-packets-that-should-be-load-balanced" id="markdown-toc-marking-packets-that-should-be-load-balanced">Marking packets that should be load-balanced</a></li>
      <li><a href="#setting-up-the-ipvs-rules" id="markdown-toc-setting-up-the-ipvs-rules">Setting up the ipvs rules</a></li>
      <li><a href="#putting-some-load-on-the-load-balancing-ip" id="markdown-toc-putting-some-load-on-the-load-balancing-ip">Putting some load on the load balancing ip</a></li>
    </ul>
  </li>
</ul>

<h1 id="face-the-load">Face the load</h1>

<h2 id="foreword">Foreword</h2>

<p>One time or another, you’ll be facing the problem that your webserver isn’t powerfull enough as it can’t handle all the incoming traffic.
You may at this moment consider using load balancing the charge between more than one server.</p>

<p>Here is what you’ll have to know about the Network topology overview related to this howto:</p>

<ul>
  <li><strong>client ip address:</strong> 192.168.0.10</li>
  <li><strong>lb ip address:</strong> 192.168.0.107</li>
  <li><strong>server1 ip address:</strong> 192.168.0.108</li>
  <li><strong>server2 ip address:</strong> 192.168.0.109</li>
  <li><strong>ip address used for loadbalancing:</strong> 192.168.0.50</li>
</ul>

<blockquote>
  <p>[!NOTE] Note: in this tutorial, I use the ifconfig command to configure interfaces, and I really don’t recommend you to do so. ifconfig is really deprecated and buggy on RedHat based systems, I strongly suggest you to use the ip command instead.</p>
</blockquote>

<h2 id="installing-necessary-packages">Installing necessary packages</h2>

<p><code class="language-plaintext highlighter-rouge">iptables</code> should already been installed on your system, but make sure of it.
Next thing you’ll need is <code class="language-plaintext highlighter-rouge">ipvsadm</code> on the load balancer :</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>yum <span class="nb">install </span>ipvsadm
<span class="o">=&gt;</span>	Loaded plugins: fastestmirror
	Loading mirror speeds from cached hostfile
	 ...
	Setting up Install Process
	Resolving Dependencies
	<span class="nt">--</span><span class="o">&gt;</span> Running transaction check
	<span class="nt">---</span><span class="o">&gt;</span> Package ipvsadm.i386 0:1.24-10 <span class="nb">set </span>to be updated
	<span class="nt">--</span><span class="o">&gt;</span> Finished Dependency Resolution
	...
	Complete!
</code></pre></div></div>

<h2 id="network-configuration">Network configuration</h2>

<p>Now you should add the ip dedicated for load balancing on servers.</p>

<p>As alias of <code class="language-plaintext highlighter-rouge">eth0</code> on the load balancer :</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>ifconfig eth0:0 192.168.0.50 netmask 255.255.255.0
ifconfig eth0:0
<span class="o">=&gt;</span>	eth0:0    Link encap:Ethernet  HWaddr 00:0C:29:5A:78:22
	          inet addr:192.168.0.50  Bcast:192.168.0.255  Mask:255.255.255.0
	          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
	          Interrupt:75 Base address:0x2000
</code></pre></div></div>

<p>And as alias of <code class="language-plaintext highlighter-rouge">lo:0</code> on server1 and server2 :</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>ifconfig lo:0 192.168.0.50 netmask 255.255.255.255
ifconfig lo:0
<span class="o">=&gt;</span>	lo:0      Link encap:Local Loopback
	          inet addr:192.168.0.50  Mask:255.255.255.255
	          UP LOOPBACK RUNNING  MTU:16436  Metric:1
ifconfig lo:0 192.168.0.50 netmask 255.255.255.255
ifconfig lo:0
<span class="o">=&gt;</span>	lo:0      Link encap:Local Loopback
	          inet addr:192.168.0.50  Mask:255.255.255.255
	          UP LOOPBACK RUNNING  MTU:16436  Metric:1
</code></pre></div></div>

<p>Yeah, this is not a permanent way to configure the interfaces, but that’s specific to your distribution, so, do it your way.</p>

<h2 id="prevent-arp-problems">Prevent ARP problems</h2>

<p>Well, as you configured ip addresses on all servers, every one of them will start to claim “i’ve got the 192.168.0.50 address !!!” via arp packets. This can result on an ARP tempest if you did this on many servers, and most certainly you’ll not be able to use the IP.</p>

<p>There’s a way of preventing this from happening, by telling servers to ignore arp and do not announce when they change something.
Put this in <code class="language-plaintext highlighter-rouge">/etc/sysctl.conf</code> of <em>each</em> real server:</p>

<div class="language-ini highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="py">net.ipv4.conf.all.arp_ignore</span> <span class="p">=</span> <span class="s">1</span>
<span class="py">net.ipv4.conf.all.arp_announce</span> <span class="p">=</span> <span class="s">2</span>
</code></pre></div></div>

<p>Then, apply changes you made in the <code class="language-plaintext highlighter-rouge">sysctl.conf</code> file :</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sysctl <span class="nt">-p</span>
</code></pre></div></div>

<h2 id="let-packets-go-through-the-load-balancer">Let packets go through the load balancer</h2>

<p>You need to let packets go through your load balancer, so add this in your /etc/sysctl.conf file on the load balancing server :</p>

<div class="language-ini highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="py">net.ipv4.ip_forward</span> <span class="p">=</span> <span class="s">1</span>
</code></pre></div></div>

<p>Then, apply changes you made in the <code class="language-plaintext highlighter-rouge">sysctl.conf</code> file :</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sysctl <span class="nt">-p</span>
</code></pre></div></div>

<h2 id="marking-packets-that-should-be-load-balanced">Marking packets that should be load-balanced</h2>

<p>What we want is that packets directed to the port 80 of the load balancer ip address are being marked (like a stamp) so that ipvs can regognize them and handle them accordingly to ipvs rules.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>iptables <span class="nt">-t</span> mangle <span class="nt">-A</span> PREROUTING <span class="nt">-j</span> CONNMARK <span class="nt">--restore-mark</span>
iptables <span class="nt">-t</span> mangle <span class="nt">-N</span> myrule
iptables <span class="nt">-t</span> mangle <span class="nt">-A</span> PREROUTING <span class="nt">-d</span> 192.168.0.50 <span class="nt">-p</span> tcp <span class="nt">--dport</span> 80 <span class="nt">-j</span> myrule
iptables <span class="nt">-t</span> mangle <span class="nt">-A</span> myrule <span class="nt">-j</span> MARK <span class="nt">--set-mark</span> 0x1
iptables <span class="nt">-t</span> mangle <span class="nt">-A</span> myrule <span class="nt">-j</span> CONNMARK <span class="nt">--save-mark</span>
</code></pre></div></div>

<h2 id="setting-up-the-ipvs-rules">Setting up the ipvs rules</h2>

<p>Now we just have to tell <code class="language-plaintext highlighter-rouge">ipvsadm</code> to route marked packets to server1 and server2 (which is meaned to be twice powerful as server1), using weight round robin load balancing. This means that servers with higher weight will receive more packets than servers with lighter weights.
Concretely, telling that server2 has a weight of 2 and server1 a weight of 1, server2 will get 10 packets when server1 got 5.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>ipvsadm <span class="nt">-A</span> <span class="nt">-f</span> 1 <span class="nt">-s</span> wrr
ipvsadm <span class="nt">-a</span> <span class="nt">-f</span> 1 <span class="nt">-r</span> 192.168.0.108:0 <span class="nt">-w</span> 1
ipvsadm <span class="nt">-a</span> <span class="nt">-f</span> 1 <span class="nt">-r</span> 192.168.0.109:0 <span class="nt">-w</span> 2
</code></pre></div></div>

<h2 id="putting-some-load-on-the-load-balancing-ip">Putting some load on the load balancing ip</h2>

<p>Here is the result of putting some load on the virtual ip :</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>IP Virtual Server version 1.2.1 <span class="o">(</span><span class="nv">size</span><span class="o">=</span>4096<span class="o">)</span>
Prot LocalAddress:Port Scheduler Flags
  -&gt; RemoteAddress:Port           Forward Weight ActiveConn InActConn
FWM  1 wrr
  -&gt; 192.168.0.109:0              Route   2      0          1451
  -&gt; 192.168.0.108:0              Route   1      0          721
</code></pre></div></div>

<p>We see that packets are transferred correctly to the servers, in accordance to their weight.</p>]]></content><author><name></name></author><category term="system" /><summary type="html"><![CDATA[]]></summary></entry><entry><title type="html">Automatize CentOS server installation</title><link href="https://bkraft.fr/system/2009/11/28/automatize-centos-server-installation.html" rel="alternate" type="text/html" title="Automatize CentOS server installation" /><published>2009-11-28T19:00:00+00:00</published><updated>2009-11-28T19:00:00+00:00</updated><id>https://bkraft.fr/system/2009/11/28/automatize-centos-server-installation</id><content type="html" xml:base="https://bkraft.fr/system/2009/11/28/automatize-centos-server-installation.html"><![CDATA[<ul id="markdown-toc">
  <li><a href="#creating-your-kickstarting-infrastructure" id="markdown-toc-creating-your-kickstarting-infrastructure">Creating your kickstarting infrastructure</a>    <ul>
      <li><a href="#introduction-and-requirements" id="markdown-toc-introduction-and-requirements">Introduction and requirements</a></li>
      <li><a href="#installing-and-configuring" id="markdown-toc-installing-and-configuring">Installing and configuring</a>        <ul>
          <li><a href="#dhcp-server" id="markdown-toc-dhcp-server">dhcp server</a></li>
          <li><a href="#tftp-server" id="markdown-toc-tftp-server">tftp server</a></li>
          <li><a href="#booting" id="markdown-toc-booting">Booting</a></li>
        </ul>
      </li>
    </ul>
  </li>
</ul>

<h1 id="creating-your-kickstarting-infrastructure">Creating your kickstarting infrastructure</h1>

<p>Did you ever wished that you automatize your server installation (called kickstarting) ? In this article you will see a way to automatize the installation of a linux server (it will be a RedHat based server) via the network.</p>

<h2 id="introduction-and-requirements">Introduction and requirements</h2>

<p>Installing a server requires some components to be present on your network.
The process of the server kickstarting will be the following :</p>

<ul>
  <li><code class="language-plaintext highlighter-rouge">server1</code> (to be kickstarted) boots and makes dhcp discover (DHCPDISCOVER) request on his network to see if there’s a dhcp server available</li>
  <li><code class="language-plaintext highlighter-rouge">server2</code> responds to the dhcp request (DHCPREQUEST) by making an offer with an IP address</li>
  <li><code class="language-plaintext highlighter-rouge">server1</code> makes a DHCPREQUEST to the server in order to have the previously offered IP address</li>
  <li><code class="language-plaintext highlighter-rouge">server2</code> acknowledges the request and indicates where the tftp server is (will be <code class="language-plaintext highlighter-rouge">server2</code> as well)</li>
  <li><code class="language-plaintext highlighter-rouge">server1</code> makes a PXE (Preboot Execution Environment) to <code class="language-plaintext highlighter-rouge">server2</code></li>
  <li><code class="language-plaintext highlighter-rouge">server1</code> loads syslinux, a small network booting environment from <code class="language-plaintext highlighter-rouge">server2</code></li>
  <li>You choose (can be defaulted) on what you want <code class="language-plaintext highlighter-rouge">server1</code> to boot</li>
  <li><code class="language-plaintext highlighter-rouge">server1</code> fetches a kickstart file and runs the instructions</li>
</ul>

<p>If we resume, you will need a dhcp server (most of you already have) and a tftp server. Optionally, you’ll need a web server to host you kickstart files.</p>

<h2 id="installing-and-configuring">Installing and configuring</h2>

<h3 id="dhcp-server">dhcp server</h3>

<p>Just one packet to go here :</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>yum <span class="nb">install </span>dhcp
<span class="o">=&gt;</span>	...
	Installed:
	  dhcp.i386 12:3.0.5-21.el5_4.1
</code></pre></div></div>

<p>Now we’ll configure the server by editing <code class="language-plaintext highlighter-rouge">/etc/dhcpd.conf</code></p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">cat</span> <span class="o">&gt;</span> /etc/dhcpd.conf
	<span class="c">#Allow pxe requests</span>
	allow booting<span class="p">;</span>
	allow bootp<span class="p">;</span>

	ddns-update-style interim<span class="p">;</span>
	ignore client-updates<span class="p">;</span>

	subnet 192.168.0.0 netmask 255.255.255.0 <span class="o">{</span>
	<span class="c">#standard network configuration</span>
	        option routers                  192.168.0.1<span class="p">;</span>
	        option subnet-mask              255.255.255.0<span class="p">;</span>

	        option nis-domain               <span class="s2">"dotnul.com"</span><span class="p">;</span>
	        option domain-name              <span class="s2">"dotnul.com"</span><span class="p">;</span>
	        option domain-name-servers      80.92.65.30<span class="p">;</span>

	        default-lease-time 21600<span class="p">;</span>
	        max-lease-time 43200<span class="p">;</span>
	<span class="c">#here we're saying where server1 should make the pxe boot</span>
	        next-server                     192.168.0.109<span class="p">;</span>
	<span class="c">#and which file syslinux is on it</span>
	        filename                        <span class="s2">"pxelinux.0"</span><span class="p">;</span>

	<span class="c">#here is the reservation for server1</span>
	        host server1 <span class="o">{</span>
	                hardware ethernet 00:0C:29:26:FA:12<span class="p">;</span>
	                fixed-address 192.168.0.108<span class="p">;</span>
	        <span class="o">}</span>
	<span class="o">}</span>
^D
</code></pre></div></div>

<p>Start and add to the default runlevel the dhcp daemon</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># Starting the server</span>
/etc/init.d/dhcpd start
<span class="o">=&gt;</span>	Starting dhcpd:                                            <span class="o">[</span>  OK  <span class="o">]</span>
<span class="c"># Adding the service to the default runlevel </span>
chkconfig dhcpd on
</code></pre></div></div>

<h3 id="tftp-server">tftp server</h3>

<p>As tftp-server uses the xinetd super daemon to start, we’ll have to install it if not already present.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>yum <span class="nb">install </span>tftp-server
<span class="o">=&gt;</span>	...
	Installed:
	  tftp-server.i386 0:0.49-2.el5.centos

	Dependency Installed:
	  xinetd.i386 2:2.3.14-10.el5
</code></pre></div></div>

<p>What we need to do is, in the <code class="language-plaintext highlighter-rouge">pxeboot</code> default directory, copy syslinux in it and create a default configuration file for syslinux along with the default boot menu.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">cd</span> /tftpboot
<span class="nb">cp</span> /usr/lib/syslinux/pxelinux.0 <span class="nb">.</span>
<span class="nb">mkdir </span>pxelinux.cfg
<span class="nb">cd </span>pxelinux.cfg/
<span class="nb">cat</span> <span class="o">&gt;</span> default
	default 1
	<span class="nb">timeout </span>1000
	prompt 1
	display menu.msg

	label 1
	       localboot 1

	label 2
	       kernel centos/5.7/i386/vmlinuz
	       append <span class="nv">initrd</span><span class="o">=</span>centos/5.7/i386/initrd.img <span class="nv">ramdisk_size</span><span class="o">=</span>10000

	label 3
	       kernel centos/5.7/i386/vmlinuz
	       append <span class="nv">initrd</span><span class="o">=</span>centos/5.7/i386/initrd.img <span class="nv">ramdisk_size</span><span class="o">=</span>10000 <span class="se">\</span>
	              <span class="nv">ksdevice</span><span class="o">=</span>eth0 <span class="nv">ks</span><span class="o">=</span>http://dotnul.com/centos-basic.ks
^D
<span class="nb">cd</span> ..
<span class="nb">cat</span> <span class="o">&gt;</span> menu.msg
	My PXE Menu

	choose between the following options :

	1 : boot <span class="nb">local </span>disk <span class="o">(</span>default<span class="o">)</span>
	2 : <span class="nb">install </span>centos by hand
	3 : <span class="nb">install </span>centos by kickstarting
^D
</code></pre></div></div>

<p>Now, we’ll have to find the installation kernel and initrd to boot the installation media from the network on a centOS repository.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">mkdir</span> <span class="nt">-p</span> centos/5.7/i386/
<span class="nb">cd </span>centos/5.7/i386/
wget http://mirror.dclux.com/centos/5.7/os/i386/images/pxeboot/initrd.img
wget http://mirror.dclux.com/centos/5.7/os/i386/images/pxeboot/vmlinuz
</code></pre></div></div>

<p>If you’re using <code class="language-plaintext highlighter-rouge">SELinux</code>, like me, make sure that the context is <code class="language-plaintext highlighter-rouge">root:object_r:tftpdir_t:s0</code></p>

<p>Edit the tftp xinetd configuration file to enable tftp-server to work</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>vim /etc/xinetd.d/tftp
...
disable <span class="o">=</span> no
...
</code></pre></div></div>

<p>Start and add to the default runlevel the xinet daemon</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>/etc/init.d/xinetd start
<span class="o">=&gt;</span>	Starting xinetd:                                            <span class="o">[</span>  OK  <span class="o">]</span>
chkconfig xinetd on
</code></pre></div></div>

<p>Now, you need a kickstart file describing how you’d like to configure the server what you want to install on it. This step won’t be detailed here, I’ll use my personnal default kickstart located at ~<del>http://dotnul.com/centos-basic.ks</del>~. It does a basic installation without X and with password as root password.</p>

<h3 id="booting">Booting</h3>

<p>Let’s start <code class="language-plaintext highlighter-rouge">server1</code> and make a pxe boot</p>

<p>Hooray ! it worked …
Here’s what in <code class="language-plaintext highlighter-rouge">server2</code> /var/log/message :</p>

<pre><code class="language-log">server2 dhcpd: DHCPDISCOVER from 00:0c:29:26:fa:12 via eth0
server2 dhcpd: DHCPOFFER on 192.168.0.108 to 00:0c:29:26:fa:12 via eth0
server2 dhcpd: DHCPREQUEST for 192.168.0.108 (192.168.0.109) from 00:0c:29:26:fa:12 via eth0
server2 dhcpd: DHCPACK on 192.168.0.108 to 00:0c:29:26:fa:12 via eth0
</code></pre>

<p>Now, type 3, and enter and the installation should run smoothly. It’s time for you to make some coffee, well done !</p>]]></content><author><name></name></author><category term="system" /><summary type="html"><![CDATA[]]></summary></entry></feed>