查看: 3509|回復: 0
打印 上一主題 下一主題

飛凌S3C2440開(kāi)發(fā)板路由實(shí)驗代碼

[復制鏈接]
跳轉到指定樓層
樓主
發(fā)表于 2010-7-22 13:56:34 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
關(guān)鍵詞: 代碼 , 飛凌 , 開(kāi)發(fā) , 路由 , 實(shí)驗
PS:
本文轉自 飛凌嵌入式技術(shù)交流群
這個(gè)是由群里一些工程師朋友做的小實(shí)驗,可以作為參考。
嵌入式Linux簡(jiǎn)單路由實(shí)驗
    本實(shí)驗所用硬件平臺為飛凌(www.witech.com.cn)TE2440V2型開(kāi)發(fā)板;該開(kāi)發(fā)板上有兩個(gè)網(wǎng)卡芯片,分別為CS8900和DM9000;在linux操作系統(采用2.6.12版本的內核)下兩個(gè)網(wǎng)卡對應的設備名分別為eth0和eht1。
    本實(shí)驗中TE2440V2開(kāi)發(fā)板作為路由器連接兩個(gè)局域網(wǎng):192.168.0.*和192.168.1.*,對應網(wǎng)關(guān)分別為192.168.0.3和192.168.1.3。
1. 配置開(kāi)發(fā)板上兩個(gè)網(wǎng)卡的IP地址:
# ifconfig eth0 192.168.0.3 up
# ifconfig eth0 192.168.1.3 up        
用ifconfig命令查看網(wǎng)卡信息如下:
        # ifconfig
        eth0      Link encap:Ethernet  HWaddr 00:00:02:50:10:08
                  inet addr:192.168.0.3 Bcast:192.168.0.255
                  Mask:255.255.255.0
                  UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
                  RX packets:33310 errors:0 dropped:0 overruns:0 frame:0
                  TX packets:5437 errors:55 dropped:0 overruns:25 carrier:5
                  collisions:798 txqueuelen:1000
                  RX bytes:6283109 (5.9 MiB)  TX bytes:3796550 (3.6 MiB)
                  Interrupt:53 Base address:0x300
        
        eth1      Link encap:Ethernet  HWaddr 00:12:34:56:80:49
                  inet addr:192.168.1.3 Bcast:192.168.1.255
                  Mask:255.255.255.0
                  UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
                  RX packets:38618 errors:0 dropped:0 overruns:0 frame:0
                  TX packets:2997 errors:0 dropped:0 overruns:0 carrier:0
                  collisions:0 txqueuelen:1000
                  RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
                  Interrupt:51 Base address:0x8300

2. 開(kāi)啟Linux內核的路由轉發(fā)功能(注意1后面有空格):
#echo 1 >/proc/sys/net/ipv4/ip_forward        
可通過(guò)如下命令查看路由轉發(fā)是否開(kāi)啟,1為開(kāi)啟,0為關(guān)閉。
# sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 1
# more /proc/sys/net/ipv4/ip_forward
1        
路由表不用配置,用自動(dòng)生成的就可以:
# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0     *               255.255.255.0   U     0      0        0 eth1
192.168.0.0     *               255.255.255.0   U     0      0        0 eth0        
3. 測試:用兩個(gè)局域網(wǎng)內(192.168.0.*、192.168.1.*)的PC機,分別將其默認網(wǎng)關(guān)設置為192.168.0.3和192.168.1.3(這里對應路由器的IP地址),然后用ping命令測試。我用的兩個(gè)客戶(hù)機的IP分別為192.168.0.221和192.168.1.228,測試結果如下:
C:\Documents and Settings\Administrator>ipconfig
Windows IP Configuration
Ethernet adapter 本地連接 5:
        Connection-specific DNS Suffix  . :
        IP Address. . . . . . . . . . . . : 192.168.1.228
        Subnet Mask . . . . . . . . . . . : 255.255.255.0
        Default Gateway . . . . . . . . . : 192.168.1.3
C:\Documents and Settings\Administrator>ping 192.168.0.221 -l 65500
Pinging 192.168.0.221 with 65500 bytes of data:
Reply from 192.168.0.221: bytes=65500 time=298ms TTL=63
Reply from 192.168.0.221: bytes=65500 time=244ms TTL=63
Reply from 192.168.0.221: bytes=65500 time=230ms TTL=63
Reply from 192.168.0.221: bytes=65500 time=257ms TTL=63
Ping statistics for 192.168.0.221:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 230ms, Maximum = 298ms, Average = 257ms
C:\Documents and Settings\Administrator>ipconfig
Windows IP Configuration

Ethernet adapter 本地連接 3:
        Connection-specific DNS Suffix  . :
        IP Address. . . . . . . . . . . . : 192.168.0.221
        Subnet Mask . . . . . . . . . . . : 255.255.255.0
        Default Gateway . . . . . . . . . : 192.168.0.3
C:\Documents and Settings\Administrator>ping 192.168.1.228 -l 65500
Pinging 192.168.1.228 with 65500 bytes of data:
Reply from 192.168.1.228: bytes=65500 time=240ms TTL=127
Reply from 192.168.1.228: bytes=65500 time=263ms TTL=127
Reply from 192.168.1.228: bytes=65500 time=226ms TTL=127
Reply from 192.168.1.228: bytes=65500 time=282ms TTL=127
Ping statistics for 192.168.1.228:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
        Minimum = 226ms, Maximum = 282ms, Average = 252ms
您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

關(guān)于我們  -  服務(wù)條款  -  使用指南  -  站點(diǎn)地圖  -  友情鏈接  -  聯(lián)系我們
電子工程網(wǎng) © 版權所有   京ICP備16069177號 | 京公網(wǎng)安備11010502021702
快速回復 返回頂部 返回列表
午夜高清国产拍精品福利|亚洲色精品88色婷婷七月丁香|91久久精品无码一区|99久久国语露脸精品|动漫卡通亚洲综合专区48页