h IP P Router []
wA@As峹аѦ B
̪sG2003/08/22
@
ڭ̦b ¦ ̭ (route) O@ӭnALiHڭ̪ƫʥ]VI~ApGP@Ӻ̭ӦhqƶqݭnӼsܡAį@w|ӦnAҥH~| Netmask aIѧڭ̴ӨרӷQ@QApGڪ줺uӦhqƶqFANӺΦpƭӤl (Subnet) |O@Ӥn@kALA]P줧ʥ]iHqơAҥHoӮɭԧڭ̴Nݭnϥ Router ( Ѿ ) ʥ]ǰeFI
@
h IP b@dWG
@@Gh IP
@@Gp@Gcommand line, ѼƳ]w
@@G`Nƶ
Ѿ RouterG
@@GO Router
@@Gݭn Router
@@G[Pק
@ Router []dG
ijG
I^UG
ҫmG

h IP b@dWG
Ѿ RouterG
@ Router []dҡG
    nաIJMD Router nBAAӷMNOnӬ[]LoI[]ku²Izun@XӰʧ@NiHաI(GЯSOdNAȦb Routing \ӤwApGzbQqݭn[] Router ɡAiH̷ӥ媺Ӭ[]AOGuhݭnΡydzӰϹjAФnϥΥ媺 IP Alias 觋IOI)
    @
    1. ]wdAϳsPF
    2. ]w route ѪAiHqF
    3. Ұ ip_forward ﶵF
    4. b Client ݳ]w gateway O server ݪ IP I
    @
    ѩڭ̪ Router ݭnӺ줬۳sqAҥHoAz Router WNݭnPɨ㦳boӺ줧 IP I~Aѩ󤣦PݭnҰ Routing \IҥHzn@Ӱʧ@ANOثe Linux tθ̭ Routing \ҰʡIڭ̦b Linux pе -- ¦Dz߽g귽޲z 峹̭gLAӮ֤ߪ{dzOOb /proc̭Aܩڭ Linux ֤ߪ\hOb /proc/sys/net/ipv4 oӥؿIӱҰ Routing {Ǭ ip_forward oɮסIunNe]w 1 YҰʡAӷ 0 ɡANOաI]AYnҰ Routing hݭny echo 1 > /proc/sys/net/ipv4/if_forward zYiIUOڪҰաIЪ`NAoӽdҳ¶ȥuOb Router \}FIzӨ̷ӱzݨDӬ[]z Router INNڪsuϥܨqXoI ^_^
    @

    һG
    @
    bڪڴҷACӤ󪺤epUG
    @
    1. Linux DGڪ Linux Aӥ@ NAT ΡA̭idA@is ADSL ƾھAoi~dN eth1 A@isAN eth0 F
    2. Hub sqGLinux D鷺d eth0 s Hub WAPɡAHub W٦sbL|ӤHqAⳡӶiաA IP O 192.168.1.11 192.168.0.11 F
    3. eth0 鷺dGѩ鷺 C Class AҥHڪd eth0 ]w 192.168.1.2 ӥt@ӵ eth0:0 ]w 192.168.0.2 I
    4. Client ݪ@~tGڪ client ݪ]w譱Ab 192.168.1.11 ϥ Windows 2000 HA 192.168.0.11 hϥ Red Hat 7.3 oөNNoI
    @
    򥻪ϥܦpUܷNG
    @

    @
    boӳ`Aڭ̤ͫ[] NAT DAӬO򳹸`~n쪺FAҥHJIab NAT Server 䤧]wA]NO eth0 ]wIYO쪺]wӤwI򥻤WAoӥiH ϰ[c @g峹eաIboӦaAڭ̪d IP I
    @

    }l]wG
    @
    ڭ̴NӵۤWBJ@B@BӧaI
    1. ]wA𫟺 eth0 192.168.1.2, eth0:0 192.168.0.2
    [root@test root]# cd /etc/sysconfig/network-scripts
    [root@test network-scripts]# vi ifcfg-eth0
    DEVICE=eth0
    ONBOOT=yes
    BOOTPROTO=static
    IPADDR=192.168.1.2
    NETMASK=255.255.255.0
    NETWORK=192.168.1.0
    BROADCAST=192.168.1.255
    GATEWAY=192.168.1.2

    [root@test network-scripts]# vi ifcfg-eth0:0
    DEVICE=eth0:0
    ONBOOT=no
    BOOTPROTO=static
    IPADDR=192.168.0.2
    NETMASK=255.255.255.0
    NETWORK=192.168.0.0
    BROADCAST=192.168.0.255

    [root@test network-scripts]# ifup eth0 ; ifup eth0:0
    [root@test network-scripts]# ifconfig eth0; ifconfig eth0:0
    eth0      Link encap:Ethernet  HWaddr 00:50:FC:22:9C:57
              inet addr:192.168.1.2  Bcast:192.168.1.255  Mask:255.255.255.0
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:5975598 errors:0 dropped:0 overruns:0 frame:0
              TX packets:6267765 errors:0 dropped:0 overruns:0 carrier:0
              collisions:1331 txqueuelen:100
              RX bytes:557835433 (531.9 Mb)  TX bytes:2811341821 (2681.1 Mb)
              Interrupt:10 Base address:0x6100

    eth0:0    Link encap:Ethernet  HWaddr 00:50:FC:22:9C:57
              inet addr:192.168.0.2  Bcast:192.168.0.255  Mask:255.255.255.0
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              Interrupt:10 Base address:0x6100
    @IҰʨӺdoIoӨSDաIiHsqӺoI

    2. [ѱpG
    [root@test network-scripts]# route
    Kernel IP routing table
    Destination     Gateway         Genmask        Flags Metric Ref    Use Iface
    140.116.142.253 *               255.255.255.255 UH    0      0        0 ppp0
    192.168.1.0     *               255.255.255.0   U     0      0        0 eth0
    192.168.0.0     *               255.255.255.0   U     0      0        0 eth0
    127.0.0.0       *               255.0.0.0       U     0      0        0 lo
    default         140.116.142.253 0.0.0.0         UG    0      0        0 ppp0
    KIѪO諸IβzL]SYOI

    3. Ұ IP FORWARD ءG
    [root@test network-scripts]# echo 1 > /proc/sys/net/ipv4/ip_forward
    ۫HܡHMunWo@Aڭ̪ Linux N㦳 Router \FI ^_^
    pG@ճQAziHNo@[J /etc/rc.d/rc.local oɮפI

    4.1 ]w 192.168.1.0 Ӻ쪺 client qG
    IP:192.168.1.11
    Gateway:192.168.1.2 <==׭n]wI
    netmask:255.255.255.0
    network:192.168.1.0
    broadcast:192.168.1.255

    4.2 ]w 192.168.0.0 Ӻ쪺 Client q
    IP:192.168.0.11
    Gateway:192.168.0.2 <==׭n]wI
    netmask:255.255.255.0
    network:192.168.0.0
    broadcast:192.168.0.255
    p@ӡAӺ줧qN|zL GATEWAY Ө̪ GATEWAY b Linux WAҥH۵Mܮei淾qաIרڭ̤wg}ҤF Routing \IIOKISDI

    o˴N]wFIpHܮeaIoˤ@ӡANiHzܦhq줧yqνwܦhoI~Ao̥X@IA]ڤWdҪNOnΨӧ@եΪAҥHd²AӥB٬ObP@ Linux DdWdwIЪ`NApGn[]jyq Router ɡAФOHidӤjPAoӷ|nOIӦܩ client ݪ]w譱iHѦҫeXGϰ]wPsW InternetC
    @
    t~AЯSOdNANpPeڭ̴LTӬݡA}ɭԡAױz alias ]w ( O_]w ONBOOT )AunҰ eth0 h eth0:n |QҰIoӮɭԽЯSOdNIpG𫟺@ IP alias ]w~ܡAiN|ɭPz鳣|qI]hbXb GATEWAY WIij]wAN eth0 shutdown AMAҰʡAYyifdown eth0; ifup eth0zMAӬݬ route pIo˥iHקKo]w\AU}oOqpoͪI
    @

    Router u@G
    @
    nFAiKUAڭ̥innnդ@Uڭ̪ router oIpթOH²rI
    @
    1. b 192.168.1.11 o client ݡAsu 192.168.1.2 լݬݯ_suF
    2. b 192.168.1.11 o client ݴլO_iHsu 192.168.0.2 o Server ݪt@ӺsF
    3. b 192.168.1.11 o client ݴլO_iHst@ client ݡAY 192.168.0.11 o client IH
    4. N Linux D /proc/sys/net/ipv4/ip_forward \AMAWTӨBJݬݡIլݬݺO_qOH
    @
    ժu@NOo²Iӧaڭ̨ӴլݬݧaI
    1. Client ݪ( Windows 2000 @~t, IP 192.168.1.11 )G
    C:\>ping 192.168.1.2  <==P쪺D
    Pinging 192.168.1.2 with 32 bytes of data:
    Reply from 192.168.1.2: bytes=32 time<10ms TTL=255
    Reply from 192.168.1.2: bytes=32 time<10ms TTL=255
    Reply from 192.168.1.2: bytes=32 time<10ms TTL=255
    Reply from 192.168.1.2: bytes=32 time<10ms TTL=255
    Ping statistics for 192.168.1.2:
        Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
    Approximate round trip times in milli-seconds:
        Minimum = 0ms, Maximum =  0ms, Average =  0ms

    C:\>ping 192.168.0.2  <==P쪺D
    Pinging 192.168.0.2 with 32 bytes of data:
    Reply from 192.168.0.2: bytes=32 time<10ms TTL=255
    Reply from 192.168.0.2: bytes=32 time<10ms TTL=255
    Reply from 192.168.0.2: bytes=32 time<10ms TTL=255
    Reply from 192.168.0.2: bytes=32 time<10ms TTL=255
    Ping statistics for 192.168.0.2:
        Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
    Approximate round trip times in milli-seconds:
        Minimum = 0ms, Maximum =  0ms, Average =  0ms

    C:\>ping 192.168.0.11  <==P쪺 Client ݡI
    Pinging 192.168.0.11 with 32 bytes of data:
    Reply from 192.168.0.11: bytes=32 time<10ms TTL=254
    Reply from 192.168.0.11: bytes=32 time<10ms TTL=254
    Reply from 192.168.0.11: bytes=32 time<10ms TTL=254
    Reply from 192.168.0.11: bytes=32 time<10ms TTL=254
    Ping statistics for 192.168.0.11:
        Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
    Approximate round trip times in milli-seconds:
        Minimum = 0ms, Maximum =  0ms, Average =  0ms
    ݨFܡHΧڭ̪ 192.168.1.11 iH ping 192.168.0.11 IOKoI

    2. Server ݪקG
    [root@test root]# echo 0 > /proc/sys/net/ipv4/ip_forward
    N IP routing \@UIլݬݵGI

    3. Client ݪ ( @~tά windows 2000, IP 192.168.1.11 )G
    C:\>ping 192.168.0.11
    Pinging 192.168.0.11 with 32 bytes of data:
    Request timed out.
    Request timed out.
    Request timed out.
    Request timed out.
    Ping statistics for 192.168.0.11:
        Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),
    Approximate round trip times in milli-seconds:
        Minimum = 0ms, Maximum =  0ms, Average =  0ms
    WNLksuFIܸرiaII ^_^

    4. _ Linux Router G
    [root@test root]# echo 1 > /proc/sys/net/ipv4/ip_forward
    nѰO IP Routing \[^өOI

    5. Υt@ Linux Dݤ@UG ( IP 192.168.0.11 )G
    [root@vbird-redhat root]# ping -c 3 192.168.1.11
    PING 192.168.1.11 (192.168.1.11) from 192.168.0.11 : 56(84) bytes of data.
    64 bytes from 192.168.1.11: icmp_seq=1 ttl=127 time=0.542 ms
    64 bytes from 192.168.1.11: icmp_seq=2 ttl=127 time=0.517 ms
    64 bytes from 192.168.1.11: icmp_seq=3 ttl=127 time=0.541 ms
    --- 192.168.1.11 ping statistics ---
    3 packets transmitted, 3 received, 0% loss, time 1998ms
    rtt min/avg/max/mdev = 0.517/0.533/0.542/0.022 ms
    ݨWrFܡHKKISIӤPT꦳bqoI ^_^

    IժG]iDڭoISISҰ Routing \N|vT Linux O_iH㦳 Router OI

ijG
Wӽdҳ¥uOF@dҨӥܽdIn`NAڭ̦bq[] router ɭԡAq`OƱ歰CyqtAoӮɭԡAMONӺO}bӹdWnIӤOb@dW]w IP Ao˰CyqtUӤjIҥHAzutu譱inܦpUϩҥܪҼ( MA]w譱hO@˰աI )G
LצpAW觋iHѤ@Ǥp~AqƭnhhAS|vTyqpɡAiHϥΨӸѨMDIAӡA󤤤pǪGupOA]iHF줣CtĪGIӳo²檺 Router ziHϥ 486 صŪªqӬ[]NiHաIϥL loading S㦹~AW@gp{eijjaѦҡG
 
oˤlˬOIDCڪNOA@ˤΪܡA٬Oݭn˿WߪdjAouOϹjӤwAӥB٬OҼ{ʥ]yqɪDC
@
zW[cAGuA linux u@idAҥHduɷ| hub WA aBb ݤPϬqq]Ou hubCoӧGu觋Aꩳhʥ]yqɡAaBb ݺ٬OiHAuL ip hݨ]OۤvϬqʥ]Ӥz|C
@
 ip alias ɾA@뤣ijΦb router/nat oP@ ip ϬqA]PϬqʥ]٬O|b@_... uӷ~ϥΤWAnrouter/nat \ɡAq`|ijϥ ip alias (DuO{ɻݭnΪ̬OuֺdiH)Aӷ|ϥΨidåBUۨϥ hub/switchζ}BzC
@
t~H޲zںgӬݡAYOϥΪ̧@ǡAO a H[]dhcpA b ϥΪ̥iNDoF:Q ٦NOAYO a q@ǡA]iHۤv ip ]w b Ϭq ipAN|hϹjĥΡC

I^UG
ҫm
h IP P Router []

2002/08/09GĤ@I
2003/08/22Gss峹AüW[I^UPҫm