Old PC to New Router with Gentoo Linux

Don’t throw that old PC away just yet, it still has some life in it yet. No matter how bad your old PC is it can always be used as a router, and your old router as a switch. All you need is two nic cards for it. Originally I did this on a Pentium 3 with 256 MBs of memory. I had that setup for around 6 months before the computer finally died. Never quite figured it out but it was either the processor or the mother board. But anyways on with the show. I will be setting this up on an AMD 3200 XP processor with one gigabyte of memory, an nForce 2 chipset and 450 gigs of hard drive space. The Linux distribution I’m using is going to be Gentoo Linux. Assuming you’ve already got the system setup and running correctly we will start with kernel configuration. Don’t freak out it’s not that hard to do.

cd /usr/src/linux
make menuconfig

You should be at a screen with a few options. Navigate the screen as follows:

Networking --> Network options -->
	[*] TCP/IP networking
		<*> IP: advanced router
Scroll down about to
	[*] Network packet filtering (replaces ipchains)
Star it hit enter and go to
		IP: Netfilter Configuration
	[*] Connection tracking (required for masq/NAT)
		<*>   FTP protocol support
		<*>   IRC protocol support
	[*] IP tables support (required for filtering/masq/NAT)
		<*> IP range match support
		<*> Packet filtering
	[*] Full NAT
		<*> MASQUERADE target support
	[s] Packet mangling
Networking Network options
	QoS and/or fair queueing
	[*] QoS and/or fair queueing
		<*> Hierarchical Token Bucket (HTB)
		<*>   Ingress Qdisc
Device Drivers
Network device support
	[*] PPP (point-to-point protocol) support
		<*> PPP filtering
		<*> PPP support for async serial ports
		<*> PPP support for sync tty ports
		<*> PPP Deflate compression
		<*> PPP BSD-Compress compression
		<*> PPP over Ethernet

Click exit all the way out until it asks you to save. Click yes to save and in terminal type:

make && make modules_install

Yup you’re officially compiling the kernel. Get some food or something because depending on your system it might take a while :). When that is done compiling, copy the binary to /boot with:

cp arch/i386/boot/bzImage /boot/kernel-2.6.17-gentoo-r5

Obviously you’ll need to use the name of your old kernel, as that might not be the name of yours. Now from here the steps are different depending on how you connect to the internet. I use cable so I don’t have to worry about PPPoE. I’ll go over a cable setup first. If you don’t have it already you will need dhcpcd.

emerge dhcpcd

Then you’ll need to make another interface for your second nic by using a symbolic link, and make them all start on boot.

ln -s net.lo /etc/init.d/net.eth1
rc-update add net.eth1 default
rc-update add net.eth0 default

If you’re using DSL/PPPoE you’ll need to do this: (Straight from gentoo handbook)

# nano /etc/ppp/pap-secrets
# client server secret
“vla9h924” * “password”
# nano /etc/conf.d/net
Tell baselayout to use adsl for your eth1:
config_eth1=( “adsl” )
user_eth1=( “vla9h924” )
(Replace ‘vla9h924’ with your username and ‘password’ with your password)

Next you’ll need to configure your LAN and WAN interface. I used eth1 as WAN and eth0 as LAN. To do this we need to configure /etc/conf.d/net

For a dynamic or even semi static (Comcast users):
config_eth1=( “dhcp” )
Static IP: (From gentoo manual never used a static IP)
config_eth1=( “66.92.78.102 broadcast 66.92.78.255 netmask 255.255.255.0” )
routes_eth1=( “default gw 66.92.78.1” )
And finally both users must add:
config_eth0=( “192.168.1.1 broadcast 192.168.1.255 netmask 255.255.255.0” )

Almost done, all we need is a firewall to protect us since we are wide open on the internet, and some NAT rules to forward traffic.

cd /etc/init.d/
wget https://cyber-knowledge.net/blog/extras/firewall
wget https://cyber-knowledge.net/blog/extras/natrouting
chmod 700 natrouting
chmod 700 firewall
rc-update add firewall default
rc-update add natrouting default

Double check those scripts to make sure everything is correct for your LAN/WAN in there. Hook up the cables so that the one coming from your modem is in the WAN port, and the one from your LAN port is going into the LAN port of a switch or your old router. Usually the WAN port on a switch is separated from the rest. If you plug more LAN cables in to that switch, all computers will have internet. If you’re using your old router make sure you change your old routers IP to 192.168.1.2 or something before using it as a switch. Reboot your computer and everything should start fine. The WAN interface should have gotten an external IP while the LAN should have gotten 192.168.1.1. If not, restart your modem by unplugging it and plugging it back in. Then restart the WAN interface by doing:

/etc/init.d/net.eth1 restart

Hopefully it worked that time. Keep in mind all PCs you hook up to the network will now have to be configured to use a static IP address. For more information on that see the Microsoft website. Some hints while doing it. The IP can be 192.168.1.100 through .255. The default gateway is 192.168.1.1. Your subnet mask should fill in automatically. The name server can be found in /etc/resolv.conf of your router or you can use 4.2.2.1. With all luck you have internet and a much faster router :D. Have fun, and comment if this worked for you or you had any issues.