当前位置:文档之家› E2440]嵌入式Linux简单路由实验

E2440]嵌入式Linux简单路由实验

TE2440]嵌入式Linux简单路由实验
Linux, 路由, 嵌入式, 实验
嵌入式Linux简单路由实验
本实验所用硬件平台为飞凌()TE2440V2型开发板;该开发板上有两个网卡芯片,分别为CS8900和DM9000;在linux操作系统(采用2.6.12版本的内核)下两个网卡对应的设备名分别为eth0和eht1。

本实验中TE2440V2开发板作为路由器连接两个局域网:192.168.0.*和
192.168.1.*,对应网关分别为192.168.0.3和192.168.1.3。

本帖隐藏的内容需要回复才可以浏览
1. 配置开发板上两个网卡的IP地址:
1.# ifconfig eth0 19
2.168.0.3 up
2.# ifconfig eth0 192.168.1.3 up
复制代码
用ifconfig命令查看网卡信息如下:
1. # ifconfig
2. eth0 Link encap:Ethernet HWaddr 00:00:02:50:10:08
3. inet addr:192.168.0.3 Bcast:192.168.0.255
4. Mask:25
5.255.255.0
5. UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
6. RX packets:33310 errors:0 dropped:0 overruns:0 frame:0
7. TX packets:5437 errors:55 dropped:0 overruns:25 carrier:5
8. collisions:798 txqueuelen:1000
9. RX bytes:6283109 (5.9 MiB) TX bytes:3796550 (3.6 MiB)
10. Interrupt:53 Base address:0x300
11.
12. eth1 Link encap:Ethernet HWaddr 00:12:34:56:80:49
13. inet addr:192.168.1.3 Bcast:192.168.1.255
14. Mask:255.255.255.0
15. UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
16. RX packets:38618 errors:0 dropped:0 overruns:0 frame:0
17. TX packets:2997 errors:0 dropped:0 overruns:0 carrier:0
18. collisions:0 txqueuelen:1000
19. RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
20. Interrupt:51 Base address:0x8300
复制代码
2. 开启Linux内核的路由转发功能(注意1后面有空格):
1.#echo 1 >/proc/sys/net/ipv4/ip_forward
复制代码
可通过如下命令查看路由转发是否开启,1为开启,0为关闭。

1.# sysctl net.ipv4.ip_forward
.ipv4.ip_forward = 1
3.# more /proc/sys/net/ipv4/ip_forward
4. 1
复制代码
路由表不用配置,用自动生成的就可以:
1.# route
2.Kernel IP routing table
3.Destination Gateway Genmask Flags Metric Ref Use Iface
4.192.168.1.0 * 25
5.255.255.0 U 0 0 0 eth1
5.192.168.0.0 * 255.255.255.0 U 0 0 0
eth0
复制代码
3. 测试:用两个局域网内(192.168.0.*、192.168.1.*)的PC机,分别将其默认网关设置为192.168.0.3和192.168.1.3(这里对应路由器的IP地址),然后用ping命令测试。

我用的两个客户机的IP分别为192.168.0.221和192.168.1.228,测试结果如下:
1.C:\Documents and Settings\Administrator>ipconfig
2.
3.Windows IP Configuration
4.
5.Ethernet adapter 本地连接 5:
6.
7. Connection-specific DNS Suffix . :
8. IP Address. . . . . . . . . . . . : 192.168.1.228
9. Subnet Mask . . . . . . . . . . . : 255.255.255.0
10. Default Gateway . . . . . . . . . : 192.168.1.3
11.
12.C:\Documents and Settings\Administrator>ping 192.168.0.221 -l 65500
13.
14.Pinging 192.168.0.221 with 65500 bytes of data:
15.
16.Reply from 192.168.0.221: bytes=65500 time=298ms TTL=63
17.Reply from 192.168.0.221: bytes=65500 time=244ms TTL=63
18.Reply from 192.168.0.221: bytes=65500 time=230ms TTL=63
19.Reply from 192.168.0.221: bytes=65500 time=257ms TTL=63
20.
21.Ping statistics for 192.168.0.221:
22. Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
23.Approximate round trip times in milli-seconds:
24. Minimum = 230ms, Maximum = 298ms, Average = 257ms
复制代码
1.C:\Documents and Settings\Administrator>ipconfig
2.
3.Windows IP Configuration
4.
5.
6.Ethernet adapter 本地连接 3:
7.
8. Connection-specific DNS Suffix . :
9. IP Address. . . . . . . . . . . . : 192.168.0.221
10. Subnet Mask . . . . . . . . . . . : 255.255.255.0
11. Default Gateway . . . . . . . . . : 192.168.0.3
12.
13.C:\Documents and Settings\Administrator>ping 192.168.1.228 -l 65500
14.
15.Pinging 192.168.1.228 with 65500 bytes of data:
16.
17.Reply from 192.168.1.228: bytes=65500 time=240ms TTL=127
18.Reply from 192.168.1.228: bytes=65500 time=263ms TTL=127
19.Reply from 192.168.1.228: bytes=65500 time=226ms TTL=127
20.Reply from 192.168.1.228: bytes=65500 time=282ms TTL=127
21.
22.Ping statistics for 192.168.1.228:
23. Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
24.Approximate round trip times in milli-seconds:
25. Minimum = 226ms, Maximum = 282ms, Average = 252ms
复制代码。

相关主题