如何对不同目的地址使用不同网关?

OOo,TeX,KO,ABI,GIMP,Picasa,ProE,QCAD,Inkscape,Kicad,Eagle
回复
buaacse
帖子: 19
注册时间: 2005-08-22 11:07
送出感谢: 0
接收感谢: 0
联系:

如何对不同目的地址使用不同网关?

#1

帖子 buaacse » 2005-11-29 13:09

实验室的网络有两个网关,一个是202.112.138.1,可以上教育网
另一个是202.112.138.3,可以用来出国
在windows下有人做了一个配置本地路由的脚本

代码: 全选

rem @echo off
rem del all routes
route delete *

rem 162.105.0.0-162.105.255.255
route -p add 162.105.0.0 mask 255.255.0.0 202.112.138.1

rem 166.111.0.0-166.111.255.255
route -p add 166.111.0.0 mask 255.255.0.0 202.112.138.1

rem 202.112.0.0-202.121.255.255
rem 202.112.0.0-202.119.255.255
route -p add 202.112.0.0 mask 255.248.0.0 202.112.138.1
rem 202.120.0.0-202.121.255.255
route -p add 202.120.0.0 mask 255.254.0.0 202.112.138.1

rem 202.192.0.0-202.207.255.255
route -p add 202.192.0.0 mask 255.240.0.0 202.112.138.1

rem 202.38.192.0-202.38.255.255
route -p add 202.38.192.0 mask 255.255.192.0 202.112.138.1

rem 202.38.64.0-202.38.127.255
route -p add 202.38.64.0.0 mask 255.255.192.0 202.112.138.1

rem 202.4.128.0-202.4.159.255
route -p add 202.4.128.0 mask 255.255.224.0 202.112.138.1

rem 210.25.0.0-210.47.255.255
rem 210.24.0.0-210.31.255.255
route -p add 210.24.0.0 mask 255.248.0.0 202.112.138.1
rem 210.32.0.0-210.47.255.255
route -p add 210.32.0.0 mask 255.240.0.0 202.112.138.1

rem 211.64.0.0-211.71.255.255
route -p add 211.64.0.0 mask 255.248.0.0 202.112.138.1

rem 211.80.0.0-211.87.255.255
route -p add 211.80.0.0 mask 255.248.0.0 202.112.138.1

rem 218.192.0.0-218.199.255.255
route -p add 218.192.0.0 mask 255.248.0.0 202.112.138.1

rem 219.216.0.0-219.220.255.255
rem 219.216.0.0-219.219.255.255
route -p add 219.216.0.0 mask 255.252.0.0 202.112.138.1
rem 219.220.255.255
route -p add 219.220.0.0 mask 255.255.0.0 202.112.138.1

rem 219.222.0.0-219.223.255.255
route -p add 219.222.0.0 mask 255.254.0.0 202.112.138.1

rem 219.224.0.0
route -p add 219.224.0.0 mask 255.255.0.0 202.112.138.1

rem 219.242.0.0-219.247.255.255
rem 219.242.0.0-219.243.255.255
route -p add 219.242.0.0 mask 255.254.0.0 202.112.138.1
rem 219.244.0.0-219.247.255.255
route -p add 219.244.0.0 mask 255.252.0.0 202.112.138.1

rem default route
route -p add 0.0.0.0 mask 0.0.0.0 202.112.138.3

route print
pause

这样,上教育网的地址就会自动用教育网对应的网关,出国就用出国的网关

哪位大侠告诉我Linux下怎么设置类似的东西
我发现SuSE10的网卡配置的窗口里直接就可以输入上面的内容
Debian/ubuntu下是不是要手动来配置呢?
清华同方P4 2.66 asus915G 256DDR333x2
80G PATA100 15'LCD
WindowsXP+Windows2000+Kubuntu5.10
头像
oneleaf
论坛管理员
帖子: 10214
注册时间: 2005-03-27 0:06
系统: Ubuntu 12.04
送出感谢: 7 次
接收感谢: 101 次

#2

帖子 oneleaf » 2005-11-29 14:43

route add -net 202.112.0.0 netmask 255.248.0.0 dev eth0

route add -net 202.112.0.0 netmask 255.248.0.0 gw 202.112.138.1
kdekid
帖子: 32
注册时间: 2005-11-25 11:57
送出感谢: 0
接收感谢: 0

#3

帖子 kdekid » 2005-11-29 16:08

用 ip route 命令比较好。

代码: 全选

ip route add 162.105.0.0/16 via 202.112.138.1
ip route add 166.111.0.0/16 via 202.112.138.1
ip route add 202.112.0.0/13 via 202.112.138.1
ip route add 202.120.0.0/15 via 202.112.138.1
ip route add 202.192.0.0/12 via 202.112.138.1
ip route add 202.38.192.0/18 via 202.112.138.1
ip route add 202.38.64.0.0/18 via 202.112.138.1
ip route add 202.4.128.0/19 via 202.112.138.1
ip route add 210.24.0.0/13 via 202.112.138.1
ip route add 210.32.0.0/12 via 202.112.138.1
ip route add 211.64.0.0/13 via 202.112.138.1
ip route add 211.80.0.0/13 via 202.112.138.1
ip route add 218.192.0.0/13 via 202.112.138.1
ip route add 219.216.0.0/14 via 202.112.138.1
ip route add 219.220.0.0/16 via 202.112.138.1
ip route add 219.222.0.0/15 via 202.112.138.1
ip route add 219.224.0.0/16 via 202.112.138.1
ip route add 219.242.0.0/15 via 202.112.138.1
ip route add 219.244.0.0/14 via 202.112.138.1

ip route add default via 202.112.138.3
buaacse
帖子: 19
注册时间: 2005-08-22 11:07
送出感谢: 0
接收感谢: 0
联系:

#4

帖子 buaacse » 2005-11-29 21:24

如何先删除掉系统默认的路由呢?
清华同方P4 2.66 asus915G 256DDR333x2
80G PATA100 15'LCD
WindowsXP+Windows2000+Kubuntu5.10
kdekid
帖子: 32
注册时间: 2005-11-25 11:57
送出感谢: 0
接收感谢: 0

#5

帖子 kdekid » 2005-11-29 23:23

buaacse 写了:如何先删除掉系统默认的路由呢?

man ip看看。

代码: 全选

ip route del default
回复

回到 “办公、图像、机械电子设计等”