LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 01-18-2004, 01:52 AM   #1
Saffsd
Member
 
Registered: Sep 2003
Distribution: Gentoo
Posts: 33

Rep: Reputation: 15
Setting up simple packet forwarding


Hey all. I've got a linux machine with two ethernet cards. One connects to a router and the other two another PC (winxp) with a crossover cable. I can ping the lnux box from the winxp box.

I'd like to know how to get internet access on the winxp box. What do I need to configure on the linux box? I've been reading about firewalls and advanced routing and i'm getting very confused. All I want to do is use the linux box as a relay, could anyone point me to a simple tutorial or howto?

Linux box is running kernel 2.4.23 with iptables compiled in. eth0 connects to the internet via my router, and eth1 connects to my other computer. I'm not connecting my other computer directly to my router because I've run out of ports, and can't afford new a hub at the moment. Had a spare ethernet card so I figured i'd try this out.

Thanks in advance!
 
Old 01-18-2004, 12:27 PM   #2
TheIrish
Member
 
Registered: Oct 2003
Location: ITALY
Distribution: Debian, Ubuntu, Fedora
Posts: 137

Rep: Reputation: 15
Hi,
yes you need to use iptables.
I'll give you the advices you need to get a basic packet forwarding.

Here's a BASIC sample of an iptables script that does what you need:

Code:
IPTABLES=/sbin/iptables     #check the correct path
EXTIF=eth0 
INTIF=eth1

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

$IPTABLES -F INPUT
$IPTABLES -P INPUT DROP
$IPTABLES -F OUTPUT
$IPTABLES -P OUTPUT DROP
$IPTABLES -F FORWARD
$IPTABLES -P FORWARD DROP
$IPTABLES -t nat -F

$IPTABLES -t nat -A POSTROUTING -o $EXTIF -j MASQUERADE    #this 'hides' internal IPs

$IPTABLES -A FORWARD -i $INTIF -o $EXTIF -j ACCEPT #this enables connections from the other PC to the internet

$IPTABLES -A FORWARD -i $EXTIF -o $INTIF -m state --state ESTABLISHED,RELATED -j ACCEPT               #What you asked to the internet by the other PC, can enter the network

$IPTABLES -A OUTPUT -o $EXTIF -j ACCEPT #if you're using the linux box directly, this enables connections out

$IPTABLES -A INPUT -i $EXTIF -m state --state ESTABLISHED,RELATED -j ACCEPT #what you asked to the internet by the linux box, can enter

#Enabling loopback... you might need the following ones if you're using samba
$IPTABLES -A INPUT -i $LOOP -j ACCEPT
$IPTABLES -A OUTPUT -o $LOOP -j ACCEPT

#The following rules let the other PC to connect to the linuxbox
$IPTABLES -A INPUT -i $INTIF -j ACCEPT
$IPTABLES -A OUTPUT -o $INTIF -j ACCEPT
I hope I didn't type anything wrong... I did this on the fly. You can run this at boot time.
NOTE: if you're connecting to the internet through PPP, you'd better do so:
EXTIF=ppp0
For more security reference, have a look at the security forum.
 
Old 01-19-2004, 12:33 AM   #3
Saffsd
Member
 
Registered: Sep 2003
Distribution: Gentoo
Posts: 33

Original Poster
Rep: Reputation: 15
Thanks for the reply! It doesn't quite seem to work though. I get the following error when i try to run all that through bash:

Code:
Warning: weird character in interface '-j' (No aliases, :, ! or *).
Bad argument 'ACCEPT'
Try 'iptables -h' or 'iptables --help' for more information.
Warning: weird character in interface '-j' (No aliases, :, ! or *).
Bad argument 'ACCEPT'
Try 'iptables -h' or 'iptables --help' for more information.
What should I do?
 
Old 01-19-2004, 09:57 AM   #4
TheIrish
Member
 
Registered: Oct 2003
Location: ITALY
Distribution: Debian, Ubuntu, Fedora
Posts: 137

Rep: Reputation: 15
This is weird... apparently there's something wrong in the kernel module or something like that...
I don't know what to say...
 
Old 01-19-2004, 06:44 PM   #5
Saffsd
Member
 
Registered: Sep 2003
Distribution: Gentoo
Posts: 33

Original Poster
Rep: Reputation: 15
Quote:
Originally posted by TheIrish
This is weird... apparently there's something wrong in the kernel module or something like that...
I don't know what to say...
Oh dear... In the kernel I compiled -everything- under the netfilter config option. Is there some stuff I should compile out?
I'm also trying to save up for a 4-port switch and the needed cables. It's a pity though, I would have liked the experience of working with iptables.
In any case, thanks for trying to help!
 
Old 01-20-2004, 12:47 PM   #6
TheIrish
Member
 
Registered: Oct 2003
Location: ITALY
Distribution: Debian, Ubuntu, Fedora
Posts: 137

Rep: Reputation: 15
It would be useful to know:
Kernel version
Distro
Iptables version (check both modules and user space).

We'll find out, don't worry
 
Old 01-20-2004, 07:06 PM   #7
Saffsd
Member
 
Registered: Sep 2003
Distribution: Gentoo
Posts: 33

Original Poster
Rep: Reputation: 15
Well the urge to spend got the best of me and I now have a (relatively inexpensive) 5 port smc switch.

In any case I'm still curious to find out what went wrong. Here's some info:
2.4.23_pre8-gss-r2 (it's a "gentoo stable sources" kernel)
Gentoo
iptables v1.2.9 (that's what "iptables -V" gives, i assume that's the userspace. How do I check the modules?)
 
  


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
packet forwarding? one.eleven Linux - Networking 19 11-08-2006 03:35 AM
Simple Port Forwarding Firewall - not forwarding MadTurki Linux - Security 14 04-09-2006 12:08 PM
Packet and Port forwarding umeshbabu Linux - Networking 1 08-21-2005 11:43 PM
packet fragmentation in packet forwarding code cranium2004 Linux - Networking 0 05-16-2005 04:05 AM
port forwarding and packet forwarding syrtsardo Linux - Newbie 2 07-03-2003 10:37 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 05:22 AM.

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