How To: Set Up Slackware Linux as a PC Router

26 April 2012 by ComputechTips
Categories: System | Tags: | Leave a comment

This article tries to show you how to set up Slackware Linux running as a PC router. The Slackware will do IP forwarding and network address translation (NAT) so any workstations inside the LAN (local area network) will be able to connect to internet.

Requirements

This tutorial requires you to have the following items:
– a personal computer with two ethernet cards installed and DVD drive.
– a Slackware 13.37 DVD installation disc
– a layer 2 switch
– one or more laptop or computer inside the LAN
– DNS servers. You can use your provider’s DNS servers or simply use Google Public DNS servers with the IP address 8.8.8.8 and 8.8.4.4

To make it easier to understand, see the network diagram below!

According to the diagram above, we will use the following configuration:
– LAN IP address: 192.168.10.0/24 with 192.168.10.1 (assigned in eth1 of the PC router) as the gateway
– WAN IP address: 123.123.134.134/29 (assigned in eth0 of the PC router) with 123.123.134.129 as the gateway
– Two workstations with the IP address 192.168.10.2 and 192.168.10.3

Let’s go to the set up

1. First you need to install the PC with Slackware Linux. Follow my previous article on how to install Slackware in a computer .

2. Login to the Slackware Linux using root or super user!

– open and edit the /etc/rc.d/rc.inet1.conf file to configure the IP address and gateway as follows:

# Config information for eth0:
IPADDR[0]="123.123.134.134"
NETMASK[0]="255.255.255.248"
USE_DHCP[0]=""
DHCP_HOSTNAME[0]=""

# Config information for eth1:
IPADDR[1]="192.168.10.1"
NETMASK[1]="255.255.255.0"
USE_DHCP[1]=""
DHCP_HOSTNAME[1]=""

# Default gateway IP address:
GATEWAY="123.123.134.129"

Save the configuration file.

3. Activate the IP forwarding.

You can use ‘pkgtool’ script to permanently activate the IP forwarding as follows

– Run ‘pkgtool‘ from command line
– Go to ‘Setup‘ (Choose Slackware installations script to run again) option
– Select the ‘services‘ (Select/deselect system daemons (services)). Use spacebar keyboard to select/deselect the setup scripts to run. Then press OK.
– Now search and select the ‘rc.ip_forward‘ service to activate IP packet forwarding. Then press OK and Exit.

You can also instantly activate the ip forwarding by issuing the following command:

# echo 1 > /proc/sys/net/ipv4/ip_forward

However once the PC restarted, the ip_forward value will be back to 0.

4. Enable the NAT (network address translation) with MASQUERADE target in the POSTROUTING chain.

This will translate the private IP address to use the public IP address assigned in the eth0 interface. Use the following command:

# iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

Save the iptables configuration using ‘iptables-save > [filename]’. For example, we will save the iptables configuration in the /root folder with the filename of ‘iptables.conf’

# iptables-save > /root/iptables.conf

So to run the iptables configuration at boot time, you need to add the following line in the /etc/rc.d/rc.local file

# echo "iptables-restore < /root/iptables.conf" >> /etc/rc.d/rc.local

Now the Slackware PC is completely configured to run as a router. Restart the PC.

You need to configure the workstations with the IP address and DNS servers as described above. The workstations inside the LAN should now be able to browse to the internet.

About ComputechTips

Computer and tech-related tips including how-tos, tutorials, and guides. Follow me at @computechtips

«

»