LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1462|回复: 2

用DSL做路由器

[复制链接]
发表于 2006-1-20 16:26:59 | 显示全部楼层 |阅读模式
用DSL做路由器
挖掘DSL这个小东西的潜能,单位上的路中器是用win2000server来做的,常常被攻击,一直想用一个小的linux来做路由,因为这方面的资料太少,很是郁闷。
近来找到dsl的一些东东,试验了一下,bingo!我介绍一下过程:
环境:主机两个网卡,eth0内网用,eth1用pppoe上外网
资源:DSL2.1b光盘,iptables.dsl
http://distro.ibiblio.org/pub/li ... current/dsl-2.1.iso
http://distro.ibiblio.org/pub/li ... system/iptables.dsl

1.用DSL光盘启动,先设定eth1上网的参数:桌面右键system->net setup->dsl/pppoe->pppoeconf
设置你的用户名和密码。

2.设置eth0的网络参数:ifconfig或用桌面上的dslpanel中的netcardconfig

[color="Red"]注意不要设置gateway,即gateway设置为空!!

3.用ifconfig和route命令检查一下,现在主机应能上网了。

4.用mydsl安装iptables.dsl

5.在emelfm(dsl用户)中用touch mytable.sh建立一个文件,修改其内容如下

#!/bin/sh

# Define Internal and External interfaces
INTIF="eth0"
EXTIF="ppp0"

# Find the IP Address of the External interface
EXTIP="`/sbin/ifconfig ppp0 | grep 'inet addr' | awk '{print $2}' | sed
-e 's/.*://'`"

# Turn on IP Forwarding to allow this box to route packets
sudo echo "1" > /proc/sys/net/ipv4/ip_forward
sudo echo "1" > /proc/sys/net/ipv4/ip_dynaddr

# Clearing any existing rules and setting default policy
sudo iptables -P INPUT ACCEPT
sudo iptables -F INPUT
sudo iptables -P OUTPUT ACCEPT
sudo iptables -F OUTPUT
sudo iptables -P FORWARD DROP
sudo iptables -F FORWARD
sudo iptables -t nat -F

# Allow IP traffic to go out External interface from the Internal
sudo iptables -A FORWARD -o $EXTIF -i ! $EXTIF -j ACCEPT

# Allow related traffic from Exteral to Internal that was
# initiated by the Internal interface
sudo iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT

sudo iptables -A FORWARD -f -j ACCEPT

# Enable SNAT (MASQUERADE) functionality on External interface
sudo iptables -t nat -A POSTROUTING -o $EXTIF -j MASQUERADE

# Define the tables for each gateway on each interface
sudo ip route add default via 10.x.x.1 dev eth0 table 1#你的内网的网关地址10.x.x.1
sudo ip route add default via 68.x.x.1 dev eth1 table 2#你的外网的网关地址,ifconfig命令可看到一个p-t-p的地址68.x.x.1

# Add rules that route packets based on source or destination
#sudo ip rule add to 204.39.x.x/16 table 2 priority 500
#sudo ip rule add to 199.199.x.x/16 table 2 priority 510
#sudo ip rule add from 10.69.x.x/24 table 1 priority 600


并将这个命令设置为可执行文件。用超级用户运行以下代码mytable.sh:

sudo mytable.sh


好了用客户机上网去吧。
发表于 2006-1-21 10:43:35 | 显示全部楼层
我做成功了。但是不知怎样保存。下次重新IP又要重新设置。虽然我已backup/save过。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-1-21 15:28:47 | 显示全部楼层
用pppoeconfig设置时选择启动时自动开启(start the PPoE connection automatically at boot time), 在/opt/bootlocal.sh内容中增加:
pon 你的用户名
ifconfig eth0 xxx.xxx.xxx
~/mytable.sh
Add2Filetools 将mytable.sh命令加入备份文件,保存backup,启动时要加入命令restore
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表