<?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>EECS from the Trenches &#187; networking samba iptables dhcp ubuntu server</title>
	<atom:link href="http://blog.njoubert.com/category/networking-samba-iptables-dhcp-ubuntu-server/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.njoubert.com</link>
	<description>Niels Joubert&#039;s Portfolio and Blog</description>
	<lastBuildDate>Thu, 15 Sep 2011 20:21:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Wiring the apartment &#8211; setting up DHCP and Routing on Ubuntu</title>
		<link>http://blog.njoubert.com/2008/02/wiring-the-apartment-setting-up-dhcp-and-routing-on-ubuntu.html</link>
		<comments>http://blog.njoubert.com/2008/02/wiring-the-apartment-setting-up-dhcp-and-routing-on-ubuntu.html#comments</comments>
		<pubDate>Sat, 16 Feb 2008 05:43:00 +0000</pubDate>
		<dc:creator>njoubert</dc:creator>
				<category><![CDATA[networking samba iptables dhcp ubuntu server]]></category>

		<guid isPermaLink="false">http://njoubert.com/blog/2008/02/wiring-the-apartment-setting-up-dhcp-and-routing-on-ubuntu.html</guid>
		<description><![CDATA[I have a confession to make. I live with 11 engineers. In two connected apartments. And when we moved it, there was no wiring in the house&#8230; Only a telephone jack in each room. And now, we all have ethernet drops and multiple wifi access points through the area. I do hope our landlord sees [...]]]></description>
			<content:encoded><![CDATA[<p>I have a confession to make. I live with 11 engineers. In two connected apartments. And when we moved it, there was no wiring in the house&#8230; Only a telephone jack in each room. And now, we all have ethernet drops and multiple wifi access points through the area. I do hope our landlord sees this as a significant improvement!</p>
<p>In the process I bumped up my networking skill quite significantly. The network layout looks something like this:</p>
<p><code>[Border Router]<br />
| |<br />
[Switches for Subnet 0]<br />
| |<br />
{eth0}[Server]{eth1}<br />
| |<br />
[Switches for Subnet 1]<br />
| |<br />
[Border Router]</code></p>
<p>Each switch is connected to about 8 desktops and two wireless access points, forming their own network. The idea is that each apartment (thus each subnet) has its own internet access point, but the fileserver is accessible from both apartments, and also routes between the two apartments so that it appears that they are both on the same network to things like SMB and the like.</p>
<p>I use DHCP on the server itself to set the correct information on all the hosts. Here is my dhcpd.conf file:</p>
<p><code># Custom DHCP3 server for the EECS House<br />
# Niels Joubert njoubert@gmail.com</code></p>
<p><code>### Add classless-static-routes option:<br />
option classless-static-routes code 121 = array of { ip-address, ip-address };<br />
option new-static-routes code 249 = string;<br />
###</p>
<p>lease-file-name "/var/lib/dhcp3/dhcpd.leases";</p>
<p>default-lease-time 86400;<br />
max-lease-time 604800;</p>
<p>authoritative;</p>
<p>subnet 192.168.0.0 netmask 255.255.255.0 {<br />
option ip-forwarding off;</p>
<p>range 192.168.0.100 192.168.0.200;<br />
option subnet-mask 255.255.255.0;<br />
option broadcast-address 192.168.0.255;</p>
<p>#option domain-name "";<br />
option domain-name-servers 192.168.1.1, 68.87.76.178, 68.87.78.130;</p>
<p>option netbios-name-servers 192.168.0.10;<br />
option netbios-node-type 8;<br />
option routers 192.168.0.10;</p>
<p>#This is to get the machines on the two subnets to talk:<br />
option new-static-routes 18:c0:a8:01:c0:a8:00:0a;</p>
<p>}</p>
<p>subnet 192.168.1.0 netmask 255.255.255.0 {<br />
option ip-forwarding off;</p>
<p>range 192.168.1.100 192.168.1.200;<br />
option subnet-mask 255.255.255.0;<br />
option broadcast-address 192.168.1.255;</p>
<p>#option domain-name "";<br />
option domain-name-servers 192.168.1.1, 68.87.76.178, 68.87.78.130;</p>
<p>option netbios-name-servers 192.168.1.10;<br />
option netbios-node-type 8;<br />
option routers 192.168.1.1;</p>
<p>#This is to get the machines on the two subnets to talk:<br />
option new-static-routes 18:c0:a8:00:c0:a8:01:0a;<br />
</code></p>
<p><code>}</code></p>
<p>There is a couple of hacks in here:<br />
- to get machines from the one subnet to see the other subnet, i use the classless-static-routes DHCP option, that puts an entry into any host that gets a DHCP offer from this box. Unfortunately this only works for windows hosts! This is a huge caveat that I have not been able to solve.<br />
For SMB use, I set the server itself as the netbios name server (more on this later). For each subnet, I set the default route as its border router. With this setup it is enough that each subnet has internet and should be able to talk to the other subnet through the server.</p>
<p><span style="font-weight: bold;">IPTABLES</span></p>
<p>To forward anything through the server itself, I use a custom iptables setup that resides in a script that gets automatically run, as follows:</p>
<p><code># NIELS JOUBERT<br />
# Custom iptables script</code></p>
<p><code># Clean up iptables (flush it)<br />
iptables -F<br />
iptables -t nat -F<br />
iptables -X</p>
<p># Enable IP MASQUERADING/NAT<br />
iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE<br />
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE<br />
</code></p>
<p><code># Set firewall policies (default behaviour)<br />
iptables -P FORWARD ACCEPT<br />
iptables -P OUTPUT ACCEPT</code></p>
<p>The idea here is to set up a nat table to masquerade ips, and the forwarding table to accept all forwarding. Simple, straight-forward and general. Possibly not the best security, but we are self-contained within the border routers right now, so if one of my roommates wants to be an ass and attack someone else, its easy enough to go hit him physically, right?</p>
<p><span style="font-weight: bold;">SAMBA</span></p>
<p>Samba itself also needs to be configured. Now, Samba is HUGE, as are its config files. I recommend a good book on Samba if you are going to do anything more than the most basic sharing with it. I personally prefer &#8220;The Official Samba-3 HOWTO and Reference Guide&#8221;.</p>
<p>The gist of my smb.conf setup looks like this:</p>
<p><code>[global]<br />
workgroup = workgroup<br />
netbios name = ubuntu<br />
server string = Niels Server<br />
dns proxy = no<br />
name resolve order = lmhosts wins host bcast<br />
smb ports = 139 240<br />
# This tells Samba to use a separate log file for each machine<br />
log file = /var/log/samba/log.%m<br />
max log size = 1000<br />
syslog = 0</code></p>
<p><code>####### WINS Services ######<br />
wins support = yes</p>
<p># Forces us to be the local master browser for WINS<br />
local master = yes<br />
preferred master = yes<br />
os level = 34<br />
domain master = yes</p>
<p># Cache TTL<br />
max ttl = 86400<br />
max wins ttl = 86400<br />
</code></p>
<p>The important thing to note is that samba works on all interfaces and is the local wins browser (netbios name server).</p>
<p>This is the setup! It works fairly well too.</p>
<p><span style="font-weight: bold;">Reliability through two interfaces!</span></p>
<p>The one apartment&#8217;s internet died today because we&#8217;re in the middle of switching from ComCast (ewww) to DSLExtreme (YAY!). I remedied 7 very angry internet-less engineers by a very simple change in routing.</p>
<p>1) Change the subnet without border router to use the server as border router<br />
2) Change the server to use as default route the border router of the other subnet</p>
<p>This took about 5 minutes, and we were piping the internet through the other apartment into our without a hiccup. Hooray for networking!</p>
<p>Feel free to ask me about my setup or use my config files.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.njoubert.com/2008/02/wiring-the-apartment-setting-up-dhcp-and-routing-on-ubuntu.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

