LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 06-01-2009, 07:07 PM   #1
get00x
LQ Newbie
 
Registered: May 2008
Distribution: Arch Linux, Debian, Slackware
Posts: 12

Rep: Reputation: 0
Question Slow Linux NAT


Hiya,

I got myself a new cable internet connection with a downstream of 50Mbps and 10Mbps upstream. I realized that my D-Link home router wouldn't be able to handle that traffic (WAN<->LAN), so I set up a computer with two NIC's and Slackware 12.2 (kernel 2.6.29.4) to use as a router instead.

My problem is that I only get a throughput of about 20Mbps down and 10Mbps up (the upstream speed is fine though of course) with the linux router. Any computer connected directly to the cable modem get full speed (50/10)... any as in my usual desktop, as well as the linux router. I'm also able to send and recieve files in 100Mbps over the LAN between my router and desktop. But I just don't get full speed through the NAT routing to or from the internet.

The two NIC's:
eth0: 01:08.0 Ethernet controller: 3Com Corporation 3c905B 100BaseTX [Cyclone] (rev 30)
eth1: 01:06.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL-8139/8139C/8139C+ (rev 10)

eth0 is connected to cable modem and eth1 is for LAN.


I've tried two different sets of iptables rules with same results:
Code:
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables -A FORWARD -i eth0 -o eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT
and
Code:
iptables -I INPUT 1 -i eth1 -j ACCEPT
iptables -I INPUT 1 -i lo -j ACCEPT
iptables -A INPUT -p TCP -i ! eth1 -d 0/0 --dport 0:1023 -j DROP
iptables -A INPUT -p UDP -i ! eth1 -d 0/0 --dport 0:1023 -j DROP
iptables -I FORWARD -i eth1 -d 192.168.0.0/255.255.255.0 -j DROP
iptables -A FORWARD -i eth1 -s 192.168.0.0/255.255.255.0 -j ACCEPT
iptables -A FORWARD -i eth0 -d 192.168.0.0/255.255.255.0 -j ACCEPT
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
The computer has a pentium 4 cpu and 1GB of ram.. cpu-usage is around 0-1% when I download from the Internet to my desktop in 20Mbps.

Any ideas what might be the cause of this..?

Last edited by get00x; 06-01-2009 at 07:08 PM.
 
Old 06-02-2009, 10:32 AM   #2
grepmasterd
Member
 
Registered: Aug 2003
Location: Seattle
Distribution: ubuntu, lately
Posts: 182
Blog Entries: 1

Rep: Reputation: 35
iptables NAT is fast, so don't look too hard at that part of the configuration. I assure you, people use iptables NAT for gigabit networks with very little impact.

Quote:
Any computer connected directly to the cable modem get full speed (50/10)
Except for your router, you mean. My first guess is that there are more likely some link issues between eth0 (linux router) and your cable modem. Are there transmission errors on eth0? Try some download tests to the linux router directly to isolate the point of slowness. If there appears to be errors, try placing a switch (not a hub) between eth0 and the cable modem - that can sometimes normalize link connectivity.

Last edited by grepmasterd; 06-02-2009 at 10:34 AM.
 
Old 06-02-2009, 11:47 AM   #3
get00x
LQ Newbie
 
Registered: May 2008
Distribution: Arch Linux, Debian, Slackware
Posts: 12

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by grepmasterd View Post
Except for your router, you mean. My first guess is that there are more likely some link issues between eth0 (linux router) and your cable modem. Are there transmission errors on eth0? Try some download tests to the linux router directly to isolate the point of slowness. If there appears to be errors, try placing a switch (not a hub) between eth0 and the cable modem - that can sometimes normalize link connectivity.
Actually, not except for my router.

# wget ftp://ftp.port80.se/100M
(4.80 MB/s) - `100M' saved [104857600]

That was downloaded to the router itself. If I try to download the same file to my desktop or laptop in the LAN I get speeds of around 2MB/s.

eth0:
RX packets:228112 errors:0 dropped:0 overruns:699 frame:0
TX packets:127707 errors:0 dropped:0 overruns:0 carrier:0

eth1:
RX packets:91983 errors:0 dropped:0 overruns:0 frame:0
TX packets:151671 errors:0 dropped:0 overruns:1 carrier:0

No errors and nothing dropped, don't know what overruns might be though? I recently rebooted it btw.

With the router active my network looks like:
cable modem <-> linux router <-> 100Mbps switch <-> client
The router gets good speeds from the Internet, but the LAN clients doesn't.

If I plug one of the LAN clients like this, it get goods speeds:
cable modem <-> 100Mbps switch <-> client
 
Old 06-02-2009, 12:26 PM   #4
grepmasterd
Member
 
Registered: Aug 2003
Location: Seattle
Distribution: ubuntu, lately
Posts: 182
Blog Entries: 1

Rep: Reputation: 35
hm, weird indeed. overruns means generally that packets are being received too fast, but that shouldn't be happening on a 50Mb line. Do you get the same overruns count when downloading directly to the router, or only when forwarding/routing? What drivers are being used by the cards? (try 'ethtool -i eth0')

also 1GB sounds like plenty of RAM, but I'm curious, what does the output of 'free' show?
 
Old 06-02-2009, 12:59 PM   #5
get00x
LQ Newbie
 
Registered: May 2008
Distribution: Arch Linux, Debian, Slackware
Posts: 12

Original Poster
Rep: Reputation: 0
# ethtool -i eth0
driver: 3c59x
version:
firmware-version:
bus-info: 0000:01:08.0

# ethtool -i eth1
driver: 8139too
version: 0.9.28
firmware-version:
bus-info: 0000:01:06.0

# free -m
total used free shared buffers cached
Mem: 1002 45 957 0 0 30
-/+ buffers/cache: 14 988
Swap: 0 0 0


I used watch ifconfig, and the overruns only occured when downloading some big file on a lan client from the internet, not when downloading directly to the router. Just like it can't route it quick enough?
 
Old 06-02-2009, 01:42 PM   #6
grepmasterd
Member
 
Registered: Aug 2003
Location: Seattle
Distribution: ubuntu, lately
Posts: 182
Blog Entries: 1

Rep: Reputation: 35
ok, just checking to see that they're using the standard drivers, and that something unexpected wasn't consuming memory, but that looks good too.

hm, try just the masquerading w/out the filter rules, since the filter rules aren't quite correctly written.

Code:
iptables -t filter -F
iptables -t mangle -F
iptables -t nat -F
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
see if there's any improvement.

as a separate test and just for kicks, try making eth1 your WAN and eth0 your LAN interface, to see if the behavior changes.
 
Old 06-02-2009, 02:24 PM   #7
get00x
LQ Newbie
 
Registered: May 2008
Distribution: Arch Linux, Debian, Slackware
Posts: 12

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by grepmasterd View Post
Code:
iptables -t filter -F
iptables -t mangle -F
iptables -t nat -F
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
Only using that didn't work at all. No connectivity.
 
Old 06-02-2009, 02:43 PM   #8
grepmasterd
Member
 
Registered: Aug 2003
Location: Seattle
Distribution: ubuntu, lately
Posts: 182
Blog Entries: 1

Rep: Reputation: 35
it should have, it does for me. here's the output from iptables-save on my system (running a similar setup as yours)

Code:
iptables-save 
# Generated by iptables-save v1.4.1.1 on Tue Jun  2 12:37:44 2009
*nat
:PREROUTING ACCEPT [216:46295]
:POSTROUTING ACCEPT [5:812]
:OUTPUT ACCEPT [27:2712]
-A POSTROUTING -o eth1 -j MASQUERADE 
COMMIT
# Completed on Tue Jun  2 12:37:44 2009
the only real difference besides hardware and drivers is that eth0 is my LAN and eth1 is my WAN (shouldn't matter, just pointing it out for the sake of clarity).
 
Old 06-02-2009, 02:47 PM   #9
get00x
LQ Newbie
 
Registered: May 2008
Distribution: Arch Linux, Debian, Slackware
Posts: 12

Original Poster
Rep: Reputation: 0
Well, no traffic got through with only that rule for some reason.

Anyway I changed eth1 to be wan and eth0 to be lan. It actually gave my clients on the lan a boost of around 15Mbps. Weird.
 
Old 06-02-2009, 02:55 PM   #10
grepmasterd
Member
 
Registered: Aug 2003
Location: Seattle
Distribution: ubuntu, lately
Posts: 182
Blog Entries: 1

Rep: Reputation: 35
maybe you have a DROP policy in place, which would explain things. iptables-save would disclose that.

so swapping interfaces fixed you up? if so, then you probably have a hardware or driver issue there somewhere.
 
Old 06-03-2009, 04:11 PM   #11
get00x
LQ Newbie
 
Registered: May 2008
Distribution: Arch Linux, Debian, Slackware
Posts: 12

Original Poster
Rep: Reputation: 0
And not only did it give a 15Mbps boost. I now have the speeds I'm supposed to be having, 50/10. Thanks for the help.
 
  


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
nat problem, web in XP too slow jonatito Linux - Networking 1 03-08-2006 05:15 PM
Slow downloads through iptables NAT sglow Linux - Networking 14 06-05-2004 12:18 PM
slow connection through iptables/nat rellick Linux - Networking 7 03-18-2004 11:24 PM
What's the difference between Linux-NAT and Sygate-NAT? yuzuohong Linux - Networking 0 08-07-2002 04:07 AM
Slow uploads over NAT network Aurix Linux - Networking 4 05-16-2002 04:06 PM

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

All times are GMT -5. The time now is 10:58 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