Morphex's blogologue (Life, technology, music, politics, business, mental health and more)

This is the blog of Morten W. Petersen, aka. morphex in various places. I blog about my life, and what I find interesting and/or important. This is a personal blog without any editor or a lot of oversight so treat it as such. :)

My email is morphex@gmail.com.

An OGG/Vorbis player, implemented in Javascript.

My Kiva bragging page
My shared (open source) code on GitHub

Morphex's Blogodex

News
Slashdot

Zope hosting by Nidelven IT

Morten Petersen on Linkedin

Morten Petersen on Facebook

Morten Petersen on SoundCloud

Morten Petersen on MixCloud

Blogologue on Twitter



Older entries



Atom - Subscribe - Categories

Facebook icon Share on Facebook Google+ icon Share on Google+ Twitter icon Share on Twitter LinkedIn icon Share on LinkedIn

Raspberry Pi as a WiFi uplink point for cable switch

So.. to keep myself entertained and work a bit with technical things I haven't worked a lot with earlier, I dug out the old Raspberry Pi and figured I could use it as an uplink for a switch I recently bought.

So basically I have

  The internet -> Apartment router -> My WiFi Router -> Raspberry Pi with Wifi -> Switch -> Computer x,y,z

This enables me to setup computers with internet, by just plugging them into the switch with an Ethernet cable. The ISC DHCP server is running on the Raspberry Pi, and deals out the necessary bits to each computer so that it gets internet access.

You can see the switch as well as the Pi on the following picture:

Raspberry Pi and ethernet switch with LED lights

Now I thought the whole thing was a bit daunting and didn't know where to start, but some recipes on the net made things fairly easy, and I do know a bit about networking etc. from earlier on.

Now, the Raspberry Pi has a DHCP server running, which deals out IP addresses, gateway etc. to each computer that connects to the switch.

The DHCP server is configured basically like this and listens on the Raspberry Ethernet port, eth0:

option domain-name "blogologue.com";
option domain-name-servers 8.8.8.8;

default-lease-time 600;
max-lease-time 7200;

ddns-update-style none;

subnet 192.168.2.0 netmask 255.255.255.0 {
        range 192.168.2.2 192.168.2.254;
        option routers 192.168.2.1;
}

But the Pi also has to know how to send data to and from the computers that are hooked up to the switch, and here's a script that sets that up:

#!/bin/bash
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
iptables -A FORWARD -i wlan0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i eth0 -o wlan0 -j ACCEPT

Using those two bits, and using the built-in WiFi configuration in raspi-config, I setup a network for easy internet access in a couple of hours.


[Permalink] [By morphex] [Technology (Atom feed)] [27 Dec 00:26 Europe/Oslo]