|
|
我想最直接的方式,就是共享上网使用的网关服务器的配置了。使用linux,一台破机器都可以。
第一步:找一台有两个网卡的机器。然后我安装了linux redhat 9,当然rehat fedaor也可以啦。安装的时候,把DNS、SSH都开上。注意:eth0设置为内网IP,eth1设置为外网IP
第二步:使用ROOT登陆,
加入以下代码,前
====================
将下列内容加入/etc/rc.local文件中:eth0绑内网IP eth1绑外网IP
################
echo 1 > /proc/sys/net/ipv4/ip_forward
/sbin/modprobe ip_tables
/sbin/modprobe iptable_filter
/sbin/modprobe iptable_nat
/sbin/modprobe ip_conntrack
/sbin/modprobe ip_conntrack_ftp
/sbin/modprobe ip_nat_ftp
/sbin/iptables --flush INPUT
/sbin/iptables --flush FORWARD
/sbin/iptables --flush POSTROUTING --table nat
/sbin/iptables --policy FORWARD DROP
/sbin/iptables --table nat --append POSTROUTING --out-interface eth1 --source 192.168.0.0/16 --jump MASQUERADE
/sbin/iptables --append FORWARD --in-interface eth1 --match state --state ESTABLISHED,RELATED --jump ACCEPT
/sbin/iptables --append FORWARD --source 192.168.0.0/16 --jump ACCEPT
################
现在192.168.0.0 - 192.168.255.255网段的机器都可以共享上网啦。
然后你可以使用以下命令
iptables --list查看过滤表
========================
但过了一段时间,一堆的兄弟这个BT,那个emule,一点都不给你面子,总要制一制吧。来,我已经给你准备好了以下代码。
rc.firewall
=======================
#http://www.roback.cc/howto/bandwidth.html
#!/bin/bash
#
# All Rates are in Kbits, so in order to gets Bytes divide by 8
# e.g. 25Kbps == 3.125KB/s
#
TC=/sbin/tc
IPTABLES=/sbin/iptables
DNLD=150Kbit # DOWNLOAD Limit
DWEIGHT=15Kbit # DOWNLOAD Weight Factor ~ 1/10 of DOWNLOAD Limit
UPLD=25KBit # UPLOAD Limit
UWEIGHT=2Kbit # UPLOAD Weight Factor
tc_start() {
$TC qdisc add dev eth0 root handle 11: cbq bandwidth 100Mbit avpkt 1000 mpu 64
$TC class add dev eth0 parent 11:0 classid 11:1 cbq rate $DNLD weight $DWEIGHT allot 1514 prio 1 avpkt 1000 bounded
$TC filter add dev eth0 parent 11:0 protocol ip handle 4 fw flowid 11:1
$TC qdisc add dev eth1 root handle 10: cbq bandwidth 10Mbit avpkt 1000 mpu 64
$TC class add dev eth1 parent 10:0 classid 10:1 cbq rate $UPLD weight $UWEIGHT allot 1514 prio 1 avpkt 1000 bounded
$TC filter add dev eth1 parent 10:0 protocol ip handle 3 fw flowid 10:1
# Mark packets to route
# Upload marking
$IPTABLES -t mangle -A FORWARD -s 192.168.200.78 -j MARK --set-mark 3
# Download marking
$IPTABLES -t mangle -A FORWARD -s ! 192.168.0.0/16 -d 192.168.200.78 -j MARK --set-mark 4
}
tc_stop() {
$TC qdisc del dev eth0 root
$TC qdisc del dev eth1 root
}
tc_restart() {
tc_stop
sleep 1
tc_start
}
tc_show() {
echo ""
echo "eth0:"
$TC qdisc show dev eth0
$TC class show dev eth0
$TC filter show dev eth0
echo ""
echo "eth1:"
$TC qdisc show dev eth1
$TC class show dev eth1
$TC filter show dev eth1
echo ""
}
case "$1" in
start)
echo -n "Starting bandwidth shaping: "
tc_start
echo "done"
;;
stop)
echo -n "Stopping bandwidth shaping: "
tc_stop
echo "done"
;;
restart)
echo -n "Restarting bandwidth shaping: "
tc_restart
echo "done"
;;
show)
tc_show
;;
*)
echo "Usage: /etc/init.d/tc.sh {start|stop|restart|show}"
;;
esac
exit 0
==========================
注意,这个脚本要有执行权限才能执行,兄弟别忘了。chmod 666 rc.firewall
其中在start段,有以下几句:
# Mark packets to route
# Upload marking
$IPTABLES -t mangle -A FORWARD -s 192.168.200.78 -j MARK --set-mark 3
# Download marking
$IPTABLES -t mangle -A FORWARD -s ! 192.168.0.0/16 -d 192.168.200.78 -j MARK --set-mark 4
一个控制上行,一个控制下行。
=================
我不知道你是使用什么来监控网关的流量,我使用iptraf
想下载的使用GOOGLE.com搜索一下就明白了。安装非常简单,使用是图形的。太简单了。大家都个乐吧。 |
|