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

<channel>
	<title>Shadows of epiphany</title>
	<atom:link href="http://blog.bodhizazen.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.bodhizazen.net</link>
	<description>A LAMP in the Samsara</description>
	<lastBuildDate>Fri, 26 Feb 2010 06:42:40 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>LXC Configure Debian Containers</title>
		<link>http://blog.bodhizazen.net/linux/lxc-configure-debian-lenny-containers/</link>
		<comments>http://blog.bodhizazen.net/linux/lxc-configure-debian-lenny-containers/#comments</comments>
		<pubDate>Wed, 24 Feb 2010 07:16:20 +0000</pubDate>
		<dc:creator>bodhi.zazen</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[LXC]]></category>
		<category><![CDATA[Virtualization]]></category>

		<guid isPermaLink="false">http://blog.bodhizazen.net/?p=989</guid>
		<description><![CDATA[I have been taking Linux Containers for a spin and was advised on IRC that Debian was easier to configure then Ubuntu, so decided to give it a try.
I will again use debootstrap to make a root file system (rootfs) for a LXC container using Debian. These instructions work with both Lenny and  Squeeze.
Commands in this tutorial are run as root, so to obtain a root shell use:
sudo -i
The working directory for this tutorial is /home/bodhi/lxc , so config.lenny and rootfs.lenny are both located in /home/bodhi/lxc

Make a rootfs via debootstrap
debootstrap &#8211;variant=minbase lenny rootfs.lenny # two &#8211; - in front of &#8220;- -variant&#8221;
Configure the container
Copy resolv.conf from host node to container
cp /etc/resolv.conf rootfs.lenny/etc
Generate a config file
I call it config.lenny . Make sure the following information is accurate:
container name (lxc.utsname)
network (lxc.network.ipv4)
rootfs (lxc.rootfs)

lxc.utsname = lenny
lxc.tty = 4
lxc.network.type = veth
lxc.network.flags = up
lxc.network.link = br0
lxc.network.name = eth0
lxc.network.mtu = 1500
lxc.network.ipv4 = 192.168.0.0/24
lxc.rootfs = /home/bodhi/lxc/rootfs.lenny
lxc.cgroup.devices.deny = [...]]]></description>
			<content:encoded><![CDATA[<p>I have been taking Linux Containers for a spin and was advised on IRC that Debian was easier to configure then Ubuntu, so decided to give it a try.</p>
<p>I will again use debootstrap to make a root file system (rootfs) for a LXC container using Debian. <strong>These instructions work with both Lenny and  Squeeze</strong>.</p>
<p>Commands in this tutorial are run as root, so to obtain a root shell use:</p>
<p class="code">sudo -i</p>
<p><strong>The working directory for this tutorial is /home/bodhi/lxc , so config.lenny and rootfs.lenny are both located in /home/bodhi/lxc<br />
</strong></p>
<h2>Make a rootfs via debootstrap</h2>
<p class="code">debootstrap &#8211;variant=minbase lenny rootfs.lenny # two &#8211; - in front of &#8220;- -variant&#8221;</p>
<h2>Configure the container</h2>
<h3>Copy resolv.conf from host node to container</h3>
<p class="code">cp /etc/resolv.conf rootfs.lenny/etc</p>
<h3>Generate a config file</h3>
<p>I call it <strong>config.lenny</strong> . Make sure the following information is accurate:</p>
<p><strong>container name (lxc.utsname)<br />
network (lxc.network.ipv4)<br />
rootfs (lxc.rootfs)</strong><br />
<code><br />
lxc.utsname = lenny<br />
lxc.tty = 4<br />
lxc.network.type = veth<br />
lxc.network.flags = up<br />
lxc.network.link = br0<br />
lxc.network.name = eth0<br />
lxc.network.mtu = 1500<br />
lxc.network.ipv4 = 192.168.0.0/24<br />
lxc.rootfs = /home/bodhi/lxc/rootfs.lenny<br />
lxc.cgroup.devices.deny = a<br />
# /dev/null and zero<br />
lxc.cgroup.devices.allow = c 1:3 rwm<br />
lxc.cgroup.devices.allow = c 1:5 rwm<br />
# consoles<br />
lxc.cgroup.devices.allow = c 5:1 rwm<br />
lxc.cgroup.devices.allow = c 5:0 rwm<br />
lxc.cgroup.devices.allow = c 4:0 rwm<br />
lxc.cgroup.devices.allow = c 4:1 rwm<br />
# /dev/{,u}random<br />
lxc.cgroup.devices.allow = c 1:9 rwm<br />
lxc.cgroup.devices.allow = c 1:8 rwm<br />
# /dev/pts/* - pts namespaces are "coming soon"<br />
lxc.cgroup.devices.allow = c 136:* rwm<br />
lxc.cgroup.devices.allow = c 5:2 rwm<br />
# rtc<br />
lxc.cgroup.devices.allow = c 254:0 rwm</code></p>
<h3>Modify the rootfs</h3>
<p>chroot into rootfs.ubuntu and configure</p>
<p class="code">chroot rootfs.lenny<br />
<br />apt-get update<br />
<br /># set locales<br />
echo &#8220;en_US.UTF-8 UTF-8&#8243; > /etc/locale.gen<br />
apt-get -y install locales<br />
<br /># Add a few applications, including openssh-server<br />
apt-get install -y adduser apt-utils iproute netbase nano openssh-blacklist openssh-blacklist-extra openssh-server console-setup sudo iputils-ping<br />
<br />#Set a root passwd<br />
passwd<br />
<br /># As an alternate to setting a root password, you may of course add a new user and configure sudo.<br />
<br />#exit chroot<br />
exit</p>
<h3>Edit /etc/inittab</h3>
<p>Using any editor (nano, vim), open <strong>rootfs.lenny/etc/inittab</strong> and comment out the following two lines:</p>
<p class="code"> #5:23:respawn:/sbin/getty 38400 tty5<br />
#6:23:respawn:/sbin/getty 38400 tty6</p>
<h3>Configure networking</h3>
<p>edit <strong>rootfs.lenny/etc/network/interfaces</strong></p>
<p class="code">auto lo<br />
iface lo inet loopback<br />
<br />auto eth0<br />
iface eth0 inet static<br />
address 192.168.0.61<br />
netmask 255.255.255.0<br />
broadcast 192.168.0.255<br />
gateway 192.168.0.1</p>
<h3>Squeeze only &#8211; make a few devices</h3>
<p>cd into rootfs.squeeze/dev and run :</p>
<p class="code">mknod -m 666 tty1 c 4 1<br />
mknod -m 666 tty2 c 4 2<br />
mknod -m 666 tty3 c 4 3<br />
mknod -m 666 tty4 c 4 4</p>
<h2>Configure and start the container</h2>
<p>Create the container:</p>
<p class="code">lxc-create -f /home/bodhi/lxc/conf.lenny -n lenny<br />
lxc-start -n lenny</p>
<p>You should now be able to access the container with either lxc-console or ssh</p>
<p class="code">ssh root@192.168.0.61</p>
<p class="code">lxc-console -n lenny</p>
<p>Assuming you get no error messages , you may start the container with the -d option</p>
<p class="code">lxc-start -d -n lenny</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bodhizazen.net/linux/lxc-configure-debian-lenny-containers/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>LXC Configure Ubuntu Karmic Containers</title>
		<link>http://blog.bodhizazen.net/linux/lxc-configure-ubuntu-karmic-containers/</link>
		<comments>http://blog.bodhizazen.net/linux/lxc-configure-ubuntu-karmic-containers/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 07:50:29 +0000</pubDate>
		<dc:creator>bodhi.zazen</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[LXC]]></category>
		<category><![CDATA[Virtualization]]></category>

		<guid isPermaLink="false">http://blog.bodhizazen.net/?p=976</guid>
		<description><![CDATA[This post is in follow up to my previous post on configuring Ubuntu Lucid (10.04) LXC containers and in this post I will show you how to configure an Ubuntu Karmic (9.10) LXC container.
I will again use debootstrap to make a root file system (rootfs) for a LXC container using Ubuntu Karmic (9.10).
Commands in this tutorial are run as root, so to obtain a root shell use:
sudo -i
The working directory for this tutorial is /home/bodhi/lxc , so config.ubuntu and rootfs.ubuntu are both located in /home/bodhi/lxc

Make a rootfs via debootstrap
debootstrap &#8211;variant=minbase karmic rootfs.ubuntu # two &#8211; - in front of &#8220;- -variant&#8221;
Configure the container
Copy resolv.conf from host node to container
cp /etc/resolv.conf rootfs.ubuntu/etc
Fix devices in rootfs.ubuntu/dev
udev does not run in lxc containers, so you need to manually make the needed devices.
I use this script to configure the devices:

#!/bin/bash

# bodhi.zazen's lxc-config
# Makes default devices needed in lxc containers
# modified from http://lxc.teegra.net/
ROOT=$(pwd)
DEV=${ROOT}/dev
if [ $ROOT [...]]]></description>
			<content:encoded><![CDATA[<p>This post is in follow up to my previous post on configuring Ubuntu Lucid (10.04) LXC containers and in this post I will show you how to configure an Ubuntu Karmic (9.10) LXC container.</p>
<p>I will again use debootstrap to make a root file system (rootfs) for a LXC container using Ubuntu Karmic (9.10).</p>
<p>Commands in this tutorial are run as root, so to obtain a root shell use:</p>
<p class="code">sudo -i</p>
<p><strong>The working directory for this tutorial is /home/bodhi/lxc , so config.ubuntu and rootfs.ubuntu are both located in /home/bodhi/lxc<br />
</strong></p>
<h2>Make a rootfs via debootstrap</h2>
<p class="code">debootstrap &#8211;variant=minbase karmic rootfs.ubuntu # two &#8211; - in front of &#8220;- -variant&#8221;</p>
<h2>Configure the container</h2>
<h3>Copy resolv.conf from host node to container</h3>
<p class="code">cp /etc/resolv.conf rootfs.ubuntu/etc</p>
<h3>Fix devices in rootfs.ubuntu/dev</h3>
<p>udev does not run in lxc containers, so you need to manually make the needed devices.</p>
<p>I use this script to configure the devices:<br />
<code><br />
#!/bin/bash<br />
<br />
# bodhi.zazen's lxc-config<br />
# Makes default devices needed in lxc containers<br />
# modified from http://lxc.teegra.net/<br />
<br />ROOT=$(pwd)<br />
DEV=${ROOT}/dev<br />
if [ $ROOT = '/' ]; then<br />
  printf "\033[22;35m\nDO NOT RUN ON THE HOST NODE\n\n"<br />
  tput sgr0<br />
  exit 1<br />
fi<br />
if [ ! -d $DEV ]; then<br />
  printf "\033[01;33m\nRun this script in rootfs\n\n"<br />
  tput sgr0<br />
  exit 1<br />
fi<br />
rm -rf ${DEV}<br />
mkdir ${DEV}<br />
mknod -m 666 ${DEV}/null c 1 3<br />
mknod -m 666 ${DEV}/zero c 1 5<br />
mknod -m 666 ${DEV}/random c 1 8<br />
mknod -m 666 ${DEV}/urandom c 1 9<br />
mkdir -m 755 ${DEV}/pts<br />
mkdir -m 1777 ${DEV}/shm<br />
mknod -m 666 ${DEV}/tty c 5 0<br />
mknod -m 666 ${DEV}/tty0 c 4 0<br />
mknod -m 666 ${DEV}/tty1 c 4 1<br />
mknod -m 666 ${DEV}/tty2 c 4 2<br />
mknod -m 666 ${DEV}/tty3 c 4 3<br />
mknod -m 666 ${DEV}/tty4 c 4 4<br />
mknod -m 600 ${DEV}/console c 5 1<br />
mknod -m 666 ${DEV}/full c 1 7<br />
mknod -m 600 ${DEV}/initctl p<br />
mknod -m 666 ${DEV}/ptmx c 5 2<br />
<br />exit 0</code></p>
<p>The script is very slightly modified from <a href="http://lxc.teegra.net/">This page</a>  and is saved in <strong>/usr/local/bin/lxc-config</strong> .</p>
<p>Make it executable :</p>
<p class="code">chmod u+x /usr/local/bin/lxc-config</p>
<p>Run the script in rootfs.ubuntu</p>
<p class="code">cd rootfs.ubuntu<br />
/usr/local/bin/lxc-config # fix /dev</p>
<h3>Generate a config file</h3>
<p>I call it <strong>config.ubuntu</strong> . Make sure the following information is accurate:</p>
<p><strong>container name (lxc.utsname)<br />
network (lxc.network.ipv4)<br />
rootfs (lxc.rootfs)</strong><br />
<code><br />
lxc.utsname = ubuntu<br />
lxc.tty = 4<br />
lxc.network.type = veth<br />
lxc.network.flags = up<br />
lxc.network.link = br0<br />
lxc.network.name = eth0<br />
lxc.network.mtu = 1500<br />
lxc.network.ipv4 = 192.168.0.0/24<br />
lxc.rootfs = /home/bodhi/lxc/rootfs.ubuntu<br />
lxc.cgroup.devices.deny = a<br />
# /dev/null and zero<br />
lxc.cgroup.devices.allow = c 1:3 rwm<br />
lxc.cgroup.devices.allow = c 1:5 rwm<br />
# consoles<br />
lxc.cgroup.devices.allow = c 5:1 rwm<br />
lxc.cgroup.devices.allow = c 5:0 rwm<br />
lxc.cgroup.devices.allow = c 4:0 rwm<br />
lxc.cgroup.devices.allow = c 4:1 rwm<br />
# /dev/{,u}random<br />
lxc.cgroup.devices.allow = c 1:9 rwm<br />
lxc.cgroup.devices.allow = c 1:8 rwm<br />
# /dev/pts/* - pts namespaces are "coming soon"<br />
lxc.cgroup.devices.allow = c 136:* rwm<br />
lxc.cgroup.devices.allow = c 5:2 rwm<br />
# rtc<br />
lxc.cgroup.devices.allow = c 254:0 rwm</code></p>
<h3>Modify the rootfs</h3>
<p>chroot into rootfs.ubuntu and configure</p>
<p class="code">chroot rootfs.ubuntu<br />
<br /># mount /proc /sys and /dev/pts<br />
mount -t devpts devpts /dev/pts<br />
mount -t proc proc /proc<br />
mount -t sysfs sysfs /sys<br />
<br />apt-get install --force-yes -y gpgv # two - - in front of "--force-yes"<br />
apt-get update<br />
<br /># set locales<br />
apt-get install -y language-pack-en<br />
update-locale LANG=”en_US.UTF-8″ LANGUAGE=”en_US.UTF-8″ LC_ALL=”en_US.UTF-8″<br />
<br /># Add to the installed applications<br />
apt-get install -y adduser apt-utils iproute netbase nano openssh-blacklist openssh-blacklist-extra openssh-server console-setup sudo ping<br />
<br />#Remove udev<br />
apt-get remove --purge udev # two – - in front of “--purge”<br />
rm -rf /etc/udev /lib/udev<br />
apt-get autoremove<br />
<br />#Remove a few upstart scripts<br />
cd /etc/init<br />
rm mountall* upstart*<br />
<br />#Set a root passwd<br />
passwd<br />
<br /># As an alternate to setting a root password, you may of course add a new user and configure sudo.<br />
<br />#unmount /proc /sys and /dev/pts<br />
umount /dev/pts<br />
umount /proc<br />
umount /sys<br />
<br />#exit chroot<br />
exit</p>
<h3>Configure networking</h3>
<p>edit <strong>rootfs.ubuntu/etc/network/interfaces</strong></p>
<p class="code">auto lo<br />
iface lo inet loopback<br />
<br />auto eth0<br />
iface eth0 inet static<br />
address 192.168.0.61<br />
netmask 255.255.255.0<br />
broadcast 192.168.0.255<br />
gateway 192.168.0.1</p>
<h3>Remove tty 5 &#038; 6</h3>
<p class="code">rm rootfs.ubuntu/etc/init/tty{5,6}.conf</p>
<h3>Fix /var/run/network/ifstate</h3>
<p class="code">mkdir -p rootfs.ubuntu/var/run/network<br />
touch rootfs.ubuntu/var/run/network/ifstate<br />
<h3>Add an upstart script to boot karmic</h3>
<p>Save the following script as rootfs.ubuntu/etc/init/lxc.conf<br />
<code><br />
# LXC – Fix init sequence to have LXC working with upstart<br />
<br /># description “Fix LXC container - Karmic”<br />
<br ?>start on startup<br />
<br />task<br />
pre-start script<br />
mount -t proc proc /proc<br />
mount -t devpts devpts /dev/pts<br />
mount -t sysfs sys /sys<br />
mount -t tmpfs varrun /var/run<br />
mount -t tmpfs varlock /var/lock<br />
mkdir -p /var/run/network<br />
touch /var/run/utmp<br />
chmod 664 /var/run/utmp<br />
chown root.utmp /var/run/utmp<br />
if [ "$(find /etc/network/ -name upstart -type f)" ]; then<br />
chmod -x /etc/network/*/upstart || true<br />
fi<br />
end script<br />
<br />script<br />
start networking<br />
initctl emit filesystem --no-wait<br />
initctl emit local-filesystems --no-wait<br />
initctl emit virtual-filesystems --no-wait<br />
init 2<br />
end script</code></p>
<h2>Configure and start the container</h2>
<p>Create the container:</p>
<p class="code">lxc-create -f /home/bodhi/lxc/conf.ubuntu -n ubuntu<br />
lxc-start -n ubuntu</p>
<p>You should now be able to access the container with either lxc-console or ssh</p>
<p class="code">ssh root@192.168.0.61</p>
<p class="code">lxc-console -n ubuntu</p>
<p>Assuming you get no error messages , you may start the container with the -d option</p>
<p class="code">lxc-console -d -n ubuntu</p>
<p>Note: Unlike lucid (Ubuntu 10.04) I am able to start the container with the -d option (lxc-start -d -n karmic),</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bodhizazen.net/linux/lxc-configure-ubuntu-karmic-containers/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>LXC Configure Fedora Containers</title>
		<link>http://blog.bodhizazen.net/linux/lxc-configure-fedora-containers/</link>
		<comments>http://blog.bodhizazen.net/linux/lxc-configure-fedora-containers/#comments</comments>
		<pubDate>Tue, 02 Feb 2010 16:09:19 +0000</pubDate>
		<dc:creator>bodhi.zazen</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[LXC]]></category>
		<category><![CDATA[Virtualization]]></category>

		<guid isPermaLink="false">http://blog.bodhizazen.net/?p=876</guid>
		<description><![CDATA[In this post I will demonstrate how to use febootstrap to make a root file system (rootfs) for a LXC container using Fedora. This technique is working with Fedora 12 and rawhide. Rawhide is under development and will become Fedora 13, so use a rawhide container at your own risk.
Most of the commands in this tutorial are run as root. To obtain a root shell use:
su -
The working directory for this tutorial is /home/bodhi/lxc , so config.fedora and rootfs.fedora are both located in /home/bodhi/lxc
Note: Unless you are familiar with selinux, it may be helpful to disable selinux as you learn to use Linux Containers.
setenforce 0
Make a rootfs via febootstrap
# Fedora 12
febootstrap fedora-12 rootfs.fedora
# Rawhide
febootstrap rawhide rootfs.fedora
Configure the rootfs
Copy resolv.conf from host node to container
cp /etc/resolv.conf rootfs.fedora/etc
Fix devices
udev does not run in lxc containers, so you need to manually make the needed devices.
I use this script to configure the devices:

#!/bin/bash

# bodhi.zazen's [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I will demonstrate how to use febootstrap to make a root file system (rootfs) for a LXC container using Fedora. This technique is working with Fedora 12 and rawhide. Rawhide is under development and will become Fedora 13, so use a rawhide container at your own risk.</p>
<p>Most of the commands in this tutorial are run as root. To obtain a root shell use:</p>
<p class="code">su -</p>
<p><strong>The working directory for this tutorial is /home/bodhi/lxc</strong> , so config.fedora and rootfs.fedora are both located in /home/bodhi/lxc</p>
<p><strong>Note</strong>: Unless you are familiar with selinux, it may be helpful to disable selinux as you learn to use Linux Containers.</p>
<p class="code">setenforce 0</code></p>
<h2>Make a rootfs via febootstrap</h2>
<p class="code"># Fedora 12<br />
febootstrap fedora-12 rootfs.fedora<br />
<br /># Rawhide<br />
febootstrap rawhide rootfs.fedora</p>
<h3>Configure the rootfs</h3>
<h2>Copy resolv.conf from host node to container</h2>
<p class="code">cp /etc/resolv.conf rootfs.fedora/etc</p>
<h3>Fix devices</h3>
<p>udev does not run in lxc containers, so you need to manually make the needed devices.</p>
<p>I use this script to configure the devices:<br />
<code><br />
#!/bin/bash<br />
<br />
# bodhi.zazen's lxc-config<br />
# Makes default devices needed in lxc containers<br />
# modified from http://lxc.teegra.net/<br />
<br />ROOT=$(pwd)<br />
DEV=${ROOT}/dev<br />
if [ $ROOT = '/' ]; then<br />
  printf "\033[22;35m\nDO NOT RUN ON THE HOST NODE\n\n"<br />
  tput sgr0<br />
  exit 1<br />
fi<br />
if [ ! -d $DEV ]; then<br />
  printf "\033[01;33m\nRun this script in rootfs\n\n"<br />
  tput sgr0<br />
  exit 1<br />
fi<br />
rm -rf ${DEV}<br />
mkdir ${DEV}<br />
mknod -m 666 ${DEV}/null c 1 3<br />
mknod -m 666 ${DEV}/zero c 1 5<br />
mknod -m 666 ${DEV}/random c 1 8<br />
mknod -m 666 ${DEV}/urandom c 1 9<br />
mkdir -m 755 ${DEV}/pts<br />
mkdir -m 1777 ${DEV}/shm<br />
mknod -m 666 ${DEV}/tty c 5 0<br />
mknod -m 666 ${DEV}/tty0 c 4 0<br />
mknod -m 666 ${DEV}/tty1 c 4 1<br />
mknod -m 666 ${DEV}/tty2 c 4 2<br />
mknod -m 666 ${DEV}/tty3 c 4 3<br />
mknod -m 666 ${DEV}/tty4 c 4 4<br />
mknod -m 600 ${DEV}/console c 5 1<br />
mknod -m 666 ${DEV}/full c 1 7<br />
mknod -m 600 ${DEV}/initctl p<br />
mknod -m 666 ${DEV}/ptmx c 5 2<br />
<br />exit 0</code></p>
<p>The script is very slightly modified from <a href="http://lxc.teegra.net/">This page</a>  and is saved in <strong>/usr/local/bin/lxc-config</strong> .</p>
<p>Make it executable :</p>
<p class="code">chmod u+x /usr/local/bin/lxc-config</p>
<p>Run the script in rootfs.fedora</p>
<p class="code">cd rootfs.fedora<br />
/usr/local/bin/lxc-config # fix /dev</p>
<h3>Generate a config file</h3>
<p>I call it <strong>config.fedora</strong> . Make sure the following information is accurate:</p>
<p><strong>container name (lxc.utsname)<br />
network (lxc.network.ipv4)<br />
rootfs (lxc.rootfs)</strong><br />
<code><br />
lxc.utsname = fedora<br />
lxc.tty = 4<br />
lxc.network.type = veth<br />
lxc.network.flags = up<br />
lxc.network.link = br0<br />
lxc.network.name = eth0<br />
lxc.network.mtu = 1500<br />
lxc.network.ipv4 = 192.168.0.0/24<br />
lxc.rootfs = /home/bodhi/lxc/rootfs.fedora<br />
lxc.cgroup.devices.deny = a<br />
# /dev/null and zero<br />
lxc.cgroup.devices.allow = c 1:3 rwm<br />
lxc.cgroup.devices.allow = c 1:5 rwm<br />
# consoles<br />
lxc.cgroup.devices.allow = c 5:1 rwm<br />
lxc.cgroup.devices.allow = c 5:0 rwm<br />
lxc.cgroup.devices.allow = c 4:0 rwm<br />
lxc.cgroup.devices.allow = c 4:1 rwm<br />
# /dev/{,u}random<br />
lxc.cgroup.devices.allow = c 1:9 rwm<br />
lxc.cgroup.devices.allow = c 1:8 rwm<br />
# /dev/pts/* - pts namespaces are "coming soon"<br />
lxc.cgroup.devices.allow = c 136:* rwm<br />
lxc.cgroup.devices.allow = c 5:2 rwm<br />
# rtc<br />
lxc.cgroup.devices.allow = c 254:0 rwm</code></p>
<h3>Fix rootfs</h3>
<p class="code">touch rootfs.fedora/var/run/syslogd.pid<br />
mkdir -p rootfs.fedora/var/lock/subsys<br />
touch rootfs.fedora/var/lock/subsys/{atd,ip6tables,iptables,local,network,rsyslogd,sshd}</p>
<h2>Disable udev</h3>
<p class="code">rm rootfs.fedora/etc/init.d/udev-post</p>
<p>edit <strong>rootfs.fedora/etc/rc.sysinit</strong> and comment out the start_udev line</p>
<p class="code"># /sbin/start_udev</p>
<h3>Set up fstab and mtab</h3>
<p class="code">touch rootfs.fedora/etc/{fstab,mtab}<br />
echo "none  /dev/pts  devpts  defaults  0  0" >> rootfs.fedora/etc/fstab</p>
<h3>Configure networking</h3>
<p><strong>eth0</strong></p>
<p>Using any editor, edit <strong>rootfs.fedora/etc/sysconfig/networking-scripts/ifcfg-eth0</strong></p>
<p>set your ipaddress in this file, either via static or dhcp (I use static IP)</p>
<p class="code">DEVICE=eth0<br />
BOOTPROTO=none<br />
ONBOOT=yes<br />
HOSTNAME=fedora<br />
TYPE=Ethernet<br />
IPADDR=192.168.0.20<br />
NETWORK=192.168.0.0<br />
GATEWAY=192.168.0.1<br />
BROADCAST=192.168.0.255<br />
NETMASK=255.255.255.0<br />
MTU=1500<br />
DNS1=192.168.0.1<br />
IPV6INIT=no<br />
USERCTL=no</p>
<p>Using any editor, edit <strong>rootfs/etc/sysconfig/network</strong></p>
<p>Add these two lines (adjust hostname):</p>
<p class="code">NETWORKING=yes<br />
HOSTNAME=fedora</p>
<p>Using any editor, edit <strong>rootfs/etc/rc.local</strong></p>
<p>Add (was necessary to bring up the network in my Fedora containers).</p>
<p class="code">service network restart</p>
<h3>Remove tty5 and tty6</h3>
<p><strong>Fedora 12</strong></p>
<p class="code">cd rootfs.fedora/etc/event.d<br />
rm tty{5,6}</p>
<p><strong>Radhide</strong>: edit <strong>rootfs.fedora/etc/sysconfig/init</strong></p>
<p>The very last line of the file reads "ACTIVE_CONSOLES=/dev/tty[1-6]" , change this to</p>
<p class="code">ACTIVE_CONSOLES=/dev/tty[1-4]</p>
<h3>Chroot and set a root password</h3>
<p class="code">chroot rootfs.fedora /bin/bash<br />
passwd</p>
<h2>Configure and start the container</h2>
<p class="code">lxc-create -f ~bodhi/lxc/config.fedora -n fedora</p>
<h3>Disable selinux (on the host</h3>
<p class="code">setenforce 0</p>
<p>Start the container, watch for error messages</p>
<p class="code">lxc-start -n fedora</p>
<p>Note: It takes some time for the container to boot ...</p>
<p>lxc-console or ssh in and set a locale</p>
<p class="code">lxc-console -n fedora</p>
<p>In the container run:</p>
<p class="code">yum -y reinstall glibc-common<br />
<br />#auditd is not woking, so turn it off<br />
chkconfig auditd off<br />
<br />#sendmail is slow to start, so if you are not using it disable it<br />
chkconfig sendmail off</p>
<h2>Clean up container</h2>
<p>From within the container</p>
<p class="code">yum clean all</p>
<p>Stop the container</p>
<p class="code">lxc-stop -n fedora</p>
<h2>Optional : Clean unnecessary files</h2>
<p>remove the febootstrap cache (if it exists). You may remove the shared doc and locales.</p>
<p class="code">rm -rf rootfs/var/yum/cache/febootstrap<br />
rm -rf rootfs/usr/share/locale/*<br />
rm -rf rootfs/usr/share/doc/*</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bodhizazen.net/linux/lxc-configure-fedora-containers/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>LXC Configure Ubuntu Lucid Containers</title>
		<link>http://blog.bodhizazen.net/linux/lxc-configure-ubuntu-lucid-containers/</link>
		<comments>http://blog.bodhizazen.net/linux/lxc-configure-ubuntu-lucid-containers/#comments</comments>
		<pubDate>Tue, 02 Feb 2010 16:09:19 +0000</pubDate>
		<dc:creator>bodhi.zazen</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[LXC]]></category>
		<category><![CDATA[Virtualization]]></category>

		<guid isPermaLink="false">http://blog.bodhizazen.net/?p=874</guid>
		<description><![CDATA[In this post I will demonstrate how to use debootstrap to make a root file system (rootfs) for a LXC container using Ubuntu Lucid (10.04).
Note: At the time of this post, Lucid (Ubuntu 10.04) is in the Alpha stage of development. As with all development releases, breakage may occur.
Commands in this tutorial are run as root, so to obtain a root shell use:
sudo -i
The working directory for this tutorial is /home/bodhi/lxc , so config.ubuntu and rootfs.ubuntu are both located in /home/bodhi/lxc

Make a rootfs via debootstrap
debootstrap &#8211;variant=minbase lucid rootfs.ubuntu # two &#8211; - in front of &#8220;- -variant&#8221;
Configure the container
Copy resolv.conf from host node to container
cp /etc/resolv.conf rootfs.ubuntu/etc
Fix devices in rootfs.ubuntu/dev
udev does not run in lxc containers, so you need to manually make the needed devices.
I use this script to configure the devices:

#!/bin/bash

# bodhi.zazen's lxc-config
# Makes default devices needed in lxc containers
# modified from http://lxc.teegra.net/
ROOT=$(pwd)
DEV=${ROOT}/dev
if [ $ROOT = '/' ]; then
 [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I will demonstrate how to use debootstrap to make a root file system (rootfs) for a LXC container using Ubuntu Lucid (10.04).</p>
<p><strong>Note</strong>: At the time of this post, Lucid (Ubuntu 10.04) is in the Alpha stage of development. As with all development releases, breakage may occur.</p>
<p>Commands in this tutorial are run as root, so to obtain a root shell use:</p>
<p class="code">sudo -i</p>
<p><strong>The working directory for this tutorial is /home/bodhi/lxc , so config.ubuntu and rootfs.ubuntu are both located in /home/bodhi/lxc<br />
</strong></p>
<h2>Make a rootfs via debootstrap</h2>
<p class="code">debootstrap &#8211;variant=minbase lucid rootfs.ubuntu # two &#8211; - in front of &#8220;- -variant&#8221;</p>
<h2>Configure the container</h2>
<h3>Copy resolv.conf from host node to container</h3>
<p class="code">cp /etc/resolv.conf rootfs.ubuntu/etc</p>
<h3>Fix devices in rootfs.ubuntu/dev</h3>
<p>udev does not run in lxc containers, so you need to manually make the needed devices.</p>
<p>I use this script to configure the devices:<br />
<code><br />
#!/bin/bash<br />
<br />
# bodhi.zazen's lxc-config<br />
# Makes default devices needed in lxc containers<br />
# modified from http://lxc.teegra.net/<br />
<br />ROOT=$(pwd)<br />
DEV=${ROOT}/dev<br />
if [ $ROOT = '/' ]; then<br />
  printf "\033[22;35m\nDO NOT RUN ON THE HOST NODE\n\n"<br />
  tput sgr0<br />
  exit 1<br />
fi<br />
if [ ! -d $DEV ]; then<br />
  printf "\033[01;33m\nRun this script in rootfs\n\n"<br />
  tput sgr0<br />
  exit 1<br />
fi<br />
rm -rf ${DEV}<br />
mkdir ${DEV}<br />
mknod -m 666 ${DEV}/null c 1 3<br />
mknod -m 666 ${DEV}/zero c 1 5<br />
mknod -m 666 ${DEV}/random c 1 8<br />
mknod -m 666 ${DEV}/urandom c 1 9<br />
mkdir -m 755 ${DEV}/pts<br />
mkdir -m 1777 ${DEV}/shm<br />
mknod -m 666 ${DEV}/tty c 5 0<br />
mknod -m 666 ${DEV}/tty0 c 4 0<br />
mknod -m 666 ${DEV}/tty1 c 4 1<br />
mknod -m 666 ${DEV}/tty2 c 4 2<br />
mknod -m 666 ${DEV}/tty3 c 4 3<br />
mknod -m 666 ${DEV}/tty4 c 4 4<br />
mknod -m 600 ${DEV}/console c 5 1<br />
mknod -m 666 ${DEV}/full c 1 7<br />
mknod -m 600 ${DEV}/initctl p<br />
mknod -m 666 ${DEV}/ptmx c 5 2<br />
<br />exit 0</code></p>
<p>The script is very slightly modified from <a href="http://lxc.teegra.net/">This page</a>  and is saved in <strong>/usr/local/bin/lxc-config</strong> .</p>
<p>Make it executable :</p>
<p class="code">chmod u+x /usr/local/bin/lxc-config</p>
<p>Run the script in rootfs.ubuntu</p>
<p class="code">cd rootfs.ubuntu<br />
/usr/local/bin/lxc-config # fix /dev</p>
<h3>Generate a config file</h3>
<p>I call it <strong>config.ubuntu</strong> . Make sure the following information is accurate:</p>
<p><strong>container name (lxc.utsname)<br />
network (lxc.network.ipv4)<br />
rootfs (lxc.rootfs)</strong><br />
<code><br />
lxc.utsname = ubuntu<br />
lxc.tty = 4<br />
lxc.network.type = veth<br />
lxc.network.flags = up<br />
lxc.network.link = br0<br />
lxc.network.name = eth0<br />
lxc.network.mtu = 1500<br />
lxc.network.ipv4 = 192.168.0.0/24<br />
lxc.rootfs = /home/bodhi/lxc/rootfs.ubuntu<br />
lxc.cgroup.devices.deny = a<br />
# /dev/null and zero<br />
lxc.cgroup.devices.allow = c 1:3 rwm<br />
lxc.cgroup.devices.allow = c 1:5 rwm<br />
# consoles<br />
lxc.cgroup.devices.allow = c 5:1 rwm<br />
lxc.cgroup.devices.allow = c 5:0 rwm<br />
lxc.cgroup.devices.allow = c 4:0 rwm<br />
lxc.cgroup.devices.allow = c 4:1 rwm<br />
# /dev/{,u}random<br />
lxc.cgroup.devices.allow = c 1:9 rwm<br />
lxc.cgroup.devices.allow = c 1:8 rwm<br />
# /dev/pts/* - pts namespaces are "coming soon"<br />
lxc.cgroup.devices.allow = c 136:* rwm<br />
lxc.cgroup.devices.allow = c 5:2 rwm<br />
# rtc<br />
lxc.cgroup.devices.allow = c 254:0 rwm</code></p>
<h3>Modify the rootfs</h3>
<p>chroot into rootfs.ubuntu and configure</p>
<p class="code">chroot rootfs.ubuntu<br />
<br />apt-get install --force-yes -y gpgv # two - - in front of "--force-yes"<br />
apt-get update<br />
<br /># set locales<br />
apt-get install -y language-pack-en<br />
update-locale LANG=”en_US.UTF-8″ LANGUAGE=”en_US.UTF-8″ LC_ALL=”en_US.UTF-8″<br />
<br /># Add to the installed applications<br />
apt-get install -y adduser apt-utils iproute netbase nano openssh-blacklist openssh-blacklist-extra openssh-server console-setup sudo ping<br />
<br />#Set a root passwd<br />
passwd<br />
<br /># As an alternate to setting a root password, you may of course add a new user and configure sudo.<br />
<br />#exit chroot<br />
exit</p>
<h3>Configure networking</h3>
<p>edit <strong>rootfs.ubuntu/etc/network/interfaces</strong></p>
<p class="code">auto lo<br />
iface lo inet loopback<br />
<br />auto eth0<br />
iface eth0 inet static<br />
address 192.168.0.60<br />
netmask 255.255.255.0<br />
broadcast 192.168.0.255<br />
gateway 192.168.0.1</p>
<h3>Remove tty4, 5, &#038; 6</h3>
<p class="code">rm rootfs.ubuntu/etc/init/tty{4,5,6}.conf</p>
<h3>Fix /var/run/network/ifstate</h3>
<p class="code">mkdir -p rootfs.ubuntu/var/run/network<br />
touch rootfs.ubuntu/var/run/network/ifstate</p>
<h3>Add a directory to allow ssh user privilege separation</h3>
<p class="code">mkdir -p rootfs.ubuntu/var/run/sshd<br />
<h3>Edit rootfs.ubuntu/lib/init/fstab</h3>
<p>Using any editor, open <strong>rootfs.ubuntu/lib/init/fstab</strong> and comment out the following lines:</p>
<p class="code">#none            /proc                     proc            nodev,noexec,nosuid               0 0<br />
#none            /sys                      sysfs           nodev,noexec,nosuid               0 0<br />
#none  /dev  devtmpfs,tmpfs  mode=0755  0 0</p>
<h3>Edit rootfs.ubuntu/etc/init/rc-sysinit.conf</h3>
<p>Using any editor, open <strong>rootfs.ubuntu/etc/init/rc-sysinit.conf</strong>, look for the line<br />
<code><br />
start on filesystem and net-device-up IFACE=lo</code></p>
<p>and change it to</p>
<p class="code">start on filesystem<strong> #</strong> and net-device-up IFACE=lo</p>
<h3>Add an init (upstart) script</h3>
<p>Using any editor, make a file <strong>rootfs.lucid/etc/init/lxc.conf</strong> and add:<br />
<code><br />
# LXC – Fix init sequence to have LXC containers boot with upstart<br />
<br /># description “Fix LXC container - Lucid”<br />
<br />start on startup<br />
<br />task<br />
pre-start script<br />
mount -t proc proc /proc<br />
mount -t devpts devpts /dev/pts<br />
mount -t sysfs sys /sys<br />
mount -t tmpfs varrun /var/run<br />
mount -t tmpfs varlock /var/lock<br />
mkdir -p /var/run/network<br />
touch /var/run/utmp<br />
chmod 664 /var/run/utmp<br />
chown root.utmp /var/run/utmp<br />
if [ "$(find /etc/network/ -name upstart -type f)" ]; then<br />
chmod -x /etc/network/*/upstart || true<br />
fi<br />
end script<br />
<br />script<br />
start networking<br />
initctl emit filesystem --no-wait<br />
initctl emit local-filesystems --no-wait<br />
initctl emit virtual-filesystems --no-wait<br />
init 2<br />
end script</code></p>
<h2>Configure and start the container</h2>
<p>Create the container:</p>
<p class="code">lxc-create -f /home/bodhi/lxc/conf.ubuntu -n ubuntu<br />
lxc-start -n ubuntu</p>
<p>You should now be able to access the container with either lxc-console or ssh</p>
<p class="code">ssh root@192.168.0.60</p>
<p class="code">lxc-console -n ubuntu</p>
<p>Update: The lucid container now boots with the -d option .</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bodhizazen.net/linux/lxc-configure-ubuntu-lucid-containers/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>LXC &#8211; Linux Containers</title>
		<link>http://blog.bodhizazen.net/linux/lxc-linux-containers/</link>
		<comments>http://blog.bodhizazen.net/linux/lxc-linux-containers/#comments</comments>
		<pubDate>Tue, 02 Feb 2010 16:09:19 +0000</pubDate>
		<dc:creator>bodhi.zazen</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[LXC]]></category>
		<category><![CDATA[Virtualization]]></category>

		<guid isPermaLink="false">http://blog.bodhizazen.net/?p=871</guid>
		<description><![CDATA[Linux containers AKA LXC: How to configure your host node]]></description>
			<content:encoded><![CDATA[<p>Linux Containers seems to be the &#8220;new kid on the virtualization block&#8221; so I decided it was time to take the technology for a spin.</p>
<p>What are Linux Containers?</p>
<blockquote><p>Linux Containers (LXC) are an operating system-level virtualization method for running multiple isolated server installs (containers) on a single control host. LXC does not provide a virtual machine, but rather provides a virtual environment that has its own process and network space. It is similar to a chroot, but offers much more isolation.</p></blockquote>
<p> ~ <a href="http://lxc.teegra.net/">Dwight Schauer</a> ~</p>
<p>Linux containers has several features / advantages:</p>
<p>Advantages:</p>
<ul>
<li>Better isolation as compared to a chroot (chroot jail).</li>
<li>Low overhead. LXC uses minimal resources in terms of RAM and hard drive space without the overhead of installing a guest OS in a virtual machine ( <a href="http://www.vmware.com/">VMWare</a> / <a href="http://www.virtualbox.org/">VirtualBox</a> / <a href="http://www.linux-kvm.org/page/Main_Page">KVM</a> ) .</li>
<li>Applications and services (servers) run at native speed.</li>
<li>There is support for <a href="http://libvirt.org/drvlxc.html">Linux containers in libvirt</a> .</li>
<li>Linux containers work well with <a href="http://btrfs.wiki.kernel.org/index.php/Main_Page">btrfs</a> .</li>
<li>No special hardware is required, runs on 32 and 64 bit processors.</li>
<li>Linux containers are Open source.</li>
<li>Unlike <a href="http://xen.org/">XEN</a> or <a href="http://wiki.openvz.org/Main_Page">OpenVZ</a> , no patch is required to the kernel.</li>
</ul>
<p>But there is also a downside:</p>
<ul>
<li>Linux containers run Linux processes on a Linux kernel. This means you can run Linux (Fedora container on an Ubuntu host) but not other operating systems (Not BSD / OSX / Windows).</li>
<li>There are no GUI (graphical) interfaces to configure or manage the containers.</li>
<li>There is a paucity of documentation on how to install and configure a container.</li>
<li>Configuring a container requires a modest technical knowledge and skill (and a large grain of patience).</li>
</ul>
<p>In this post I will show how to configure your host node using Fedora and Ubuntu as examples. This information is relatively generic and you should be able to adapt most of the information to other Linux hosts. Some distributions (Arch / SUSE) have specific reference pages listed at the end of this post.</p>
<p>Configuration of the Host takes 4 steps:</p>
<ol>
<li>Kernel.</li>
<li>LXC tools.</li>
<li>Cgroups.</li>
<li>Bridge network card.</li>
</ol>
<h2>Kernel</h2>
<p>The good news, Linux containers are part of the mainstream Linux kernel. This means there is no need to patch or compile a custom kernel.</p>
<p>To run Linux containers you need kernel >= 2.6.27. The stock or default kernels, 2.6.29 or greater, that ship with most Linux distributions work out of the box.</p>
<h2>LXC tools</h2>
<p>There are a set tools are a set of commands / scripts to create and manage containers.</p>
<p><strong>lxc</strong> &#8211; These are the scripts used to manage containers. <a href="http://sourceforge.net/projects/lxc/">Home page</a> .</p>
<p><strong>bridge-utils</strong> &#8211; Although there are several options for networking, the consensus appears that the easiest ( ? best) option for networking is a bridge.</p>
<p><strong>debootstrap / febootstrap</strong> &#8211; These tools allow one to install a minimal Debian/Ubuntu or Fedora root file system.</p>
<p><strong>Fedora Host</strong></p>
<p class="code">su -c &#8220;yum install lxc bridge-utils febootstrap&#8221;</p>
<p><strong>Ubuntu Host</strong></p>
<p class="code">sudo apt-get install lxc bridge-utils debootstrap</p>
<p>Alternately you may compile the most recent lxc package from source :</p>
<p>Get the source code (the lxc project also maintains a git repository for bleeding edgers). At the time of this post, lxc-0.6.5 was the most recent version and, since it was recently released, no updated git version was yet available.</p>
<p><a href="http://lxc.sourceforge.net/download/lxc/">lxc source code</a></p>
<p class="code">wget http://lxc.sourceforge.net/download/lxc/lxc-0.6.5.tar.gz<br />
tar xvf lxc-0.6.5.tar.gz</p>
<p>Install dependencies:</p>
<p><strong>Feodra</strong></p>
<p class="code">su -c &#8220;yum install -y make gcc libcap libcap-devel&#8221;</p>
<p><strong>Ubuntu</strong></p>
<p class="code">sudo apt-get -y install libcap-dev</p>
<p>Compile and install</p>
<p class="code">
cd lxc-0.6.5<br />
./configure &#8211;prefix=/usr # two &#8211; - in front of &#8220;&#8211;prefix&#8221;<br />
make<br />
sudo make install # Ubuntu<br />
su -c &#8220;make install&#8221; # Fedora</p>
<p>As you compile you may see a message about running lxc as a user (vs root). You may ignore this advice as I could not get lxc-setcap working (the majority of the lxc commands require root privileges even after enabling the &#8220;lxc-setcap&#8221;).</p>
<blockquote><p>If you wish to have a non root user to use the lxc tools, you can add the needed capabilities to the tools by invoking the &#8216;lxc-setcap&#8217; script. To remove the capabilities, use the &#8216;lxc-setcap -d&#8217;.</p></blockquote>
<h2>cgroups</h2>
<p>AKA Control groups</p>
<p>cgroups are basically the configuration files that set and regulate (limit) resources available to the containers.</p>
<p>For additional information on cgroups see :</p>
<p><a href="http://www.mjmwired.net/kernel/Documentation/cgroups/cgroups.txt">Linux Kernel Documentation &#8211; cgroups</a><br />
<a href="http://berrange.com/personal/diary/2009/12/using-cgroups-with-libvirt-and-lxckvm">Using CGroups with libvirt and LXC/KVM guests in Fedora 12</a><br />
<a href="http://manpages.ubuntu.com/manpages/karmic/man1/lxc-cgroup.1.html">man lxc-cgroup</a></p>
<p>To configure cgroups, <strong>as root</strong>, run the following commands:</p>
<p class="code">mkdir /cgroup</p>
<p>Using any editor, edit <strong>/etc/fstab</strong> to include:</p>
<p class="code">none  /cgroup  cgroup  defaults  0 0</p>
<p>/cgroups will now mount automatically when you boot your system. To mount it manually without rebooting:</p>
<p class="code">mount /cgroup</p>
<h2>Bridge network card</h2>
<p>As outlined in the <a href="http://manpages.ubuntu.com/manpages/karmic/man5/lxc.conf.5.html">lxc.conf man page</a> there are several options for networking. The consensus when I searched the documentation was to use a bridge, so that is what I will outline here. Feel free to try the other options (examples in lxc.conf man page).</p>
<p>Unfortunately, configuring a bridge must be done manually. Also Network Manager will not manage the bridge (nor will many graphical firewall tools).</p>
<p><strong>Note</strong>: You can not bridge a wireless card.</p>
<h3>Fedora</h3>
<p>As root:</p>
<p class="code">chkconfig NetworkManager off<br />
chkconfig network on<br />
service NetworkManager stop<br />
service network start</p>
<p>Using any editor, edit <strong>/etc/sysconfig/network-scripts/ifcfg-eth0<br />
</strong></p>
<p class="code">DEVICE=eth0<br />
TYPE=Ethernet<br />
HWADDR=aa:bb:cc:dd:ee:ff:11:22 # DO NOT change your hardware mac<br />
ONBOOT=yes<br />
BRIDGE=br0<br />
USERCTL=no<br />
IPV6INIT=no</p>
<p>Make a new config file for your bridge</p>
<p>Using any editor, edit <strong>/etc/sysconfig/network-scripts/ifcfg-br0</strong></p>
<p><strong>To obtain an ip address automatically using DHCP</strong>:</p>
<p class="code">DEVICE=br0<br />
TYPE=Bridge<br />
BOOTPROTO=dhcp<br />
ONBOOT=yes<br />
DELAY=0</p>
<p><strong>To set a static IP</strong>:</p>
<p class="code">HOSTNANE=fedora<br />
DEVICE=br0<br />
ONBOOT=yes<br />
BOOTPROTO=static<br />
DELAY=0<br />
TYPE=Bridge<br />
IPADDR=192.168.0.10<br />
NETWORK=192.168.0.0<br />
NETMASK=255.255.255.0<br />
GATEWAY=192.168.0.1<br />
MTU=1500<br />
DNS1=192.168.0.1<br />
IPV6INIT=no<br />
USERCTL=no</p>
<p>Next, using any editor, edit <strong>/etc/sysconfig/network-scripts/ifup-post</strong></p>
<p>Just above the &#8220;exit 0&#8243; at the bottom add:</p>
<p class="code">if [ $DEVNAME = "br0" ]; then<br />
  /usr/sbin/brctl setfd br0 0<br />
fi</p>
<p>Restart your network:</p>
<p class="code">service network restart</p>
<p><strong>Note</strong>: You may need to manually edit <strong>/etc/resolv.conf</strong> and add your nameserver back in.</p>
<p class="code">nameserver 192.168.0.1</p>
<h3>Ubuntu</h3>
<p>Turn network manager off or remove it.</p>
<p class="code">sudo apt-get remove –purge network-manager network-manager-gnome</p>
<p>Stop your networking</p>
<p class="code">service networking stop</p>
<p>Using any editor, edit <strong>/etc/network/interfaces</strong> adding lines for your bridge:</p>
<p><strong>To obtain an ip address automatically using DHCP</strong>:</p>
<p class="code">auto lo<br />
iface lo inet loopback<br />
<br />auto br0<br />
iface br0 inet dhcp<br />
bridge_ports eth0<br />
bridge_stp off<br />
bridge_maxwait 5<br />
post-up /usr/sbin/brctl setfd br0 0</p>
<p><strong>To set a static IP</strong>:</p>
<p class="code">auto lo<br />
iface lo inet loopback<br />
<br />auto br0<br />
iface br0 inet static<br />
address 192.168.0.10<br />
netmask 255.255.255.0<br />
broadcast 192.168.0.255<br />
gateway 192.168.0.1<br />
bridge_ports eth0<br />
bridge_stp off<br />
bridge_maxwait 5<br />
post-up /usr/sbin/brctl setfd br0 0</p>
<p>Using any editor, edit <strong>/etc/resolv.conf</strong> and add in your nameserver</p>
<p class="code">nameserver 192.168.0.1</p>
<h2>Managing containers</h2>
<p>Containers, or guests, are built either with lxc tools (lxc-debian or lxc-fedora), debootstrap / febootstrap, or by converting openvz containers.</p>
<p>In Fedora, lxc-debian is not working. In Ubuntu neither lxc-fedora nor lxc-debian are working (and there is no lxc-ubuntu yet).</p>
<p>OpenVZ containers may be old / out of date and will require some modification.</p>
<p>Thus, of the 3 options I prefer bootstraping a minimal container.</p>
<p>In practice, creating a container takes some time and in my next blogs I will post detailed instructions for Fedora and Ubuntu.</p>
<p><strong>In this post I will assume you have a working root file system</strong>, I call mine rootfs.fedora , rootfs.ubuntu, etc</p>
<p><strong>Note</strong>: The commands to manage containers are run as root.</p>
<h3>Create a container</h3>
<p>To use LXC to provide VPS you need two things, a directory containing the file system, aka rootfs (see the above section), and a configuration file.</p>
<p>To create a config file for your container I suggest you either editing a generic template or better, read the man page and write one from scratch. See <a href="http://manpages.ubuntu.com/manpages/karmic/man5/lxc.conf.5.html">man lxc.conf</a> for options</p>
<p>Basic file (very slightly modified from the default config file generated from lxc-fedora on a Fedora host):<br />
<code><br />
lxc.utsname = container_name<br />
lxc.tty = 4<br />
lxc.network.type = veth<br />
lxc.network.flags = up<br />
lxc.network.link = br0<br />
lxc.network.name = eth0<br />
lxc.network.mtu = 1500<br />
lxc.network.ipv4 = your_network_here #for example 192.168.0.0/24<br />
lxc.rootfs = /full/path/to/rootfs<br />
lxc.cgroup.devices.deny = a<br />
# /dev/null and zero<br />
lxc.cgroup.devices.allow = c 1:3 rwm<br />
lxc.cgroup.devices.allow = c 1:5 rwm<br />
# consoles<br />
lxc.cgroup.devices.allow = c 5:1 rwm<br />
lxc.cgroup.devices.allow = c 5:0 rwm<br />
lxc.cgroup.devices.allow = c 4:0 rwm<br />
lxc.cgroup.devices.allow = c 4:1 rwm<br />
# /dev/{,u}random<br />
lxc.cgroup.devices.allow = c 1:9 rwm<br />
lxc.cgroup.devices.allow = c 1:8 rwm<br />
# /dev/pts/* - pts namespaces are "coming soon"<br />
lxc.cgroup.devices.allow = c 136:* rwm<br />
lxc.cgroup.devices.allow = c 5:2 rwm<br />
# rtc<br />
lxc.cgroup.devices.allow = c 254:0 rwm</code></p>
<p>Basically you will edit 3 lines (although you may use additional options, see man lxc.conf).<br />
lxc.utsname = container_name<br />
lxc.network.ipv4 = your_network_here (ie 192.168.0.0/24)<br />
lxc.rootfs = /full/path/to/rootfs</p>
<p>The lines with &#8220;lxc.group &#8230;&#8221; define which resources are available to the container and configure confinement. The line &#8220;lxc.cgroup.devices.deny = a&#8221; denies access to everything and exceptions are added in in the following lines as needed. Yes, the terminology is cryptic, and for a better understanding I will have to refer you to the cgroup references in this blog.</p>
<p>Once you have a rootfs and a config file, run lxc-create :</p>
<p class="code">lxc-create -f /path_to/config.file -n name_of_container</p>
<p>For example:</p>
<p class="code">lxc-create -f /root/config.fedora -n fedora</p>
<h3>Start a container</h3>
<p>The basic command is lxc-start -n name_of_container</p>
<p class="code">lxc-start -n fedora</p>
<p>Starting this way will show you the boot messages you would normally get when booting your distro. Watch for error messages (you will need to fix them manually).</p>
<p>Once the container is working, you can start it with the -d (demonize) option.</p>
<p class="code">lxc-start -d -n fedora</p>
<p><strong>Note</strong>: Some containers may not start with the -d option, in that case, IMO, better to use screen:</p>
<p class="code">screen -dmS lxc_container_name lxc-start -n lxc_container_name</p>
<p>For example:</p>
<p class="code">screen -dmS ubuntu lxc-start -n ubuntu</p>
<h3>Stop a container</h3>
<p class="code">lxc-stop -n name_of_container</p>
<p>For example:</p>
<p class="code">lxc-stop -n fedora</p>
<h3>Destroy a container</h3>
<p class="code">lxc-destroy -n name_of_container</p>
<p>For example:</p>
<p class="code">lxc-destroy -n fedora</p>
<h3>Manage resources</h3>
<p>The resources available to your containers is managed via cgroups. You manage them with the lxc-cgroup command. The resources are listed as flat text files in /cgroup/name_of_container .</p>
<p>A detailed discussion of cgroup is beyond this post, but I may devote a separate blog to this topic after finishing instructions for Fedora and Ubuntu containers. See the links in the cgroup section above for helpful links to &#8220;get you started&#8221;.</p>
<h2>Tips</h2>
<p>A few comments on the structure of containers on the host file system. </p>
<p>1. /var/lib/lxc : Container configuration files are kept in /var/lib/lxc . It makes life easier to make a link or bind /var/lib/lxc to /lxc</p>
<p class="code">mkdir /lxc<br />
ln -s /var/lib/lxc /lxc</p>
<p>2. /var/cache/lxc : Used by lxc-debian and lxc-fedora as a cache for downloading and installing a rootfs .</p>
<p>3. /cgroup/name_of_container : Location of container cgroup files.</p>
<p>4. lxc-fedora</p>
<p>When using lxc-fedora, the root file system is downloaded to /var/cache/lxc/fedora and then copied to your current working directory. This makes it much faster the next time you invoke lxc-fedora as it will copy the cached rootfs to your current working directory without repeating the downloading and installation of the base packages.</p>
<p>So, for example, if you lxc-fedora create, you will be asked a few questions, including the name of your container and network configuration.</p>
<p>If you run the command from /root, the script will cache and install the packages in /var/cache/lxc/fedora, copy the /var/cache/lxc/fedora to /root/name_of_container, and generate a configuration file based on the options you give.</p>
<p>When you then create a container, with lxc-create, the configuration files are generated in /var/lib/lxc , and a link is generated for the rootfs to /root/fedora (assuming you names the container fedora).</p>
<p>This behavior is NOT emulated if you use bootstrap to make a rootfs manually or import (convert) an openvz template.</p>
<p>The down side of lxc-fedora is that the container still needs some modification and it is larger then if you use febootstrap.</p>
<p>See my blogs on generating a Fedora and Ubuntu container for detailed instructions.</p>
<p>5. IMHO, containment is <strong>very poor if you chroot</strong> into the container form the host node. Use lxc-console or ssh into the container.</p>
<h2>References:</h2>
<ul>
<li><a href="http://lxc.sourceforge.net/lxc.html">LXC Home page</a>.</li>
<li><a href="http://www.ibm.com/developerworks/linux/library/l-lxc-containers/">IBM &#8211; LXC: Linux container tools.</a></li>
<li><a href="http://libvirt.org/drvlxc.html">Libvirt LXC</a>.</li>
<li><a href="http://lxc.teegra.net/">Arch specific</a>.</li>
<li><a href="http://en.opensuse.org/LXC">SUSE specific</a>.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.bodhizazen.net/linux/lxc-linux-containers/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>ModSecurity 2.5  &#8211; Book Review</title>
		<link>http://blog.bodhizazen.net/uncategorized/modsecurity-2-5-book-review/</link>
		<comments>http://blog.bodhizazen.net/uncategorized/modsecurity-2-5-book-review/#comments</comments>
		<pubDate>Fri, 08 Jan 2010 05:39:43 +0000</pubDate>
		<dc:creator>bodhi.zazen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.bodhizazen.net/?p=863</guid>
		<description><![CDATA[Happy New Year Everybody =)
I had the privilege of reviewing ModSecurity 2.5 by Magnus Mischel and now that the holidays are over, well, time to stop procrastinating.

For those unfamiliar with ModSecurity, it is an Apache module designed to enhance (Apache server) security. For more information on mod_security see this link .
ModSecurity is a security tool that has a number of features, but how to unleash the power of these advanced features ? Sure one can download and install mod_security and the community rule set, but where to go from there ? Where to turn for assistance with deploying mod_security ?
Enter ModSecurity 2.5 by Magnus Mischel
Although when working with Apache security it is helpful if you understand the basics of HTTP headers, this book will help get you started with mod_security. The book starts with installation of mod_security and then covers configuration and customization. The features of mod_security are detailed with [...]]]></description>
			<content:encoded><![CDATA[<p>Happy New Year Everybody =)</p>
<p>I had the privilege of reviewing <a href="http://www.packtpub.com/modsecurity-2-5/book">ModSecurity 2.5 by Magnus Mischel</a> and now that the holidays are over, well, time to stop procrastinating.</p>
<p><img src="http://bodhizazen.net/img/ModSec.jpg" alt="Book Cover" /></p>
<p>For those unfamiliar with ModSecurity, it is an Apache module designed to enhance (Apache server) security. For more information on mod_security see <a href=" http://www.modsecurity.org/projects/modsecurity/apache/">this link</a> .</p>
<p>ModSecurity is a security tool that has a number of features, but how to unleash the power of these advanced features ? Sure one can download and install mod_security and the community rule set, but where to go from there ? Where to turn for assistance with deploying mod_security ?</p>
<p>Enter ModSecurity 2.5 by Magnus Mischel</p>
<p>Although when working with Apache security it is helpful if you understand the basics of HTTP headers, this book will help get you started with mod_security. The book starts with installation of mod_security and then covers configuration and customization. The features of mod_security are detailed with clear explanations and examples. </p>
<p>The Book consists of 9 chapters and 2 appendices.</p>
<p><strong>Chapter 1</strong> Describes how to obtain and compile mod_security from source code. Often when working with security it is preferable to install the most up to date version rather then relying on older binaries from repositories. As such the instructions for compiling are easy to follow and will make compiling mod_security from source less intimidating. The author then describes how to configure Apache to use mod_security and test the initial installation.</p>
<p><strong>Chapter 2</strong> Describes how to write rules for mod_security. For those who are unfamiliar with regular expressions, there is a brief but thorough review of the syntax of regular expressions (and may be helpful even if you are familiar with regular expressions). The chapter concludes with several examples of practical rules to block undesired traffic by IP address, region, or after failing a set number of log in attempts.</p>
<p><strong>Chapter 3</strong> presents an analysis of how mod_security affects performance and suggests methods to both test and optimize performance.</p>
<p><strong>Chapter 4</strong> continues with a description of how to use and review the log files for mod_security. The chapter begins with a description of the logs and an overview of the options. The chapter concludes with a description of how to install and use the ModSecurity Console, which provides a web based graphical log analysis. Although again compiling is necessary, the directions were easy to understand and I was able to download and install the ModSecurity Console without any problems. I found the Console easy to understand and use.<br />
<strong><br />
Chapter 5</strong> covers additional practical examples of using mod_security via the use of &#8220;Virtual Patching&#8221;. The general idea here is that if there is a known vulnerability in Apache, or mysql, one may be able to deploy a set of rules using mod_security that will prevent exploitation of such a zero day exploit while waiting for a patch from upstream. As is characteristic of the book, the chapter concludes with an example of a theoretical mysql injection and how to &#8220;virtual patch&#8221; the vulnerability with mod_security. Cross-site scripting and the twitter worm are covered as additional examples.<br />
<strong><br />
Chapter 6</strong> is titled &#8220;Blocking Common Attacks&#8221; and as you might imagine covers very practical security threats such as http fingerprinting, blocking proxy requests, cross-site scripting, cross site forgeries, shell command execution attempts, and SQL injection (to name a few). An overview if each potential threat is provided if you do not know the terminology and then specific examples and mod_security rules are described.</p>
<p><strong>Chapter 7</strong> covers chroot jails. The concept of a chroot jail is introduced and using mod_security to simplify using apache in a chroot jail is then described.</p>
<p><strong>Chapter 8</strong> &#8211; REMO. Remo is a web based graphical tool to write and edit mod_security rules. Again easy to follow directions were provided and REMO was easy to install. The chapter covers how to configure REMO and use the interface to modify rules.</p>
<p>The book concludes with <strong>chapter 9</strong> &#8220;Protecting a Web Application&#8221;. This chapter details how to write and monitor a custom set of rules for a web application, YaBB (Yet another Bulletin Board). This is a daunting task and if you feel your are super man (or woman) go for it. The process involves a thorough understanding of the normal functions of the web application and would require a test server to use for development and testing of rules. Ethereal or fiddler are used to monitor http activity and this information is then used to write a rule set for YaBB. The rules then are debugged.</p>
<p><strong>Appendix A</strong> is a compendium of Directives and variables for use with mod_security.</p>
<p><strong>Appendix B</strong> covers Regular Expressions in more detail.</p>
<p>OK, so not exactly light reading. This book will provide a solid foundation for ModSecurity and should be extremely helpful in understanding an deploying mod_security.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bodhizazen.net/uncategorized/modsecurity-2-5-book-review/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Firewall Ubuntu GUFW</title>
		<link>http://blog.bodhizazen.net/linux/firewall-ubuntu-gufw/</link>
		<comments>http://blog.bodhizazen.net/linux/firewall-ubuntu-gufw/#comments</comments>
		<pubDate>Wed, 25 Nov 2009 00:01:25 +0000</pubDate>
		<dc:creator>bodhi.zazen</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://blog.bodhizazen.net/?p=842</guid>
		<description><![CDATA[This is the third in my Firewall series, is in follow up to my previous 2 blogs about firewalls, and is intended to introduce GUFW, a graphical front end to UFW.
Firewall Ubuntu Desktops
Firewall Ubuntu Servers
Although the GUFW GUI may seem deceptively simple, the graphical front end is both easy to use and capable of performing the most common firewall configuration options. The graphical tool is a perfect place to start if you find ufw and iptables overwhelming.
Again the most difficult part of managing a firewall is knowing who you wish to allow or restrict (by ip address) and what service and port you need to allow (open) or deny (close). Gufw can help as many of these options are preconfigured. If you need further assistance, start with gufw, configure as much as you can, and then review the other two links.
GUFW is an option if you installed a few simple [...]]]></description>
			<content:encoded><![CDATA[<p>This is the third in my Firewall series, is in follow up to my previous 2 blogs about firewalls, and is intended to introduce GUFW, a graphical front end to UFW.</p>
<p><a href="http://blog.bodhizazen.net/linux/firewall-ubuntu-desktops/">Firewall Ubuntu Desktops</a><br />
<a href="http://blog.bodhizazen.net/linux/firewall-ubuntu-servers/">Firewall Ubuntu Servers</a></p>
<p>Although the GUFW GUI may seem deceptively simple, the graphical front end is both easy to use and capable of performing the most common firewall configuration options. The graphical tool is a perfect place to start if you find ufw and iptables overwhelming.</p>
<p>Again the most difficult part of managing a firewall is knowing who you wish to allow or restrict (by ip address) and what service and port you need to allow (open) or deny (close). Gufw can help as many of these options are preconfigured. If you need further assistance, start with gufw, configure as much as you can, and then review the other two links.</p>
<p>GUFW is an option if you installed a few simple servers on your desktop (torrents for example) or if you installed a graphical desktop/ window manager (Gnome, Fluxbox, etc) to help you administrate a server.</p>
<p>As a side note, server side, rather then installing a GUI, some people probably use either the command line or web tools such as <a href="http://www.webmin.com/">webmin</a>, <a href="http://www.phpmyadmin.net/home_page/index.php">phpMyAdmin</a>, etc to manage servers.</p>
<h2>Install GUFW</h2>
<p>Although ufw is installed by default, gufw is not. </p>
<p>First, <a href="https://help.ubuntu.com/community/Repositories/Ubuntu">Enable the Universe repository</a>.</p>
<p>Then, <a href="https://help.ubuntu.com/community/InstallingSoftware">using any method</a>, install gufw (apt-get shown here).</p>
<p class="code">sudo apt-get update<br />
sudo apt-get -y install gufw</p>
<p>In Ubuntu 9.10, UFW is then located under System -> Administration -> Firewall configuration.</p>
<h2>Enable your firewall</h2>
<p>Simply click (check off) the &#8220;Enabled&#8221; button and select &#8220;Deny&#8221; in the &#8220;By Default&#8221; pull down menu.</p>
<p><img src="http://bodhizazen.net/img/GUFW/UFW.png" alt="Enable Firewall" /></p>
<p>The default settings are probably sufficient for the vast majority of Desktop users and, unless you are running a server, nothing further needs to be done. Simply close the GUFW window and your firewall will remain active, even if you reboot.</p>
<p>IMO, The most common servers used on desktops would include torrents, VNC, Samba, Apache, and SSH. If you are wanting to allow access to one or more of these servers you will need to configure GUFW as outlined below.</p>
<h2>Allow inbound connections</h2>
<p>UFW manages NEW INBOUND connections. <strong>Gufw allows all outbound traffic (see limitations below).</strong></p>
<p>Use the following options if you are running servers and you wish to allow inbound connections from other computers.</p>
<p>To add a rule, first click the &#8220;Add&#8221; box on the bottom left. You will get a dialog box which will allow you a number of options.</p>
<h3>Preconfigured options</h3>
<p>GUFW has a number of common services preconfigured. You allow a service by program name (perhaps most useful on Desktops). As you can see common servers used on desktops, such as Transmission, are included (surprise, torrents are servers).</p>
<p><img src="http://bodhizazen.net/img/GUFW/UFW-1.png" alt="Preconfigured Programs" /></p>
<p>Or by service (perhaps most useful on servers).</p>
<p><img src="http://bodhizazen.net/img/GUFW/UFW-2.png" alt="Preconfigured Services" /></p>
<h3>By port</h3>
<p>In the &#8220;Simple&#8221; tab you can open a specific port, by tcp, udp, or both. Simply add the port you wish to open in the box.</p>
<p><img src="http://bodhizazen.net/img/GUFW/UFW-3.png" alt="Simple" /></p>
<p>You may specify multiple ports, comma delineated</p>
<p>22,80,443</p>
<p>Or a range of ports with a : , so to allow bittorrent, open ports 6881 – 6999, use </p>
<p>6881:6999</p>
<h2>Limit traffic</h2>
<p>You may use the &#8220;Advanced&#8221; tab to allow or deny traffic from a specific ip address or subnet (LAN). Keep in mind order of your rules counts, so deny first then allow.</p>
<p>You may blacklist an ip address by denying all traffic from that IP.</p>
<p>In this example, all traffic from your LAN is allowed to connect to Apache (sorry the first part of &#8220;192.168.0.0/24&#8243; was outside the box).</p>
<p><img src="http://bodhizazen.net/img/GUFW/UFW-4.png" alt="Limit traffic" /></p>
<p>Firewall rules are displayed in the main GUFW window. The rule displayed in this example allows all traffic on the LAN (192.168.0.0/24) to access Apache ( port 80/tcp) on the server (ip address 192.168.1.10).</p>
<p><img src="http://bodhizazen.net/img/GUFW/UFW-5.png" alt="Allow Apache" /></p>
<h2>Remove a rule</h2>
<p>Simply select your rule and click the &#8220;Remove&#8221; button on the bottom.</p>
<p><img src="http://bodhizazen.net/img/GUFW/UFW-6.png" alt="Remove Rule" /></p>
<h2>Logs</h2>
<p>Logging is enabled by default. Under the menu, select Edit -> Preferences</p>
<p><img src="http://bodhizazen.net/img/GUFW/UFW-7.png" alt="Enable logs" /></p>
<p>Enable logging by selecting (checking off) your &#8220;Enable Gufw Logging&#8221; and &#8220;Enable ufw Logging&#8221;.</p>
<h3>View the log</h3>
<p>Under File -> Select the option &#8220;Log&#8221; with the magnifying glass icon</p>
<p><img src="http://bodhizazen.net/img/GUFW/UFW-8.png" alt="File - log" /> </p>
<p>And you will see your logs. Although not displayed, any denied traffic will be logged.</p>
<p><img src="http://bodhizazen.net/img/GUFW/UFW-9.png" alt="View logs" /></p>
<p>You may clear the logs from this menu as well.</p>
<h2>Limitations of GUFW</h2>
<p>IMO GUFW is designed for users who wish to enable a firewall and do not feel they need to know the dirty details. As such it is simple and effective, although it does not offer all of the available options from either ufw or iptables.</p>
<ul>
<li>GUFW does not manage (limit) outbound traffic.</li>
<li>GUFW only manages NEW connections.</li>
<li>GUFW does not give the option to block ping or limit connections.</li>
</ul>
<p>You will need to user either ufw from the command line, learn iptables, or use another configuration tool if you need these options.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bodhizazen.net/linux/firewall-ubuntu-gufw/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Firewall Ubuntu Servers</title>
		<link>http://blog.bodhizazen.net/linux/firewall-ubuntu-servers/</link>
		<comments>http://blog.bodhizazen.net/linux/firewall-ubuntu-servers/#comments</comments>
		<pubDate>Mon, 23 Nov 2009 23:43:42 +0000</pubDate>
		<dc:creator>bodhi.zazen</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://blog.bodhizazen.net/?p=789</guid>
		<description><![CDATA[This post is in follow up to my post on firewalls on Ubuntu Desktops.
IMO firewalls are often helpful for restricting access to servers. Servers come in two varieties, public and private, and often people wish to limit access or black list IP addresses that misbehave.
Again I will use UFW which is installed by default. In the last section I will introduce iptables. One feature that is nice about ufw, if you understand the ufw rules it is an easy transition to iptables.
The most important thing you need to know to firewall servers is;

Who (ip address) you wish to allow or restrict access.
What protocol (tcp / udp) and port is used by your server.

A listing of ports is available here.
Enable your firewall
If you are accessing your server remotely be sure NOT to lock yourself out
Assuming you are accessing via ssh, allow ssh (we will restrict ssh access below, for now just [...]]]></description>
			<content:encoded><![CDATA[<p>This post is in follow up <a href="http://blog.bodhizazen.net/linux/firewall-ubuntu-desktops/">to my post on firewalls on Ubuntu Desktops</a>.</p>
<p>IMO firewalls are often helpful for restricting access to servers. Servers come in two varieties, public and private, and often people wish to limit access or black list IP addresses that misbehave.</p>
<p>Again I will use UFW which is installed by default. In the last section I will introduce iptables. One feature that is nice about ufw, <strong>if you understand the ufw rules it is an easy transition to iptables</strong>.</p>
<p>The most important thing you need to know to firewall servers is;</p>
<ol>
<li>Who (ip address) you wish to allow or restrict access.</li>
<li>What protocol (tcp / udp) and port is used by your server.</li>
</ol>
<p>A listing of ports is available <a href="http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers">here</a>.</p>
<h2>Enable your firewall</h2>
<p><strong>If you are accessing your server remotely be sure NOT to lock yourself out</strong></p>
<p>Assuming you are accessing via ssh, allow ssh (we will restrict ssh access below, for now just do not lock yourself out).</p>
<p class="code">sudo ufw allow 22</p>
<p>Now enable your firewall. Except for ssh, which you allowed with the above rule, this will deny all incoming (udp/tcp) traffic to your server.</p>
<p class="code">sudo ufw enable<br />
sudo default deny</p>
<h2>Public servers</h2>
<p>Examples of public servers would be Apache (http) or FTP servers (to name a few). Here we wish to allow access to just about everyone.</p>
<p>Simply allow by port</p>
<p class="code">sudo ufw allow 80</p>
<p>Or if you wish, by protocol and port (most servers will be tcp).</p>
<p class="code">sudo ufw allow 80/tcp</p>
<p>You may specify multiple ports (comma separated list):</p>
<p class="code">sudo ufw allow 80,443/tcp</p>
<p>Or a range of ports, low:high:</p>
<p class="code">#Allow ports 6881 &#8211; 6999 (torrent)<br />
sudo ufw allow 6881:6999/tcp</p>
<p>You may specify most services by name.</p>
<p>By Name :</p>
<p class="code">sudo ufw allow ssh</p>
<p>Some servers can be specified &#8220;by application&#8221;, although this is still by port and is not application specific. By that I mean : if you allow &#8220;Apache&#8221;, you open port 80, which can be used by any client application (firefox, wget, etc).</p>
<p>List applications with -</p>
<p class="code">sudo ufw app list</p>
<p><code><br />
ufw app list<br />
Available applications:<br />
  Apache<br />
  Apache Full<br />
  Apache Secure<br />
  CUPS<br />
  OpenSSH</code></p>
<p>To translate the cryptic output to English,<br />
Apache = http = port 80<br />
Apache Secure = https = port 443<br />
Apache Full = both ports</p>
<p>As you install servers, they will be added to the list.</p>
<p>Now allow by application.</p>
<p>Examples (you do not need to use all 3 rules):</p>
<p class="code">sudo ufw allow Apache<br />
<br />#Note: Quotes are needed with &#8220;Apache Full&#8221;<br />
sudo ufw allow &#8220;Apache Full&#8221;<br />
<br />sudo ufw allow from 192.168.0.0/24 app OpenSSH</p>
<p>You may add <strong>custom applications or custom ports</strong> to /etc/ufw/application.d</p>
<p>As an example, /etc/ufw/applications.d/apache2.2-common contains<br />
<code><br />
[Apache]<br />
title=Web Server<br />
description=Apache v2 is the next generation of the omnipresent Apache web server.<br />
ports=80/tcp<br />
<br />[Apache Secure]<br />
title=Web Server (HTTPS)<br />
description=Apache v2 is the next generation of the omnipresent Apache web server.<br />
ports=443/tcp<br />
<br />[Apache Full]<br />
title=Web Server (HTTP,HTTPS)<br />
description=Apache v2 is the next generation of the omnipresent Apache web server.<br />
ports=80,443/tcp</code></p>
<p>So if you changed the ssh port to 8822, add a file &#8220;ssh-custom&#8221;, at /etc/ufw/applications.d/ssh-custom</p>
<p class="code">[SSH Custom]<br />
title= SSH Custom port<br />
description=OpenSSH Server Custom port<br />
ports=8822/tcp</p>
<p>You will now see &#8220;SSH Custom&#8221; when you list apps and can use it as above.</p>
<h2>Private servers</h2>
<p>Examples may included NFS, Samba, ssh, VNC, and VPN. I will use ssh and Apache as an examples.</p>
<p>For these examples we will assume your <strong>LAN is 192.168.0.0/24 and your server is 192.168.0.10</strong></p>
<p>Here we almost always wish to restrict access to a single ip or perhaps range of IP. For example to restrict access for ssh to a single machine, say 192.168.0.20</p>
<p class="code">sudo ufw allow proto tcp from 192.168.0.20 to 192.168.0.10 port 22</p>
<p>The syntax is protocol from	&lt;ip&gt; to	&lt;server ip&gt; port</p>
<p>To allow ssh from any client on your your lan use:</p>
<p class="code">sudo ufw allow proto tcp from 192.168.0.0/24 to 192.168.0.10 port 22</p>
<h2>Limiting access</h2>
<p>Limiting access comes in two flavors, the first is to limit a DOS or brute force attempt, and the other blacklisting.</p>
<h3>Brute Force</h3>
<p>UFW will rate limit connection attempts:</p>
<blockquote><p>ufw supports connection rate limiting, which is useful for protecting against brute-force login attacks.  ufw  will  deny connections  if  an  IP  address  has  attempted  to  initiate  6  or  more  connections  in  the  last  30 seconds.</p></blockquote>
<p>Example (using ssh):</p>
<p class="code">sudo ufw limit ssh</p>
<p><strong>&#8220;Limit&#8221; opens the port, so you do not need a second rule.</strong></p>
<p><code><br />
ufw status<br />
Status: active<br />
<br />To                         Action  From<br />
--                         ------  ----<br />
22                         LIMIT   Anywhere</code></p>
<p>This output demonstrates &#8211; <strong>Port 22 is open and access is limited by ufw.</strong></p>
<h3>Blacklist</h3>
<p>Keep in mind the order of your rules is critical. As such I like to block first, accept second. So for example let us assume we wish to block a misbehaving client on our LAN, 192.168.0.20:</p>
<p class="code">sudo ufw insert 1 deny from 192.168.0.20</p>
<p>Here &#8220;insert 1&#8243; is specifying to ufw to insert the rule first (or near the top) of the chain.</p>
<p><strong>Using UFW in this way blocks only NEW connections.</strong></p>
<p>IMO better to use iptables or an application such as <a href="http://ubuntuforums.org/showthread.php?t=530183">iplist</a>.</p>
<h2>Block ping</h2>
<p>By default, UFW allows ping requests. In order to block these requests you will need to edit /etc/ufw/before.rules </p>
<p class="code">sudo -e /etc/ufw/before.rules</p>
<p>Change <code><br />
# ok icmp codes<br />
-A ufw-before-input -p icmp --icmp-type destination-unreachable -j ACCEPT<br />
-A ufw-before-input -p icmp --icmp-type source-quench -j ACCEPT<br />
-A ufw-before-input -p icmp --icmp-type time-exceeded -j ACCEPT<br />
-A ufw-before-input -p icmp --icmp-type parameter-problem -j ACCEPT<br />
-A ufw-before-input -p icmp --icmp-type echo-request -j ACCEPT</code></p>
<p>to</p>
<p class="code"># ok icmp codes<br />
-A ufw-before-input -p icmp &#8211;icmp-type destination-unreachable -j ACCEPT<br />
-A ufw-before-input -p icmp &#8211;icmp-type source-quench -j ACCEPT<br />
-A ufw-before-input -p icmp &#8211;icmp-type time-exceeded -j ACCEPT<br />
-A ufw-before-input -p icmp &#8211;icmp-type parameter-problem -j ACCEPT<br />
-A ufw-before-input -p icmp &#8211;icmp-type echo-request -j DROP</p>
<p>Restart UFW</p>
<p class="code">sudo ufw disable<br />
sudo ufw enable</p>
<h2>Deleting rules</h2>
<p>Deleting a rule is also easy. Use the same syntax you used to add a rule to ufw with the word &#8220;delete&#8221; added.</p>
<p>For example, using Apache as an example:</p>
<p class="code"># sudo ufw allow Apache<br />
Rule added<br />
<br/># ufw status<br />
Status: active<br />
<br />To                         Action  From<br />
&#8211;                         &#8212;&#8212;  &#8212;-<br />
22                         LIMIT   Anywhere<br />
Apache                     ALLOW   Anywhere<br />
<br /># sudo ufw delete allow Apache<br />
Rule deleted<br />
<br /># ufw status<br />
Status: active<br />
<br />To                         Action  From<br />
&#8211;                         &#8212;&#8212;  &#8212;-<br />
22                         LIMIT   Anywhere</p>
<h2>Iptables</h2>
<p>Now that you have ufw under your belt, it is easier to understand iptables. If you are wanting to use iptables, best disable UFW first.</p>
<p class="code">sudo ufw disable<br />
<br />#These iptables rules clean up after UFW, deleting the custom tables<br />
sudo iptables -F<br />
sudo iptables -X</p>
<p>To deny all incoming traffic (take care not to lock yourself out form remote servers, allow ssh first !!!):</p>
<p class="code">sudo iptables -A INPUT -j DROP</p>
<p>You can set a Policy with iptables, but doing so makes it easy to lock yourself out if you issue the command &#8220;iptables -F&#8221;.</p>
<p>To allow ssh</p>
<p class="code">sudo iptables -A INPUT -p tcp &#8211;dport 22 -j ACCEPT</p>
<p>To allow ssh only from your LAN:</p>
<p class="code">sudo iptables -A INPUT -s 192.168.0.0/24 -p tcp &#8211;dport 22 -j ACCEPT</p>
<p>iptables is much more feature rich the UFW and hopefully this blog will both stimulate your interest and facilitate your learning of the use of iptables.</p>
<p>See also : <a href="http://bodhizazen.net/Tutorials/iptables">Bodhi Zazen&#8217;s Iptables Primer</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bodhizazen.net/linux/firewall-ubuntu-servers/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Firewall Ubuntu Desktops</title>
		<link>http://blog.bodhizazen.net/linux/firewall-ubuntu-desktops/</link>
		<comments>http://blog.bodhizazen.net/linux/firewall-ubuntu-desktops/#comments</comments>
		<pubDate>Mon, 23 Nov 2009 06:34:16 +0000</pubDate>
		<dc:creator>bodhi.zazen</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://blog.bodhizazen.net/?p=765</guid>
		<description><![CDATA[Many Ubuntu users are interested in learning how to enable a firewall. The majority of people seem to be interested in filtering in an out bound connections on a Desktop installation.
Without getting into the inevitable debate on the merits of using a firewall, I would like to pass on some basic information. Please understand that discussions about firewalls and understanding the technical details of a firewall can become complicated very fast. The goal of this blog therefore is to enable users to feel comfortable with the basic firewall manipulations on an Ubuntu Desktop installation.
You should also know, by default Ubuntu, unlike some operating systems, has no significant listening servers. You may list your listening servers with any of the following commands:
sudo bash -c &#8220;netstat -an &#124; grep LISTEN &#124; grep -v ^unix&#8221;
netstat -ntulp
sudo lsof -i -n -P
Alternately you may perform a portscan from a second computer, ie nmap
I strongly advise [...]]]></description>
			<content:encoded><![CDATA[<p>Many Ubuntu users are interested in learning how to enable a firewall. The majority of people seem to be interested in filtering in an out bound connections on a Desktop installation.</p>
<p>Without getting into the inevitable debate on the merits of using a firewall, I would like to pass on some basic information. Please understand that discussions about firewalls and understanding the technical details of a firewall can become complicated very fast. The goal of this blog therefore is to enable users to feel comfortable with the basic firewall manipulations on an Ubuntu Desktop installation.</p>
<p>You should also know, by default Ubuntu, unlike some operating systems, has no significant listening servers. You may list your listening servers with any of the following commands:</p>
<p class="code">sudo bash -c &#8220;netstat -an | grep LISTEN | grep -v ^unix&#8221;<br />
netstat -ntulp<br />
sudo lsof -i -n -P</p>
<p>Alternately you may perform a portscan from a second computer, ie <a href="http://nmap.org/nmap_doc.html">nmap</a></p>
<p>I strongly advise the use of <a href="https://help.ubuntu.com/community/Uncomplicated_Firewall_ufw">UFW (Uncomplicated FireWall)</a> as it is installed by default, the syntax is easy to understand, and the defaults are more then adequate for the vast majority of users. If you prefer a graphical front end, install <a href="https://help.ubuntu.com/community/Gufw">GUFW</a>.</p>
<h2>Enable your firewall</h2>
<p>This is very easy:</p>
<p class="code">sudo ufw enable</p>
<h2>Deny incoming connections</h2>
<p>This setting will deny all new incoming connections. Established connections (connections you request) are allowed.</p>
<p class="code">sudo ufw default deny</p>
<p>Since we are not running a server, nothing further is required for incoming connections.</p>
<h2>Deny outgoing connections</h2>
<p>This is a bit harder as you need to know the services you wish to allow and write rules for outbound traffic you wish to allow. Common services you may wish to allow (and their ports) include:</p>
<p>Basic services:<br />
DNS (Domain Name Service) = protocol udp port 53.<br />
Web browsing = http protocol tcp port 80.<br />
Secure web browsing = https protocol tcp port 443.<br />
Mail = protocol tcp port 25.<br />
FTP = protocol tcp port 20 and 21.<br />
SSH = protocol tcp port 22.<br />
VNC = protocol tcp port 5900.<br />
Samba uses multiple ports , protocol udp ports 137 and 138 as well as tcp ports 139, and 445.<br />
IRC protocol tcp , Ubuntu Servers defaults to 8001.</p>
<p>A listing of ports can be found <a href="http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers">here</a>.</p>
<p>UFW will block outbound traffic based on the destination port on the server. To allow the outbound traffic listed above use:</p>
<p class="code">sudo ufw allow out 53,137,138/udp<br />
sudo ufw allow out 20,21,22,25,80,139,443,5900,8001/tcp</p>
<p>Then block all other outbound traffic with:</p>
<p class="code">sudo ufw deny out to any</p>
<p>Keep in mind, order of the rules is critical. So if you need to allow additional traffic, you will need to insert a rule.</p>
<p>List your rules by number with:</p>
<p class="code">sudo ufw status numbered</p>
<p>If you used the above syntax you will see :<br />
<code><br />
Status: active<br />
<br />     To                         Action      From<br />
     --                         ------      ----<br />
[ 1] 53,137,138/udp             ALLOW OUT   Anywhere (out)<br />
[ 2] 20,21,22,25,80,139,443,5900,8001/tcp ALLOW OUT   Anywhere (out)<br />
[ 3] Anywhere                   DENY OUT    Anywhere (out)</code></p>
<p>Say we wish to allow out telnet on port 23. We will need to add this before the third rule (which denies all outbound traffic). We do this using insert.</p>
<p class="code">ufw insert 3 allow out 23</p>
<h2>Peer-to-peer (torrents)</h2>
<p>Peer-to-peer file sharing via torrents are popular and allowing torrent traffic is a bit complicated. The major reason for this is that IP providers often block common torrent ports, so it is almost impossible to know what ports will be used for the torrent transfer and it may be easier to disable your firewall if you use torrents.</p>
<p>The somewhat more complicated approach is to determine the inbound port for your torrent client, and allow inbound traffic on that port.</p>
<p>Using the &#8220;default&#8221; torrent ports as an example (bittorrent uses ports 6881-6999), the easiest settings for torrent sharing are to allow these ports in and allow all outbound traffic. Check your torrent application for the inbound port or ports (Transmission, the default client in Ubuntu, uses port 51413 for example).</p>
<p class="code">#This first rule allow ports 6881-6999 inclusive<br />
sudo ufw allow 6881:6999/tcp<br />
<br /># Allow all outbound traffic if we blocked it previously<br />
sudo ufw delete deny out to any</p>
<h2>Deleting rules</h2>
<p>If you need to delete a rule, simply use &#8220;delete&#8221;, for example:</p>
<p class="code">sudo ufw delete deny out to all</p>
<h2>Additional information</h2>
<p><a href="https://help.ubuntu.com/community/Uncomplicated_Firewall_ufw">Ubuntu Wiki UFW</a><br />
<a href="https://help.ubuntu.com/community/Gufw">Ubuntu Wiki GUFW</a><br />
<a href="http://beginlinux.com/blog/2009/10/ubuntu-9-10-ufw-firewall/">Begin linux blog &#8211; ubuntu 9.10 ufw firewall</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bodhizazen.net/linux/firewall-ubuntu-desktops/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Download Ubuntu 9.10 OpenVZ Templates</title>
		<link>http://blog.bodhizazen.net/linux/download-ubuntu-9-10-openvz-templates/</link>
		<comments>http://blog.bodhizazen.net/linux/download-ubuntu-9-10-openvz-templates/#comments</comments>
		<pubDate>Fri, 13 Nov 2009 17:47:51 +0000</pubDate>
		<dc:creator>bodhi.zazen</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[OpenVZ]]></category>

		<guid isPermaLink="false">http://blog.bodhizazen.net/?p=752</guid>
		<description><![CDATA[Bodhi's Ubuntu OpenVZ Templates available fo rdownload.]]></description>
			<content:encoded><![CDATA[<p>As many of you know, I am a big fan of <a href="http://wiki.openvz.org/Main_Page">Openvz</a> and I have helped several learn to use OpenVZ. Although you certainly may wish to make your own Ubuntu Templates, several people have asked me if I have any.</p>
<p>So, I am making my templates available for download =)</p>
<p>I updated a set of Ubuntu 9.10 OpenVZ Templates and have made them available for download.</p>
<p>The templates are named such that they are compatible with <a href="http://pve.proxmox.com/wiki/Main_Page">Proxmox</a> (these templates will show up in the Proxmox menu).</p>
<p>These templates work out of the box and are up to date as of November 12, 2009. The only thing that is &#8220;missing&#8221; would be an openssh-server (I remove openssh-server from my VPS). Openssh server can be installed with apt-get if you wish.</p>
<p class="code">apt-get install ssh</p>
<p>The templates have been generated according to <a href="http://blog.bodhizazen.net/linux/openvz-ubuntu-templates/">this how to</a> and include <a href="http://blog.bodhizazen.net/linux/openvz-ubuntu-9-10-templates/">this init script</a> (which is modified from the script provieded by Stephane Graber).</p>
<p>If you want only the init script, it can be downloaded from <a href="http://bodhizazen.net/openvz.conf">here</a>. Simply save that file in /etc/init/ as /etc/init/openvz.conf</p>
<p>i386 : 32 bit VPS<br />
<a href="http://bodhizazen.fivebean.net/ubuntu-9.10-minimal_9.10_i386.tar.gz">ubuntu-9.10-minimal_9.10_i386.tar.gz</a><br />
<a href="http://bodhizazen.fivebean.net/ubuntu-9.10-minimal_9.10_i386.tar.gz.md5">ubuntu-9.10-minimal_9.10_i386.tar.gz md5sum</a></p>
<p>amd64 : 64 bit VPS<br />
<a href="http://bodhizazen.fivebean.net/ubuntu-9.10-minimal_9.10_amd64.tar.gz">ubuntu-9.10-minimal_9.10_amd64.tar.gz</a><br />
<a href="http://bodhizazen.fivebean.net/ubuntu-9.10-minimal_9.10_amd64.tar.gz.md5">ubuntu-9.10-minimal_9.10_amd64.tar.gz md5sum</a></p>
<p>To use these templates, save them in /vz/templates/cache (I always link /var/lib/vz to /vz on Debian / Ubuntu Openvz host nodes).</p>
<p class="code">sudo ln -s /var/lib/vz /vz</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bodhizazen.net/linux/download-ubuntu-9-10-openvz-templates/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.331 seconds -->
