[Discuss] routing, traffic shaping
D. S.
news.observer at gmail.com
Thu Dec 6 21:54:42 PST 2007
I've got a box running damnsmalllinux with two ethernet cards in it. The first,
eth0, correctly connects to the net (via a router) no problem. What I
want now, is
to configure eth1 to allow connections to the net from it. I want the system to
act as a router or a hub, but I also want to be able to limit
bandwidth used by eth1.
(Damnsmalllinux (3.4) does not have the bridge module.) Is there a way
to do this,
without brctl?
(Assumng so,) I've cobbled totgether a script that attempts to
configire eth1 to
allow connections. After running it, I see eth1 using ifconfig (see
below), and the shaper
device also. But when I plug in a PC to eth1, it acts as if it isn't
plugged in to anything at all. So I haven't configured eth1 properly
(obviously).
Does something here leap out to anyone as wrong, impossible, etc.?
Below is the config script for eth0 and eth1, followed by the output
of ifconfig and route. I feel like I'm close :-)
=============
ifconfig eth0 down
modprobe shaper
ifconfig eth0 192.168.1.104 netmask 255.255.255.0 \
broadcast 192.168.1.255 up
ifconfig eth1 192.168.2.1 netmask 255.255.255.0 \
broadcast 192.168.2.255 up
# Associate the shaper device with our eth1
# device and apply the rate limit
#
# You must do this before bringing the shaper
# device up.
#
shapecfg attach shaper0 eth1
# associate with eth0
shapecfg speed shaper0 1000000
# shape rate limit set (5000000 = 5 Mbps, for ex)
# Configure our shaper device
#
# The shaper device will usually be configured
# with the same IP address as
# that of the associated physical device.
#
ifconfig shaper0 192.168.2.1 netmask 255.255.255.0 up
route add -net default gw 192.168.2.1 dev eth1
route add -net -n 0.0.0.0 dev eth0 # ??
# delete old configuration, if any
#Flush all the rules in filter and nat tables
iptables --flush
iptables --table nat --flush
# delete all chains that are not in default filter and nat table
iptables --delete-chain
iptables --table nat --delete-chain
# Set up IP FORWARDing and Masquerading (NAT)
iptables --table nat --append POSTROUTING --out-interface eth0 -j MASQUERADE
iptables --append FORWARD --in-interface eth1 -j ACCEPT
#enable forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward
=============
After running the above scrpt, ifconfig tells me this:
$ ifconfig
eth0 Link encap:Ethernet HWaddr 00:20:18:2A:50:49
inet addr:192.168.1.104 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1826 errors:0 dropped:0 overruns:0 frame:7
TX packets:1916 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:174042 (169.9 KiB) TX bytes:1225128 (1.1 MiB)
Interrupt:10 Base address:0xb000
eth1 Link encap:Ethernet HWaddr 00:40:F6:D4:AA:6D
inet addr:192.168.2.1 Bcast:192.168.2.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:2 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:2052 (2.0 KiB)
Interrupt:11 Base address:0xa800
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:164 errors:0 dropped:0 overruns:0 frame:0
TX packets:164 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:13279 (12.9 KiB) TX bytes:13279 (12.9 KiB)
shaper0 Link encap:Ethernet HWaddr 00:00:00:00:00:00
inet addr:192.168.2.1 Mask:255.255.255.0
UP RUNNING MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:10
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
$ route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.2.0 * 255.255.255.0 U 0 0 0 shaper0
192.168.2.0 * 255.255.255.0 U 0 0 0 eth1
192.168.1.0 * 255.255.255.0 U 0 0 0 eth0
default 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
default 192.168.2.1 0.0.0.0 UG 0 0 0 eth1
More information about the Discuss
mailing list