LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 09-06-2003, 12:02 AM   #1
kleptophobiac
Member
 
Registered: Jun 2003
Distribution: Arch
Posts: 315

Rep: Reputation: 30
Making a slackware 9.0 2.4.22 router


How would I go about doing this? I will be using 2 3Com 3C509B cards and a 3Com 3C905-TX card.

I want to have control over what ports are open to where, and run some simple servers on the box. I've used ipfw under freebsd before, but I sortof don't know what I'm doing now.

Specs:
2.4.22
Slackware 9.0
3C509B - to cable modem
3C509B - to wireless
3C905-TX - to wired lan
Celeron 400
256MB PC133
 
Old 09-06-2003, 01:05 AM   #2
jalal
Member
 
Registered: Aug 2003
Location: .bh
Distribution: Gentoo
Posts: 188

Rep: Reputation: 30
You can start by using IPTables, which is similar to ipfw.

http://www.iptables.org/
 
Old 09-06-2003, 08:42 PM   #3
eric.r.turner
Member
 
Registered: Aug 2003
Location: Planet Earth
Distribution: Linux Mint
Posts: 216

Rep: Reputation: 31
I have exactly what you're looking for already set up!

First you need to make sure the drivers for your cards are either compiled in to your kernel, or loaded at runtime via /etc/rc.d/rc.modules. Try uncommenting the line that says "/sbin/modprobe 3C509" to see if that driver works for your cards.

Next you need to figure out which interfaces are associated with eth0, eth1, and eth2 (or wlan0 if you have a wireless card in the computer.) Then edit /etc/rc.d/rc.inet1 to configure the settings for each of these interfaces. I like to create separate rc scripts (e.g. /etc/rc.d/rc.eth0) for each interface, then call those scripts from /etc/rc.d/rc.inet1. I basically just pull the interface-specific code from rc.inet1 and put it in rc.eth0. Anyway, you need to configure the settings on each interface. My eth1 interface is automatically configured via DHCP by my ISP (including the default gateway) so in /etc/rc.d/rc.eth1 I set USE_DHCP=yes. Here's an example of my /etc/rc.d/rc.eth0 and my /etc/rc.d/rc.inet1:

Code:
#! /bin/sh
# /etc/rc.d/rc.eth0

INTERFACE="eth0"

IPADDR="192.168.0.1"
NETMASK="255.255.255.0"
USE_DHCP=no
#DHCP_HOSTNAME="CCHOSTNUM-A"

if [ "$USE_DHCP" = "yes" ]; then
  echo "Attempting to configure $INTERFACE by contacting a DHCP server..."
  # Add the -h option to the DHCP hostname:
  if [ ! "$DHCP_HOSTNAME" = "" ]; then
    DHCP_HOSTNAME="-h $DHCP_HOSTNAME"
  fi
  rm -f /etc/dhcpc/dhcpcd-$INTERFACE.pid
  /sbin/dhcpcd -t 10 ${DHCP_HOSTNAME} -d ${INTERFACE}
elif [ ! "$IPADDR" = "127.0.0.1" -a ! "$IPADDR" = "" ]; then # set up IP statically:
  # Determine broadcast and network addresses from the IP address and netmask:
  BROADCAST=`/bin/ipmask $NETMASK $IPADDR | cut -f 1 -d ' '`
  NETWORK=`/bin/ipmask $NETMASK $IPADDR | cut -f 2 -d ' '`
  # Set up the ethernet card:
  echo "Configuring ${INTERFACE}:"
  echo "ifconfig ${INTERFACE} ${IPADDR} broadcast ${BROADCAST} netmask ${NETMASK}"
  /sbin/ifconfig ${INTERFACE} ${IPADDR} broadcast ${BROADCAST} netmask ${NETMASK}
  # If that didn't succeed, give the system administrator some hints:
  if [ ! $? = 0 ]; then
    echo "Your ${INTERFACE} card was not initialized properly.  Here are some reasons why this"
    echo "may have happened, and the solutions:"
    echo "1. Your kernel does not contain support for your card.  Including all the"
    echo "   network drivers in a Linux kernel can make it too large to even boot, and"
    echo "   sometimes including extra drivers can cause system hangs.  To support your"
    echo "   ethernet, either edit /etc/rc.d/rc.modules to load the support at boot time,"
    echo "   or compile and install a kernel that contains support."
    echo "2. You don't have an ethernet card, in which case you should run netconfig"
    echo "   and configure your machine for loopback. (Unless you don't mind seeing this"
    echo "   error...)"
  fi
fi
Code:
#! /bin/sh
# /etc/rc.d/rc.inet1
# This script starts up the base networking system.
#
# Version:
# @(#)/etc/rc.d/rc.inet1 8.1 Tue May 28 15:27:39 PDT 2002 (pjv)

# Edit the next line to point to your gateway:
GATEWAY="" # REPLACE with YOUR gateway!

# Set up the loopback interface:
/sbin/ifconfig lo 127.0.0.1
/sbin/route add -net 127.0.0.0 netmask 255.0.0.0 lo

# Set up the interfaces
if [ -x /etc/rc.d/rc.eth0 ]; then
   /etc/rc.d/rc.eth0
fi

if [ -x /etc/rc.d/rc.eth1 ]; then
   /etc/rc.d/rc.eth1
fi

if [ -x /etc/rc.d/rc.eth2 ]; then
   /etc/rc.d/rc.eth2
fi

if [ -x /etc/rc.d/rc.wlan0 ]; then
   /etc/rc.d/rc.wlan0
fi

# Set up the gateway:
if [ ! "$GATEWAY" = "127.0.0.1" -a ! "$GATEWAY" = "" ]; then
  /sbin/route add default gw ${GATEWAY} metric 1
fi

# End of /etc/rc.d/rc.inet1
Finally, you need to use iptables to do firewalling/NAT/Masquerading. On my server I have three interfaces: eth1 goes to my cable modem, eth0 goes to my internal wired network (192.168.0.0/24), and wlan0 goes to my wireless PCI card (192.168.1.0/24). My server acts as an access point for wireless clients. The only ports I allow access to from the Internet are 25 (smtp email server) and 22 (ssh). Here's my /etc/rc.d/rc.firewall script that I call from /etc/rc.d/rc.local:

Code:
#!/bin/sh
# /etc/rc.d/rc.firewall

###############################################################################
#
# Author: Eric R. Turner <eric.r.turner(at)bitbreather(dot)com>
#
# The syntax of iptables is basically:
#
#    iptables [-t table] -ACDI CHAIN rule-specification -j TARGET [options]
#
# There are three built-in tables that each have some built-in chains:
#
#    filter - Basic packet-filter table with INPUT, FORWARD, and OUTPUT chains.
#             Only one of the chains will be traversed. (This the default
#             table.)
#    nat    - Network address translation table with PREROUTING, POSTROUTING,
#             and OUTPUT chains. PREROUTING accepts the DNAT target. Other
#             chains accept the SNAT target.
#    mangle - Table used to change info other than the IP address in the
#             header. For example, it can change the type of service (TOS) 
#             or time-to-live(ttl) information.
#
###############################################################################

   IPT=/usr/sbin/iptables

# Use a trusted PATH

   PATH=/sbin:/usr/sbin:/usr/local/sbin:/bin:/usr/bin:/usr/local/bin
   export PATH

# Disable IP forwarding until the rules are in place.

   echo 0 > /proc/sys/net/ipv4/ip_forward

# Install the necessary kernel modules.

   /sbin/modprobe ip_tables
   /sbin/modprobe ip_nat_ftp
   /sbin/modprobe ip_conntrack_ftp

# Flush the tables and delete the non-builtin chains
# to ensure that we are starting from scratch.

   for i in filter nat mangle
   do
      $IPT --table $i --flush
      $IPT --table $i --delete-chain
   done

# Set up a user-defined chain called "tcprules" in the filter table that 
# prevents anyone from connecting to local computers from the outside, but 
# allows local computers to establish connections to the outside. We'll 
# specify that the INPUT and FORWARD chains use the rules defined in our 
# "tcprules" chain after we've established those rules.

   $IPT --table filter --new-chain tcprules

   # Accept traffic (and related traffic on different ports) coming in on
   # any interface if the traffic has been seen before in both directions.

   $IPT --table filter \
        --append tcprules \
        --match state \
        --state ESTABLISHED,RELATED \
        --jump ACCEPT

   # Accept new TCP traffic coming in on any interface
   # for the email server.

   $IPT --table filter \
        --append tcprules \
        --protocol tcp \
        --destination-port 25 \
        --match state \
        --state NEW \
        --jump ACCEPT

   # Accept new SSH traffic coming in on any interface.

   $IPT --table filter \
        --append tcprules \
        --protocol tcp \
        --destination-port 22 \
        --match state \
        --state NEW \
        --jump ACCEPT

   # Accept new traffic coming in on any interface except eth1 (the
   # Internet interface).

   $IPT --table filter \
        --append tcprules \
        --in-interface ! eth1 \
        --match state \
        --state NEW \
        --jump ACCEPT

   # The catch-all rule: drop new or invalid traffic coming in on any
   # network interface.

   $IPT --table filter \
        --append tcprules \
        --match state \
        --state NEW,INVALID \
        --jump DROP

   # Use the rules defined in the "tcprules" chain for the INPUT and 
   # FOREWARD chains.

   $IPT --table filter \
        --append INPUT \
        --jump tcprules

   $IPT --table filter \
        --append FORWARD \
        --jump tcprules

   # Make sure the default policy for the filter table's INPUT and 
   # FORWARD chains is DROP rather than ACCEPT, in case we misconfigure 
   # the firewall.

   $IPT --table filter \
        --policy INPUT DROP

   $IPT --table filter \
        --policy FORWARD DROP

   
# Add masquerading to the POSTROUTING chain in the nat table.

   $IPT --table nat \
        --append POSTROUTING \
        --out-interface eth1 \
        --source 192.168.0.0/24 \
        --destination 0/0 \
        --jump MASQUERADE

   $IPT --table nat \
        --append POSTROUTING \
        --out-interface eth1 \
        --source 192.168.1.0/24 \
        --destination 0/0 \
        --jump MASQUERADE
        
# Enable IP forwarding

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

Last edited by eric.r.turner; 09-06-2003 at 08:53 PM.
 
Old 09-07-2003, 09:54 PM   #4
vrillusions
Member
 
Registered: Feb 2003
Location: Ohio, USA
Distribution: Ubuntu, Debian, CentOS
Posts: 99

Rep: Reputation: 25
Although slightly OT, another option for a linux firewall app is getting smoothwall @ http://www.smoothwall.org/ If your like me and too lazy to setup my own
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Making a Router sibtay Linux - Networking 4 10-13-2004 03:03 AM
making a router in slackware kmail Slackware 6 06-20-2004 09:12 PM
Making Slackware a router wenberg Linux - Networking 4 01-03-2004 07:56 PM
making a wireless router box yocompia Linux - Wireless Networking 0 08-05-2003 04:31 PM
Making a router!!! BouReaq Linux - Networking 6 03-19-2003 02:23 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 10:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration