How To: Set Up Slackware Linux as a PC Router
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.
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 220.127.116.11 and 18.104.22.168
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: 22.214.171.124/29 (assigned in eth0 of the PC router) with 126.96.36.199 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 [video].
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="188.8.131.52" NETMASK="255.255.255.248" USE_DHCP="" DHCP_HOSTNAME="" # Config information for eth1: IPADDR="192.168.10.1" NETMASK="255.255.255.0" USE_DHCP="" DHCP_HOSTNAME="" # Default gateway IP address: GATEWAY="184.108.40.206"
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.