Setting up my home router: PART 1

I have a d-link router that works fine and with which I can use Internet. I have 3 laptops and 1 PlayStation 3 connected through wireless and I have 1 server that is connected through LAN. Everything is working fine but I'm unhappy: What's the purpose of a server if all the routing, dhcp'ing, and dns'ing is done by a router automatically? Plus, if I have my own box working as a wireless router, I'll be able to block some Ad server with DNS so I'll end up saving a bit of bandwith. So how do I get this working? Let's start with some specs of my computer which will run as my server with interfaces name on the ethernet adapters:

  • Debian Etch fully upgraded
  • Pentium 4 1.5Ghz
  • 256 RAM (Oh yeah... ONLY 256... motherboard doesn't support my other Ram chips)
  • 1 Accton Technology Corporation EN-1216 Ethernet Adapter [eth1]
  • 1 D-Link System Inc RTL8139 Ethernet [eth0]
  • 1 Atheros Communications, Inc. AR5212 802.11abg NIC (it's a D-Link) [wlan0]

Ok so now let's get down to work. First we need to decide which one of the two ethernet card I'll use for the WAN input. I gotta say this was more complicated than I expected: my accton ethernet card was unable to work as a routing device. I can't remember how I figured this out, but I did.. so WAN is eth1 and LAN is eth0 in order to solves this issue. wlan0 will be my wireless NIC to allow wifi connection to the router. So we need to create a bridge between wlan0 and eth0:

vim /etc/network/interface:

# Automatic load of the following interfaces
auto lo
# The loopback network interface
iface lo inet loopback

# The Gateway.
auto eth1
iface eth1 inet dhcp

# The LAN
allow-hotplug eth0
iface eth0 inet static
address 0.0.0.0
netmask 255.255.255.0

# The WLAN
auto wlan0
iface wlan0 inet static
# This creates wlan0 on the wifi0 interface (this is how it works with atheros' chipset) with mode master
pre-up wlanconfig wlan0 destroy
pre-up wlanconfig wlan0 create wlandev wifi0 wlanmode ap
# pre-up ifconfig wlan0 up
# iwconfig wlan0 essid "netroot" mode Master
address 0.0.0.0
netmask 255.255.255.0
# Delete the wlan0 interface on ifdown
post-down wlanconfig wlan0 destroy

# Bridge initialization
auto br0
iface br0 inet static
bridge_ports eth0 wlan0
pre-up sleep 3Now here I don't know why, but I could not reboot my computer and have my networking working. When it would reboot, I would have my wlan0 coming up but the "wlanconfig" would not be set properly. "iwconfig wlan0" would show me that wlan0 is in Managed mode instead of the desired mode (Master).

Anyway, once the networking service is working, it's time to encrypt the wireless to a WPA2 protocol. I'll be using hostapd for this.

/etc/hostapd/hostapd.conf:interface=wlan0
bridge=br0
driver=madwifi
logger_syslog=-1
logger_syslog_level=2
logger_stdout=-1
logger_stdout_level=2
debug=0
dump_file=/tmp/hostapd.dump
ctrl_interface=/var/run/hostapd
ctrl_interface_group=0
ssid=netroot
max_num_sta=255
auth_algs=3
wme_enabled=1
wme_ac_bk_cwmin=4
wme_ac_bk_cwmax=10
wme_ac_bk_aifs=7
wme_ac_bk_txop_limit=0
wme_ac_bk_acm=0
wme_ac_be_aifs=3
wme_ac_be_cwmin=4
wme_ac_be_cwmax=10
wme_ac_be_txop_limit=0
wme_ac_be_acm=0
wme_ac_vi_aifs=2
wme_ac_vi_cwmin=3
wme_ac_vi_cwmax=4
wme_ac_vi_txop_limit=94
wme_ac_vi_acm=0
wme_ac_vo_aifs=2
wme_ac_vo_cwmin=2
wme_ac_vo_cwmax=3
wme_ac_vo_txop_limit=47
wme_ac_vo_acm=0
eapol_key_index_workaround=0
eap_server=0
wpa=3
wpa_psk_file=/etc/hostapd/wpa_psk
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP TKIP
wpa_group_rekey=600
wpa_gmk_rekey=86400
Let's "/etc/init.d/hostapd restart".
"iwconfig wlan0" should show up with the encryption key.

Once this is working, your other computer should be able to see the network and access it with static IP. Now we want to add some dhcp feature to this server.

Dhcp3-server gonna be our man for this job. Once install, configure dhcpd.conf with the following rules:
server-identifier jupiter;
allow client-updates;
ddns-update-style interim;
option domain-name "mynetwork.local";
option domain-name-servers 192.168.0.1, 24.200.241.37;
option routers 192.168.0.1;
default-lease-time 600;
max-lease-time 7200;
authoritative;
log-facility local7;
include "/etc/bind/rndc.key";
#Use proper key in the right zone
zone mynetwork.local. {
primary 127.0.0.1;
key "rndc-key";
}
#Configuring the actual subnet
subnet 192.168.0.0 netmask 255.255.255.0 {
range 192.168.0.10 192.168.0.75;
zone 0.168.192.in-addr.arpa. {
primary 192.168.0.1; <----- Put you're primary DNS key "rndc-key"; } zone mynetwork.local. { primary 192.168.0.1; <------ Primary DNS of your provider if you don't have one key "rndc-key"; } } Alright, now we should be able to connect to our network with any type of computer. Enjoy.