惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

美团技术团队
罗磊的独立博客
SecWiki News
SecWiki News
The Register - Security
The Register - Security
The GitHub Blog
The GitHub Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
S
Schneier on Security
IT之家
IT之家
博客园 - 聂微东
T
The Exploit Database - CXSecurity.com
Recorded Future
Recorded Future
大猫的无限游戏
大猫的无限游戏
Know Your Adversary
Know Your Adversary
Latest news
Latest news
Vercel News
Vercel News
G
GRAHAM CLULEY
D
DataBreaches.Net
D
Darknet – Hacking Tools, Hacker News & Cyber Security
S
SegmentFault 最新的问题
博客园_首页
雷峰网
雷峰网
T
Tenable Blog
Spread Privacy
Spread Privacy
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
酷 壳 – CoolShell
酷 壳 – CoolShell
Cisco Talos Blog
Cisco Talos Blog
V
Visual Studio Blog
J
Java Code Geeks
博客园 - Franky
The Cloudflare Blog
Apple Machine Learning Research
Apple Machine Learning Research
C
CERT Recently Published Vulnerability Notes
T
Threatpost
Google DeepMind News
Google DeepMind News
F
Fortinet All Blogs
P
Privacy International News Feed
T
Threat Research - Cisco Blogs
T
The Blog of Author Tim Ferriss
V
Vulnerabilities – Threatpost
Recent Announcements
Recent Announcements
Blog — PlanetScale
Blog — PlanetScale
Security Latest
Security Latest
U
Unit 42
M
MIT News - Artificial intelligence
Y
Y Combinator Blog
K
Kaspersky official blog
有赞技术团队
有赞技术团队
B
Blog
腾讯CDC

博客园 - 龙

曾经沧海难为水,除却巫山不是云 智能功http://www.56.com/u12/v_NDA3NjA3Mw.html 蓝牙上网配置-服务端( 注意防火墙的设置) 蓝牙网络接入设置-客户端 treo 650 利用蓝牙上网 六祖坛经庞明讲解 http://heihe.blogchina.com/ 北峰5118对讲机简要使用指南! 关于加强业余无线电台站管理工作有关问题的通知 北峰对讲机5118软扩频 北峰5118对讲机设置差频注意使用“FUNC”键 般若波罗蜜多心经 winxp 64 金山毒霸6 Debian 安装资源 易语言 V3.8 简体中文正式版特别版 routeos 配置文件 ubuntu5.04下 输入法问题解决 在 FC3 中启动输入法的方法步骤以及 alternatives 工具的介绍
用linux构建路由器
· 2005-05-05 · via 博客园 - 龙

原文地址:

[URL=http://www.5ilinux.com/route01.html]http://www.5ilinux.com/route01.html[/URL]

--------------------------------------------------------------------------------

关键字:linux route 路由器 静态路由 GateWay 网关

用linux构建路由器

网络结构如图,Linux路由器这台计算机标识为A,它与三个网段相连,192.168.1.0/24,10.0.0.0/8,172.16.0.0/16。
[img:224c456376]http://www.5ilinux.com/image/route.png[/img:224c456376]

A计算机必须拥有三块网卡,分别与三个网段相连。

假设:
eth0与172.16.0.0相连,
eth1与10.0.0.0相连,
eth2与192.168.1.0相连。

首先来配置eth0。给这个网络接口分配地址172.16.1.1,运行下列命令: 

# ifconfig eth0 172.16.1.1 netmask 255.255.0.0

为了使这个地址不再计算机重新启动后消失,
编辑/etc/sysconfig/network-scripts/ifcfg-eth0文件,修改为如下格式:

DEVICE = eth0
ONBOOT = yes 
BROADCAST = 172.16.255.255 
NETWORK = 172.16.0.0 
NETMASK = 255.255.0.0 
IPADDR = 172.16.1.1

增加一条静态路由: 

# route add -net 172.16.0.0 netmask 255.255.0.0
这样系统中就增加了一条静态路由: 

# route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 
172.16.0.0 * 255.255.0.0 U 0 0 0 eth0

接下来,配置eth1,eth1与10.0.0.0网段相连,分配给它的地址是10.254.254.254,使用ifconfig命令为它配置参数: 

# ifconfig eth1 10.254.254.254 netmask 255.0.0.0

同样编辑/etc/sysconfig/network-scripts目录下的ifcfg-eth1文件,内容如下:

DEVICE = eth1 
ONBOOT = yes 
BROADCAST = 10.255.255.255
NETWORK = 10.0.0.0
NETMASK = 255.0.0.0
IPADDR = 10.254.254.254

再增加一条静态路由: 
# route add -net 10.0.0.0 netmask 255.0.0.0

网络中当前的路由表为 
# route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface
172.16.0.0 * 255.255.0.0 U 0 0 0 eth0
10.0.0.0 * 255.0.0.0 U 0 0 0 eth1

最后配置eth3,它连接192.168.1.0网段,分配的IP地址是192.168.1.254,执行下列命令:

# ifconfig eth2 192.168.1.254 netmask 255.255.255.0

编辑/etc/sysconfig/network-scripts目录下的ifcfg-eth2文件,内容如下:

DEVICE = eth2
ONBOOT = yes 
BROADCAST = 192.168.1.255
NETWORK = 192.168.1.0
NETMASK = 255.255.255.0
IPADDR = 192.168.1.254

再增加一条静态路由: 
# route add -net 192.168.1.0 netmask 255.255.255.0

这样网络中就有三条静态路由记录了: # route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface
172.16.0.0 * 255.255.0.0 U 0 0 0 eth0
10.0.0.0 * 255.0.0.0 U 0 0 0 eth1
192.168.1.0 * 255.255.255.0 U 0 0 0 eth2

还要为系统增加一条缺省路由,因为缺省的路由是把所有的数据包都发往它的上一级网关(假设地址是172.16.1.100,这个地址依赖于使用的网络而定,由网络管理员分配),因此增加如下的缺省路由记录: 
# route add default gw 172.16.1.100

这样系统的静态路由表建立完成,它的内容是
# route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface
172.16.0.0 * 255.255.0.0 U 0 0 0 eth0
10.0.0.0 * 255.0.0.0 U 0 0 0 eth1
192.168.1.0 * 255.255.255.0 U 0 0 0 eth2
default 172.16.1.100 0.0.0.0 UG 0 0 0 eth0

最后一步,要增加系统的IP转发功能。这个功能由/proc/sys/net/ipv4目录下的ip_forward文件控制,执行如下命令打开ip转发功能: 
echo 1 > /proc/sys/net/ipv4/ip_forward
这样我们的路由器基本上是配置好了

测试路由器的工作情况。

在linux路由器上测试:

第一步,测试自身网络是否工作正常,执行如下命令
ping 172.16.1.1 
ping 192.168.1.254 
ping 10.254.254.254
如果这些地址都能ping通,则第一步通过,否则查找原因,排除错误。

第二步,测试与上一级网关之间是否连通 
ping 172.16.1.100
如果通畅,则正常;否则查找错误原因。

在192.168.1.0网络内测试,假设它的地址是192.168.1.1,
第一步,测试自身是否工作正常, ping 192.168.1.1
第二步,测试与网关是否连通, ping 192.168.1.254
第三步,测试与10.254.254.99是否连通,这是10.0.0.0网段内的一台计算机 ping 10.254.254.99
第四步,测试与外网地址是否连通 ping 172.16.1.100 如果连通了,表示路由器配置正确,否则,查找原因,并排除之。