天天看點

如何使用兩台主機實作三個網段之間互通且三個網段均可聯網

    版權聲明:對于本部落格所有原創文章,允許個人、教育和非商業目的使用,但務必保證文章的完整性且不作任何修改地以超連結形式注明原始作者、出處及本聲明。

    部落格位址:http://blog.csdn.net/shuxiao9058

    原始作者:季亞

step1:搭建網絡拓撲

首先,圖1是我們在實驗室所搭建的網絡拓撲結構,其中192.168.1.*為我們實驗室的内網,210.28.164.11通往外網,我們所要實作的功能就是使A、B、C三網段網絡互通,且三網段可以使用210.28.164.11這個IP連接配接到外網上網。

如何使用兩台主機實作三個網段之間互通且三個網段均可聯網

圖1 網絡拓撲

網絡拓撲注解:上面兩台主機是我們欲做路由器且裝有多個網卡和LInux作業系統的PC機,其中Route1裝有兩個網卡,其中一個網卡(裝置名eth1)的IP位址為192.168.1.250,另一個網卡(裝置名eth0)的IP位址為192.168.2.254;而Route2裝有三個網卡,其中一個網卡(裝置名em1)是為了與外網相連的,它的IP位址為210.28.164.11,其餘網卡(裝置名為p1p1和p2p1)的IP位址分别為192.168.3.254和192.168.2.253。下面一層的裝置是三個交換機,分别連接配接三個不同網段的内網,且我們使用三台主機号為5的機器進行測試三個網段之間的網絡通暢情況。     

注意:在進行連線的時候注意如果是PC機和交換機相連需要直連線,如果兩台PC機之間相連則需要使用交叉線!另外,比較新的網卡有隻能識别功能,是以直連線和交叉線均可,相關知識讀者可以參考鳥哥的Linux私房菜 伺服器架設篇(第二版)中Page26-27頁中的内容。

網絡拓撲搭建好了,下面我們來進行相關網絡配置,首先我們要确認兩台機器都裝有Linux系統,筆者所使用的兩台機器安裝的作業系統分别為紅帽5.5(Route1)企業版和Fedora15(Route2).詳細資訊如下:

Route1:

[[email protected] ~]# uname -a
Linux localhost.localdomain 2.6.18-53.el5 #1 SMP Wed Oct 10 16:34:02 EDT 2007 i686 i686 i386 GNU/Linux
[[email protected] ~]# 
           

Route2:

[[email protected] ~]# uname -a
Linux localhost.localdomain 2.6.40.6-0.fc15.i686.PAE #1 SMP Tue Oct 4 00:44:38 UTC 2011 i686 i686 i386 GNU/Linux
[[email protected] ~]# 
           

另外,還要確定兩台機器都裝有iptables,可使用rpm指令檢查iptables元件是否安裝:

Route1:

[[email protected] ~]# rpm -qa iptables
iptables-1.3.5-1.2.1
[[email protected] ~]# 
           

Route2:

[[email protected] ~]# rpm -qa iptables
iptables-1.4.10-2.fc15.i686
[[email protected] ~]# 
           

如果機器中沒有安裝iptables,請通過Linux系統安裝CD光牒/鏡像檔案或在網上搜尋(http://rpm.pbone.net)下載下傳擷取安裝iptables所需的軟體包,并将該iptables安裝軟體拷貝至機器上進行安裝。

step2:IP配置

根據圖一中的拓撲結構依次配置兩台主機的IP位址,如下所示:

Route1:

+-------+ Devernet Configuration +--------+                   
                  |                                         |                   
                  |                                         |                   
                  | Name               eth1________________ |                   
                  | Device             eth1________________ |                   
                  | Use DHCP           [ ]                  |                   
                  | Static IP          192.168.1.250_______ |                   
                  | Netmask            255.255.255.0_______ |                   
                  | Default gateway IP ____________________ |                   
                  |                                         |                   
                  |      +----+            +--------+       |                   
                  |      | Ok |            | Cancel |       |                   
                  |      +----+            +--------+       |                   
                  |                                         |                   
                  |                                         |                   
                  +-----------------------------------------+                   
                                                                                
                                                                                                                                                                
                                                                                
                  +-------+ Devernet Configuration +--------+                   
                  |                                         |                   
                  |                                         |                   
                  | Name               eth0________________ |                   
                  | Device             eth0________________ |                   
                  | Use DHCP           [ ]                  |                   
                  | Static IP          192.168.2.254_______ |                   
                  | Netmask            255.255.255.0_______ |                   
                  | Default gateway IP 192.168.2.253_______ |                   
                  |                                         |                   
                  |      +----+            +--------+       |                   
                  |      | Ok |            | Cancel |       |                   
                  |      +----+            +--------+       |                   
                  |                                         |                   
                  |                                         |                   
                  +-----------------------------------------+                   
                                                                                
                                                                                
           

請注意Route1中eth0的預設網關的設定,不然A、B兩個網段将不能正常上網。

Route2:

┌─────────────┤ 網絡配置 ├─────────────┐
                    │                                      │
                    │                                      │
                    │ 名稱            em1_________________ │
                    │ 裝置            em1_________________ │
                    │ 使用 DHCP       [ ]                  │
                    │ 靜态 IP         210.28.164.11_______ │
                    │ 子網路遮罩        255.255.255.0_______ │
                    │ 預設網關 IP     210.28.164.254______ │
                    │ 主 DNS 伺服器   61.155.18.30________ │
                    │ 第二 DNS 伺服器 208.67.222.222______ │
                    │                                      │
                    │     ┌──────┐          ┌──────┐       │
                    │     │ 确定 │          │ 取消 │       │
                    │     └──────┘          └──────┘       │
                    │                                      │
                    │                                      │
                    └──────────────────────────────────────┘
                    ┌─────────────┤ 網絡配置 ├─────────────┐
                    │                                      │
                    │                                      │
                    │ 名稱            p1p1________________ │
                    │ 裝置            p1p1________________ │
                    │ 使用 DHCP       [ ]                  │
                    │ 靜态 IP         192.168.3.254_______ │
                    │ 子網路遮罩        255.255.255.0_______ │
                    │ 預設網關 IP     ____________________ │
                    │ 主 DNS 伺服器   61.155.18.30________ │
                    │ 第二 DNS 伺服器 208.67.222.222______ │
                    │                                      │
                    │     ┌──────┐          ┌──────┐       │
                    │     │ 确定 │          │ 取消 │       │
                    │     └──────┘          └──────┘       │
                    │                                      │
                    │                                      │
                    └──────────────────────────────────────┘

                    ┌─────────────┤ 網絡配置 ├─────────────┐
                    │                                      │
                    │                                      │
                    │ 名稱            p2p1________________ │
                    │ 裝置            p2p1________________ │
                    │ 使用 DHCP       [ ]                  │
                    │ 靜态 IP         192.168.2.253_______ │
                    │ 子網路遮罩        255.255.255.0_______ │
                    │ 預設網關 IP     ____________________ │
                    │ 主 DNS 伺服器   61.155.18.30________ │
                    │ 第二 DNS 伺服器 208.67.222.222______ │
                    │                                      │
                    │     ┌──────┐          ┌──────┐       │
                    │     │ 确定 │          │ 取消 │       │
                    │     └──────┘          └──────┘       │
                    │                                      │
                    │                                      │
                    └──────────────────────────────────────┘
           

備注:上面部配置設定置資訊無意義,請注意使用的均是靜态IP,不要勾選DHCP選項。

step3:重新開機網絡

配置完成之後,請輸入下面指令重新開機網絡:

Route1:

[[email protected] ~]# service network restart
正在關閉接口 eth0: [确定]
正在關閉接口 eth1: [确定]
關閉環回接口: [确定]
禁用 IPv4 包轉送: net.ipv4.ip_forward = 0
[确定]
彈出環回接口: [确定]
彈出界面 eth0: [确定]
彈出界面 eth1: [确定]
[[email protected] ~]# 
           

Route2:

[[email protected] ~]# service network restart
Restarting network (via systemctl):  [确定]
[[email protected] ~]# 
           

注意:請注意網絡是否正常開啟,如有問題,請查閱相關資料,解決後繼續下面工作。

重新開機網絡後可以檢視系統中預設的路由資訊:

Route1:

[[email protected] ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.2.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth1
169.254.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth1
[[email protected] ~]# 
           

Route2:

[[email protected] ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         210.28.164.254  0.0.0.0         UG    0      0        0 em1
192.168.2.0     0.0.0.0         255.255.255.0   U     1      0        0 p2p1
192.168.3.0     0.0.0.0         255.255.255.0   U     1      0        0 p1p1
192.168.10.0    0.0.0.0         255.255.255.0   U     0      0        0 p1p1
210.28.164.0    0.0.0.0         255.255.255.0   U     1      0        0 em1
[[email protected] ~]# 
           

從上面的路由表資訊中可以知道,系統會自動根據網卡的IP位址資訊給網卡添加預設路由資訊,如在Route1中裝置eth0的IP位址為192.168.2.254,系統會自動給它添加192.168.2.*網段的路由資訊;在Route2中裝置p2p1的IP位址為192.168.2.253,系統會自動給它添加192.168.2.*網段的路由資訊。由以上資訊可知由Route1可以通過192.168.2.253直接ping通Route2,但是不能通過192.168.3.254ping通Route2,因為沒有到從192.168.2.*或者192.168.1.*到192.168.3.*的路由路徑,反向也是如此。

step4:啟動系統IP轉發(這一步非常重要,其他操作都完成了,但是網絡還是不通暢大多都是這個問題)

Linux系統預設并沒有打開IP轉發功能,由于進出内網的資料都必須經過防火牆,是以必須啟動防火牆的IP資料包轉發功能。首先編輯/etc/sysctl.conf檔案,并設定參數net.ipv4.ip_forward的值為1,操作指令如下所示:

[[email protected] ~]# vi /etc/sysctl.conf 

# Kernel sysctl configuration file for Red Hat Linux
#
# For binary values, 0 is disabled, 1 is enabled.  See sysctl(8) and
# sysctl.conf(5) for more details.

# Controls IP packet forwarding
net.ipv4.ip_forward = 1

# Controls source route verification
net.ipv4.conf.default.rp_filter = 1

# Do not accept source routing
net.ipv4.conf.default.accept_source_route = 0

# Controls the System Request debugging functionality of the kernel
kernel.sysrq = 0

# Controls whether core dumps will append the PID to the core filename
# Useful for debugging multi-threaded applications
kernel.core_uses_pid = 1

# Controls the use of TCP syncookies
net.ipv4.tcp_syncookies = 1
"/etc/sysctl.conf" 35L, 994C written
[[email protected] ~]# service network restart
正在關閉接口 eth0: [确定]
正在關閉接口 eth1: [确定]
關閉環回接口: [确定]
彈出環回接口: [确定]
彈出界面 eth0: [确定]
彈出界面 eth1: [确定]
[[email protected] ~]# 
           

操作完成後,記得重新啟動下網絡,最後檢查确認IP轉發功能的狀态,可以檢視/proc檔案系統中的/proc/sys/net/ipv4/ip_forward狀态值,如果該值為0,說明目前系統禁止進行IP轉發;如果是1,則說明系統的IP轉發功能已經打開。操作指令如下所示:

[[email protected] ~]# cat /proc/sys/net/ipv4/ip_forward 
1
[[email protected] ~]# 
           

step5:添加路由資訊

終于到了最最核心的部分了,其實就是一個指令的多次使用,以使IP能夠路由。由于在第四步中我們知道系統已經為我們自動添加已有網卡所對應IP位址的IP網段的路由資訊,是以無需添加本網段的路由資訊了。即 無需在Route1添加如下路由資訊了:

[[email protected] ~]# route add -net 192.168.2.0/24 eth0
[[email protected] ~]# route add -net 192.168.3.0/24 eth0
           

同樣,在Route2也 無需添加如下路由資訊:

[[email protected] ~]# route add -net 192.168.1.0/24 p2p1
[[email protected] ~]# route add -net 192.168.2.0/24 p2p1
[[email protected] ~]# route add -net 192.168.3.0/24 p1p1
           

即隻需在路由表中添加非0.0.0.0網關的路由資訊,添加指令操作如下。 Route1中的操作指令如下所示:

[[email protected] ~]# route add -net 192.168.3.0/24 gw 192.168.2.253 eth0
[[email protected] ~]# route add -net 192.168.2.0/24 gw 192.168.2.253 eth0
[[email protected] ~]# 
           

下面是我在A網段中的一台IP位址為192.168.1.5,網關為192.168.1.250的PC機中的操作:

Microsoft Windows XP [版本 5.1.2600]
(C) 版權所有 1985-2001 Microsoft Corp.

C:\Documents and Settings\jiya>ping 192.168.1.250

Pinging 192.168.1.250 with 32 bytes of data:

Reply from 192.168.1.250: bytes=32 time<1ms TTL=64

Ping statistics for 192.168.1.250:
    Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms
Control-C
^C
C:\Documents and Settings\jiya>ping 192.168.3.254

Pinging 192.168.3.254 with 32 bytes of data:

Reply from 192.168.3.254: bytes=32 time<1ms TTL=63

Ping statistics for 192.168.3.254:
    Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms
Control-C
^C
C:\Documents and Settings\jiya>ping 192.168.3.5

Pinging 192.168.3.5 with 32 bytes of data:

Reply from 192.168.3.5: bytes=32 time<1ms TTL=62
Reply from 192.168.3.5: bytes=32 time<1ms TTL=62

Ping statistics for 192.168.3.5:
    Packets: Sent = 2, Received = 2, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms
Control-C
^C
C:\Documents and Settings\jiya>tracert 192.168.3.5

Tracing route to 192.168.3.5 over a maximum of 30 hops

  1    <1 ms     *        *     192.168.1.250
  2    <1 ms    <1 ms    <1 ms  192.168.2.253
  3    <1 ms    <1 ms    <1 ms  192.168.3.5

Trace complete.

C:\Documents and Settings\jiya>
           

Route2中的操作指令如下所示:

[[email protected] ~]# route add -net 192.168.1.0/24 gw 192.168.2.254 p2p1
[[email protected] ~]# route add -net 192.168.2.0/24 gw 192.168.2.254 p2p1
[[email protected] ~]# 
           

這樣便可以實作由Route1通過192.168.3.254通路Route2了,操作指令如下所示:

[[email protected] ~]# ping 192.168.3.254
PING 192.168.3.254 (192.168.3.254) 56(84) bytes of data.
64 bytes from 192.168.3.254: icmp_seq=1 ttl=64 time=1.11 ms
64 bytes from 192.168.3.254: icmp_seq=2 ttl=64 time=0.127 ms
64 bytes from 192.168.3.254: icmp_seq=3 ttl=64 time=0.145 ms
64 bytes from 192.168.3.254: icmp_seq=4 ttl=64 time=0.144 ms

--- 192.168.3.254 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 2999ms
rtt min/avg/max/mdev = 0.127/0.381/1.111/0.421 ms
[[email protected] ~]# 
           

Step6:IP僞裝配置(為内網IP做端口映射)

如此,雖然我們這三個内網可以互通網絡,但是我們還是不能在這A、B、C網段内上網,操作指令如下所示: Route1:

[[email protected] ~]# ping www.baidu.com
ping: unknown host www.baidu.com
[[email protected] ~]# 
           

這是為什麼呢?因為如果我們内網的IP發送資料到外網,但是我們的IP并不合法,一旦進入外網,IP資訊會被過濾掉,自然不能上網了,如此,我們需要為内網的IP位址做個端口映射,即使A網段的IP使用192.168.2.254這個IP上網,而使B網段和C網段内的IP使用210.28.164.11這個IP上網,其實192.168.2.254也屬于B網段,是以根本上是使A、B、C這三個網段可以使用210.28.164.11這個IP端口上網。 在Route1中,我們可以通過NAT防火牆進行IP位址僞裝,操作指令如下所示:

[[email protected] ~]# iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o eth0 -j MASQUERADE
[[email protected] ~]# service iptables save
将目前規則儲存到 /etc/sysconfig/iptables:[确定]
[[email protected] ~]# service iptables restart
清除防火牆規則:[确定]
把 chains 設定為 ACCEPT 政策:nat filter [确定]
正在解除安裝 Iiptables 子產品:[确定]
應用 iptables 防火牆規則:[确定]
載入額外 iptables 子產品:ip_conntrack_netbios_ns [确定]
[[email protected] ~]# 
           

類似的,在Route2中,我們也可以通過NAT防火牆進行IP位址僞裝,操作指令如下所示:

[[email protected] ~]# iptables -t nat -A POSTROUTING -s 192.168.2.0/24 -o em1 -j MASQUERADE
[[email protected] ~]# iptables -t nat -A POSTROUTING -s 192.168.3.0/24 -o em1 -j MASQUERADE
[[email protected] ~]# service iptables save
iptables:将防火牆規則儲存到 /etc/sysconfig/iptables:[确定]
[[email protected] ~]# service iptables restart
Restarting iptables (via systemctl):  [确定]
[[email protected] ~]# 
           

這些步驟操作完成之後,我們就可以在用戶端192.168.1.5、192.168.2.5和192.168.3.5三台機器上上網了,而且A、B、C這三個網段也可以互通了。

step7:測試

下面是在Route1(利用B網段中192.168.2.254這個IP上網,而B網段又利用210.28.164.11這個IP上網)中的操作:

[[email protected] ~]# ping www.baidu.com
PING www.a.shifen.com (119.75.218.45) 56(84) bytes of data.
64 bytes from 119.75.218.45: icmp_seq=1 ttl=49 time=26.0 ms
64 bytes from 119.75.218.45: icmp_seq=2 ttl=49 time=26.0 ms
64 bytes from 119.75.218.45: icmp_seq=3 ttl=49 time=26.2 ms
64 bytes from 119.75.218.45: icmp_seq=4 ttl=49 time=25.9 ms
64 bytes from 119.75.218.45: icmp_seq=5 ttl=49 time=26.0 ms
64 bytes from 119.75.218.45: icmp_seq=6 ttl=49 time=26.2 ms
64 bytes from 119.75.218.45: icmp_seq=7 ttl=49 time=26.0 ms

--- www.a.shifen.com ping statistics ---
7 packets transmitted, 7 received, 0% packet loss, time 5999ms
rtt min/avg/max/mdev = 25.966/26.084/26.228/0.214 ms
[[email protected] ~]# traceroute www.baidu.com
traceroute to www.baidu.com (119.75.217.56), 30 hops max, 40 byte packets
 1  192.168.2.253 (192.168.2.253)  0.146 ms  0.085 ms  0.082 ms
 2   (210.28.164.254)  1.111 ms  1.108 ms  1.112 ms
 3  172.18.32.254 (172.18.32.254)  2.851 ms  2.834 ms  2.809 ms
 4  10.29.0.201 (10.29.0.201)  0.784 ms  0.781 ms  0.831 ms
 5  * * *
 6  202.119.128.229 (202.119.128.229)  8.992 ms  9.452 ms  9.933 ms
 7  202.119.128.2 (202.119.128.2)  8.089 ms  8.113 ms  8.153 ms
 8  zhz0.cernet.net (202.112.38.113)  8.257 ms  8.264 ms  8.278 ms
 9  202.112.53.25 (202.112.53.25)  8.397 ms  8.733 ms  8.794 ms
10  202.112.62.57 (202.112.62.57)  31.151 ms  31.138 ms  31.244 ms
11  202.112.62.242 (202.112.62.242)  25.516 ms  25.557 ms  25.639 ms
12  202.112.6.54 (202.112.6.54)  26.034 ms !X * *
[[email protected] ~]# 
           

由以上的資訊可以知道Route1可以上網。

下面是我在A網段中的一台IP位址為192.168.1.5,網關為 192.168.1.250的PC機中的操作:

Microsoft Windows XP [版本 5.1.2600]
(C) 版權所有 1985-2001 Microsoft Corp.

C:\Documents and Settings\jiya>ipconfig

Windows IP Configuration


Ethernet adapter VMware Network Adapter VMnet8:

        Connection-specific DNS Suffix  . :
        IP Address. . . . . . . . . . . . : 192.168.11.1
        Subnet Mask . . . . . . . . . . . : 255.255.255.0
        Default Gateway . . . . . . . . . :

Ethernet adapter VMware Network Adapter VMnet1:

        Connection-specific DNS Suffix  . :
        IP Address. . . . . . . . . . . . : 192.168.110.1
        Subnet Mask . . . . . . . . . . . : 255.255.255.0
        Default Gateway . . . . . . . . . :

Ethernet adapter 本地連接配接:

        Connection-specific DNS Suffix  . :
        IP Address. . . . . . . . . . . . : 192.168.1.5
        Subnet Mask . . . . . . . . . . . : 255.255.255.0
        Default Gateway . . . . . . . . . : 192.168.1.250

C:\Documents and Settings\jiya>ping www.qq.com

Pinging www.qq.com [125.39.127.22] with 32 bytes of data:

Reply from 125.39.127.22: bytes=32 time=134ms TTL=46
Reply from 125.39.127.22: bytes=32 time=139ms TTL=46
Reply from 125.39.127.22: bytes=32 time=137ms TTL=46

Ping statistics for 125.39.127.22:
    Packets: Sent = 3, Received = 3, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 134ms, Maximum = 139ms, Average = 136ms
Control-C
^C
C:\Documents and Settings\jiya>tracert www.qq.com

Tracing route to www.qq.com [125.39.127.22]
over a maximum of 30 hops:

  1    <1 ms    <1 ms    <1 ms  192.168.1.250
  2    <1 ms    <1 ms    <1 ms  192.168.2.253
  3     1 ms     2 ms     1 ms  210.28.164.254
  4    <1 ms    <1 ms    <1 ms  172.18.32.254
  5     7 ms    <1 ms    <1 ms  10.29.0.201
  6     *        *        *     Request timed out.
  7     8 ms     8 ms     8 ms  202.119.128.229
  8     8 ms     8 ms     8 ms  202.119.128.2
  9     8 ms     8 ms     8 ms  zhz0.cernet.net [202.112.38.113]
 10     8 ms     8 ms     8 ms  202.112.53.25
 11    14 ms    19 ms    14 ms  202.112.36.38
 12    14 ms    14 ms    13 ms  202.112.53.202
 13   139 ms   141 ms   142 ms  219.158.34.121
 14   141 ms   139 ms   139 ms  219.158.5.229
 15    31 ms    31 ms    31 ms  219.158.96.49
 16   152 ms   151 ms   155 ms  219.158.13.250
 17   157 ms   157 ms   156 ms  202.99.66.106
 18   132 ms   134 ms   133 ms  125.39.81.134
 19   138 ms   134 ms   134 ms  125.39.127.22

Trace complete.

C:\Documents and Settings\jiya>
           

由以上的資訊可以知道A網段中的PC可以正常上網。

下面是我在B網段中的一台IP位址為192.168.2.5,網關為 192.168.2.253的PC機中的操作:

Microsoft Windows XP [版本 5.1.2600]
(C) 版權所有 1985-2001 Microsoft Corp.

C:\Documents and Settings\Admin>ipconfig

Windows IP Configuration


Ethernet adapter 本地連接配接:

        Connection-specific DNS Suffix  . :
        IP Address. . . . . . . . . . . . : 192.168.2.5
        Subnet Mask . . . . . . . . . . . : 255.255.255.0
        Default Gateway . . . . . . . . . : 192.168.2.253

C:\Documents and Settings\Admin>ping www.baidu.com

Pinging www.a.shifen.com [119.75.218.45] with 32 bytes of data:

Reply from 119.75.218.45: bytes=32 time=26ms TTL=49
Reply from 119.75.218.45: bytes=32 time=26ms TTL=49
Reply from 119.75.218.45: bytes=32 time=26ms TTL=49

Ping statistics for 119.75.218.45:
    Packets: Sent = 3, Received = 3, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 26ms, Maximum = 26ms, Average = 26ms
Control-C
^C
C:\Documents and Settings\Admin>tracert www.baidu.com

Tracing route to www.a.shifen.com [119.75.218.45]
over a maximum of 30 hops:

  1    <1 ms    <1 ms    <1 ms  192.168.2.253
  2     1 ms     1 ms     1 ms  210.28.164.254
  3    <1 ms    <1 ms    <1 ms  172.18.32.254
  4    <1 ms    <1 ms    <1 ms  10.29.0.201
  5     *        *        *     Request timed out.
  6     8 ms     8 ms     8 ms  202.119.128.229
  7     8 ms     8 ms     8 ms  202.119.128.2
  8     8 ms     8 ms     8 ms  202.112.38.109
  9     8 ms     8 ms     8 ms  202.112.53.25
 10    30 ms    30 ms    30 ms  bj-11-p11-1.cernet.net [202.112.46.5]
 11     *       25 ms     *     cd1.cernet.net [202.112.53.74]
 12    25 ms    26 ms    25 ms  202.112.6.58
 13    31 ms    31 ms    31 ms  192.168.0.5
 14    26 ms    26 ms    26 ms  10.65.190.131
 15    26 ms    26 ms    26 ms  119.75.218.45

Trace complete.

C:\Documents and Settings\Admin>
           

下面是我在B網段中的一台IP位址為192.168.2.5,網關為 192.168.2.254的PC機中的操作:

Microsoft Windows XP [版本 5.1.2600]
(C) 版權所有 1985-2001 Microsoft Corp.

C:\Documents and Settings\Admin>ipconfig

Windows IP Configuration


Ethernet adapter 本地連接配接:

        Connection-specific DNS Suffix  . :
        IP Address. . . . . . . . . . . . : 192.168.2.5
        Subnet Mask . . . . . . . . . . . : 255.255.255.0
        Default Gateway . . . . . . . . . : 192.168.2.254

C:\Documents and Settings\Admin>ping www.baidu.com

Pinging www.a.shifen.com [119.75.218.45] with 32 bytes of data:

Reply from 119.75.218.45: bytes=32 time=26ms TTL=49
Reply from 119.75.218.45: bytes=32 time=26ms TTL=49
Reply from 119.75.218.45: bytes=32 time=26ms TTL=49

Ping statistics for 119.75.218.45:
    Packets: Sent = 3, Received = 3, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 26ms, Maximum = 26ms, Average = 26ms
Control-C
^C
C:\Documents and Settings\Admin>tracert www.baidu.com

Tracing route to www.a.shifen.com [119.75.218.45]
over a maximum of 30 hops:

  1    <1 ms    <1 ms    <1 ms  192.168.2.254
  2    <1 ms    <1 ms     *     192.168.2.253
  3   450 ms     *        *     210.28.164.254
  4   191 ms    96 ms   374 ms  172.18.32.254
  5     *      113 ms    35 ms  10.29.0.201
  6     *        *        *     Request timed out.
  7   347 ms   471 ms   638 ms  202.119.128.229
  8   278 ms   568 ms    71 ms  202.119.128.2
  9   427 ms   343 ms     *     202.112.38.109
 10     *        *        *     Request timed out.
 11   708 ms     *      617 ms  bj-11-p11-1.cernet.net [202.112.46.5]
 12     *        *        *     Request timed out.
 13   797 ms   509 ms   308 ms  202.112.6.58
 14   569 ms   339 ms   376 ms  192.168.0.5
 15   952 ms   464 ms   874 ms  10.65.190.131
 16   214 ms   579 ms   550 ms  119.75.218.45

Trace complete.

C:\Documents and Settings\Admin>
           

由以上的資訊我們可以知道在B網段中,無論我們使用192.168.2.253做網關,還是用192.168.2.254做網關,這個網段内的PC機均可以正常上網。隻是用192.168.2.254做網段的機器上網的話需要多一次路由。

下面是我在C網段中的一台IP位址為192.168.3.5,網關為 192.168.3.254的PC機中的操作:

Microsoft Windows XP [版本 5.1.2600]
(C) 版權所有 1985-2001 Microsoft Corp.

C:\Documents and Settings\Admin>ipconfig

Windows IP Configuration


Ethernet adapter 本地連接配接:

        Connection-specific DNS Suffix  . :
        IP Address. . . . . . . . . . . . : 192.168.3.5
        Subnet Mask . . . . . . . . . . . : 255.255.255.0
        Default Gateway . . . . . . . . . : 192.168.3.254

C:\Documents and Settings\Admin>ping www.baidu.com

Pinging www.a.shifen.com [119.75.218.45] with 32 bytes of data:

Reply from 119.75.218.45: bytes=32 time=395ms TTL=49
Reply from 119.75.218.45: bytes=32 time=389ms TTL=49
Reply from 119.75.218.45: bytes=32 time=520ms TTL=49

Ping statistics for 119.75.218.45:
    Packets: Sent = 3, Received = 3, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 389ms, Maximum = 520ms, Average = 434ms
Control-C
^C
C:\Documents and Settings\Admin>tracert www.baidu.com

Tracing route to www.a.shifen.com [119.75.218.45]
over a maximum of 30 hops:

  1    <1 ms    <1 ms    <1 ms  192.168.3.254
  2   141 ms   416 ms   828 ms  210.28.164.254
  3   326 ms   314 ms   196 ms  172.18.32.254
  4   235 ms   145 ms     *     10.29.0.201
  5     *        *        *     Request timed out.
  6   414 ms   551 ms     *     202.119.128.229
  7   289 ms   246 ms   216 ms  202.119.128.2
  8     *      404 ms   705 ms  202.112.38.109
  9     *      407 ms   419 ms  202.112.53.25
 10   180 ms   209 ms   281 ms  bj-11-p11-1.cernet.net [202.112.46.5]
 11     *        *      354 ms  cd1.cernet.net [202.112.53.74]
 12     *      298 ms   555 ms  202.112.6.58
 13    35 ms    37 ms    31 ms  192.168.0.5
 14   153 ms   144 ms   181 ms  10.65.190.131
 15     *        *       27 ms  119.75.218.45

Trace complete.

C:\Documents and Settings\Admin>
           

由以上的資訊可以知道C網段中的PC可以正常上網。 至此,我們發現A、B、C這三個網段之間的機器可以互通網絡,且可以通過指定網關上網。 下面是本人配置成功後的路由表資訊,僅供參考: Route1:

[[email protected] ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.3.0     192.168.2.253   255.255.255.0   UG    0      0        0 eth0
192.168.3.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.2.0     192.168.2.253   255.255.255.0   UG    0      0        0 eth0
192.168.2.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth1
169.254.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth1
0.0.0.0         192.168.2.253   0.0.0.0         UG    0      0        0 eth0
[[email protected] ~]# 
           

Route2:

[[email protected] ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         210.28.164.254  0.0.0.0         UG    0      0        0 em1
192.168.1.0     192.168.2.254   255.255.255.0   UG    0      0        0 p2p1
192.168.2.0     0.0.0.0         255.255.255.0   U     1      0        0 p2p1
192.168.3.0     0.0.0.0         255.255.255.0   U     1      0        0 p1p1
192.168.10.0    0.0.0.0         255.255.255.0   U     0      0        0 p1p1
210.28.164.0    0.0.0.0         255.255.255.0   U     1      0        0 em1
[[email protected] ~]# 
           

【版權聲明】

如有疑問請咨詢本人: http://t.qq.com/shuxiao9058 如需轉載本文請注明出處: http://blog.csdn.net/shuxiao9058/article/details/6897955

繼續閱讀