<?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>ejohansson.se &#187; network</title>
	<atom:link href="http://ejohansson.se/categories/computers/network/feed/" rel="self" type="application/rss+xml" />
	<link>http://ejohansson.se</link>
	<description>Random bits about Linux, programming, computers and occasionally other stuff.</description>
	<lastBuildDate>Tue, 06 Mar 2012 09:02:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Transparent HTTP proxy in&#160;python</title>
		<link>http://ejohansson.se/archives/2012/03/06/transparent-http-proxy-in-python/</link>
		<comments>http://ejohansson.se/archives/2012/03/06/transparent-http-proxy-in-python/#comments</comments>
		<pubDate>Tue, 06 Mar 2012 09:02:05 +0000</pubDate>
		<dc:creator>Erik Johansson</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://ejohansson.se/?p=460</guid>
		<description><![CDATA[I recently wanted to modify a web resource that a device on my local network loads when starting. To avoid having a static local modified copy of the resource I wrote a simple transparent HTTP proxy in python using the Twisted networking engine (which btw was a joy to use) which does the modification when [...]]]></description>
			<content:encoded><![CDATA[<p>I recently wanted to modify a web resource that a device on my local network loads when starting. To avoid having a static local modified copy of the resource I wrote a simple transparent HTTP proxy in python using the <a href="http://twistedmatrix.com/">Twisted networking engine</a> (which btw was a joy to use) which does the modification when the resource is loaded. The code is not modular (e.g. the resource modification is hard coded in the processResponse() function) and the logging is very verbose, but if anyone is interested the code is available on github: <a href="https://github.com/erijo/transparent-proxy">transparent-proxy.git</a>.</p>
<p>The proxy is now running on my local server which sits behind the real gateway. Besides making the device use the server as gateway and enable NAT on the server this single iptables rule is all that is needed:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">iptables <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-A</span> PREROUTING <span style="color: #660033;">-s</span> <span style="color: #007800;">$CLIENT_IP</span> <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">80</span> <span style="color: #660033;">-j</span> REDIRECT <span style="color: #660033;">--to-port</span> <span style="color: #000000;">8080</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://ejohansson.se/archives/2012/03/06/transparent-http-proxy-in-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SFTP only access to&#160;server</title>
		<link>http://ejohansson.se/archives/2011/11/29/sftp-only-access-to-server/</link>
		<comments>http://ejohansson.se/archives/2011/11/29/sftp-only-access-to-server/#comments</comments>
		<pubDate>Tue, 29 Nov 2011 10:17:16 +0000</pubDate>
		<dc:creator>Erik Johansson</dc:creator>
				<category><![CDATA[debian]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[config]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://ejohansson.se/?p=370</guid>
		<description><![CDATA[I recently installed a NAS server in my home and wanted to give my family and relatives access to it so that they could use it as a remote backup server for photos and stuff. To keep it as secure as possible I only wanted to give them SFTP access. (All commands below are executed [...]]]></description>
			<content:encoded><![CDATA[<p>I recently installed a NAS server in my home and wanted to give my family and relatives access to it so that they could use it as a remote backup server for photos and stuff. To keep it as secure as possible I only wanted to give them SFTP access.</p>
<p>(All commands below are executed as root.)</p>
<p>First I created a group to group them together and then added the users to that group. I choose to disable their password as I only allow logins using SSH keys.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">addgroup sftponly
<span style="color: #666666; font-style: italic;"># Repeat the line below for each user</span>
adduser <span style="color: #660033;">--disabled-password</span> <span style="color: #660033;">--ingroup</span> sftponly ausername</pre></div></div>

<p>As for the upload directory I wanted them to upload their data to my raid1 volume mounted under /data/pool1. Since OpenSSH has some requirements for the permission on the directories used as chroot I created the following directory layout.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>data<span style="color: #000000; font-weight: bold;">/</span>pool1
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-m</span> <span style="color: #000000;">751</span> sftp
<span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> . sftp<span style="color: #000000; font-weight: bold;">/</span>home
<span style="color: #666666; font-style: italic;"># Repeat the lines below for each user</span>
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-m</span> <span style="color: #000000;">700</span> sftp<span style="color: #000000; font-weight: bold;">/</span>ausername
<span style="color: #c20cb9; font-weight: bold;">chmod</span> ausername.root sftp<span style="color: #000000; font-weight: bold;">/</span>ausername</pre></div></div>

<p>The home symlink is there to make the initial SFTP directory /ausername and the sftp directory is created with 751 to disallow directory listing in the top directory.</p>
<p>Then, as &#8220;all components of the pathname must be root-owned directories that are not writable by any other user or group&#8221; and /data/pool1 is not root owned I created a bind mount by adding the following to /etc/fstab.</p>

<div class="wp_syntax"><div class="code"><pre class="div" style="font-family:monospace;"><span style="color: #44aa44;">/</span>data<span style="color: #44aa44;">/</span>pool1<span style="color: #44aa44;">/</span>sftp  <span style="color: #44aa44;">/</span>srv<span style="color: #44aa44;">/</span>sftp  bind  bind  <span style="color: #cc66cc;">0</span>  <span style="color: #cc66cc;">0</span></pre></div></div>

<p>Before the initial mount, the directory must be created.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>srv<span style="color: #000000; font-weight: bold;">/</span>sftp
<span style="color: #c20cb9; font-weight: bold;">mount</span> <span style="color: #000000; font-weight: bold;">/</span>srv<span style="color: #000000; font-weight: bold;">/</span>sftp</pre></div></div>

<p>Then, the final part was to configure OpenSSH by adding the following lines at the end of /etc/ssh/sshd_config.</p>

<div class="wp_syntax"><div class="code"><pre class="div" style="font-family:monospace;">Match Group sftponly
  ChrootDirectory <span style="color: #44aa44;">/</span>srv<span style="color: #44aa44;">/</span>sftp
  ForceCommand internal<span style="color: #44aa44;">-</span>sftp
  AllowTcpForwarding no
  X11Forwarding no</pre></div></div>

<p>Remember to restart the server afterwards.</p>
]]></content:encoded>
			<wfw:commentRss>http://ejohansson.se/archives/2011/11/29/sftp-only-access-to-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wake on LAN with&#160;Debian</title>
		<link>http://ejohansson.se/archives/2009/12/31/wake-on-lan-with-debian/</link>
		<comments>http://ejohansson.se/archives/2009/12/31/wake-on-lan-with-debian/#comments</comments>
		<pubDate>Thu, 31 Dec 2009 13:45:20 +0000</pubDate>
		<dc:creator>Erik Johansson</dc:creator>
				<category><![CDATA[debian]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[config]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://ejohansson.se/?p=309</guid>
		<description><![CDATA[To enable Wake on LAN on a Asus P5E-V motherboard under Debian you can do the following. Since I have a Asus motherboard, that&#8217;s the only one I&#8217;ve tested, but except from the BIOS (which may differ a bit), the instructions should be the same for all motherboards/NIC that supports Wake on LAN. In the [...]]]></description>
			<content:encoded><![CDATA[<p>To enable <a href="http://en.wikipedia.org/wiki/Wake-on-LAN">Wake on LAN</a> on a Asus P5E-V motherboard under Debian you can do the following. Since I have a Asus motherboard, that&#8217;s the only one I&#8217;ve tested, but except from the BIOS (which may differ a bit), the instructions should be the same for all motherboards/NIC that supports Wake on LAN.</p>
<p>In the BIOS, enable &#8220;Power on by PCIE device&#8221;.</p>
<p>In Linux, first install ethtool and then check that Wake on LAN is supported by running the following command:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">root<span style="color: #000000; font-weight: bold;">@</span>host$ ethtool eth0
...
        Supports Wake-on: g
        Wake-on: g
...</pre></div></div>

<p>The output should contain a &#8216;g&#8217; to indicate that the device can be woken by sending it a &#8220;magic packet&#8221;.</p>
<p>Enable Wake-on by running:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">root<span style="color: #000000; font-weight: bold;">@</span>host$ ethtool <span style="color: #660033;">-s</span> eth0 wol g</pre></div></div>

<p>Since this command must be run on every boot, add it to /etc/rc.local.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">root<span style="color: #000000; font-weight: bold;">@</span>host$ <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>rc.local
...
ethtool <span style="color: #660033;">-s</span> eth0 wol g
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span></pre></div></div>

<p>As the last step we must make sure that halt doesn&#8217;t disable the network device. This is done by adding this line to /etc/default/halt:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">NETDOWN</span>=no</pre></div></div>

<p>We also need the MAC address to send the magic packet to.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">root<span style="color: #000000; font-weight: bold;">@</span>host$ <span style="color: #c20cb9; font-weight: bold;">ifconfig</span> eth0
eth0      Link encap:Ethernet  HWaddr 00:1e:8c:cf:d0:bb  
...</pre></div></div>

<p>Then shutdown the computer. On an other computer, install e.g. <a href="http://gsd.di.uminho.pt/jpo/software/wakeonlan/">wakeonlan</a> and run:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">user<span style="color: #000000; font-weight: bold;">@</span>other$ wakeonlan 00:1e:8c:cf:d0:bb</pre></div></div>

<p>The computer should now start.</p>
]]></content:encoded>
			<wfw:commentRss>http://ejohansson.se/archives/2009/12/31/wake-on-lan-with-debian/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Wii and Netgear&#160;WNR834B</title>
		<link>http://ejohansson.se/archives/2008/12/20/wii-and-netgear-wnr834b/</link>
		<comments>http://ejohansson.se/archives/2008/12/20/wii-and-netgear-wnr834b/#comments</comments>
		<pubDate>Sat, 20 Dec 2008 17:44:23 +0000</pubDate>
		<dc:creator>Erik Johansson</dc:creator>
				<category><![CDATA[network]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[wii]]></category>

		<guid isPermaLink="false">http://ejohansson.se/?p=276</guid>
		<description><![CDATA[I recently had a lot of problems connecting my Nintendo Wii wireless to my girlfriend&#8217;s Netgear router (WNR834B). The router was configured to use WPA-PSK [TKIP] + WPA2-PSK [AES] with a fairly long pass phrase (ASCII characters). It worked very well with my iBook (Mac OS X) and worked most of the time with my [...]]]></description>
			<content:encoded><![CDATA[<p>I recently had a lot of problems connecting my Nintendo Wii wireless to my girlfriend&#8217;s Netgear router (WNR834B). The router was configured to use WPA-PSK [TKIP] + WPA2-PSK [AES] with a fairly long pass phrase (ASCII characters). It worked very well with my iBook (Mac OS X) and worked most of the time with my girlfriend&#8217;s laptop (Windows Vista). But it seemed like Windows used the WPA variant instead of WPA2. It just didn&#8217;t connect when forcing it to use WPA2. And the Wii would only connect if we turned encryption off. Not acceptable!</p>
<p>We tried many things to get the Wii to connect, without any success. In a last attempt we tried changing the pass phrase to a 64 characters long hexadecimal pass phrase. That did the trick. Both the Wii and both laptops now connect without any problem. So if you are having problems connecting your Wii to the wireless network, try changing the pass phrase to consist of hexadecimal characters (0-9, A-F) only. For WPA/WPA2 it must be exactly 64 characters long.</p>
]]></content:encoded>
			<wfw:commentRss>http://ejohansson.se/archives/2008/12/20/wii-and-netgear-wnr834b/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simulate a slow&#160;network</title>
		<link>http://ejohansson.se/archives/2006/03/24/simulate-a-slow-network/</link>
		<comments>http://ejohansson.se/archives/2006/03/24/simulate-a-slow-network/#comments</comments>
		<pubDate>Fri, 24 Mar 2006 08:47:10 +0000</pubDate>
		<dc:creator>Erik Johansson</dc:creator>
				<category><![CDATA[network]]></category>

		<guid isPermaLink="false">http://ejohansson.se/archives/2006/03/24/simulate-a-slow-network/</guid>
		<description><![CDATA[Kurt Pfeifle has written an interesting article about how to simulate a slow network. I haven&#8217;t been able to test it yet since CONFIG_NET_SCH_NETEM wasn&#8217;t enabled in my kernel config. But as soon as I have recompiled my kernel, I will. More information on netem&#8217;s homepage.]]></description>
			<content:encoded><![CDATA[<p>Kurt Pfeifle has written an interesting article about <a href="http://www.kdedevelopers.org/node/1878">how to simulate a slow network</a>. I haven&#8217;t been able to test it yet since CONFIG_NET_SCH_NETEM wasn&#8217;t enabled in my kernel config. But as soon as I have recompiled my kernel, I will.</p>
<p>More information on <a href="http://linux-net.osdl.org/index.php/Netem">netem&#8217;s homepage</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://ejohansson.se/archives/2006/03/24/simulate-a-slow-network/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

