wiki:TipAndDoc/VM/network

VMによるネットワークテスト

network map

                      WAN
                       |
                       |
                 Windows (NAT)
                 192.168.40.1
                       |
                       |
            ((( 192.168.40.0/24 )))
             |                   |
             |                   |
        192.168.40.10     192.168.40.20
             |                   *
           <eth0>              <eth0>
      [[ubuntu-outer]]   <<centos-outer>>
           <eth1>              <eth1>
             *(10.0.0.254)       |
           10.0.0.10       10.0.0.20
                  |         |
                  |         |
                 (10.0.0.0/16)
                       |
                       |
                  10.0.0.254
                       *(10.0.0.20)
                     <eth0>
               <<ubuntu-router>>
              <eth1>        <eth2>
                |             |
          10.1.0.254         10.2.0.254
               |                      |
               |                      |
    ((((( 10.1.0.0/16 )))))          ((((( 10.2.0.0/16 )))))
    |          |      |   |             |      |  |       |
    |          |      |   |             |      |  |       |
10.1.0.10  10.1.0.20  |  10.1.0.30  10.2.0.30  |  |       |
    *          |      |   |             *      /  |       |
  <eth0>     <eth1>   |  <eth0>     <eth1>    /   |       |
 [[ubuntu-inner-AA]]  | [[ubuntu-inner-AB]]  /    |       |
                      |                     /     |       |
                      |                    /      |       |
                 10.1.0.110        10.2.0.110  10.2.0.10  10.2.0.20
                      |             |             *          |
                     <eth1>     <eth2>          <eth0>     <eth1>
                      [[centos-inner]]         [[ubuntu-inner-BB]]
                           <eth0>
                             *
                      192.168.50.110
                             |
                             |
                       192.168.50.1
                       Windows (NAT)
                             |
                             |
                            WAN
  • ((()))
    • LANセグメント
  • [[]]
    • 通常ノード
  • <<>>
    • net.ipv4.ip_forward=1 になっているノード
  • * が付いているNIC
    • デフォルトゲートウェイが設定されている
    • 同じネットワークで、ノードによってゲートウェイが異なる設定がされている場合は()で明示
    • 明示されていなければ、X.X.X.254がGW

問題点

  • (10.0.0.0/16) にデフォルトゲートウェイが二つ設定されている
    • ubuntu-outer -> 10.0.0.254(ubuntu-router)
    • ubuntu-router -> 10.0.0.20(centos-outer)
  • IP masquerade設定がない
    • centos-outer, centos-inner以外はWANに出られない
    • => centos-outerにIP masqueradeを設定すればよい => masquerade
  • 補足
    • WANとは通信できないものの、10.[0-2].0.[1-3]0のIPノード同士がubuntu-routerにmasqueradeを設定せずとも通信出来ているのは、「デフォルトゲートウェイがubuntu-routerに設定されている」かつ「ubuntu-routerは10.[0-2].0.0のルートを知っている」、「ubuntu-routerはnet.ipv4.ip_forward=1 になっている」ため。
    • 逆に言うと、WANと通信しようとした場合、WANへrequestは出来ても、192.168.[45]0.1のNATは10.[0-2].0.[1-3]0などというルートを持たないので、reply出来ない。(そもそもSourceIPがPrivateな時点でWANに出てはいけないが…)

設定

centos-outer

  • centos-outer ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
    DEVICE=eth0
    BOOTPROTO=static
    IPADDR=192.168.40.20
    NETMASK=255.255.255.0
    NETWORK=192.168.40.0
    GATEWAY=192.168.40.1
    ONBOOT=yes
    
  • centos-outer ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1
    DEVICE=eth1
    BOOTPROTO=static
    IPADDR=10.0.0.20
    NETMASK=255.255.0.0
    NETWORK=10.0.0.0
    ONBOOT=yes
    
  • centos-outer ~]# route
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    192.168.40.0    *               255.255.255.0   U     0      0        0 eth0
    10.0.0.0        *               255.255.0.0     U     0      0        0 eth1
    169.254.0.0     *               255.255.0.0     U     0      0        0 eth1
    default         192.168.40.1    0.0.0.0         UG    0      0        0 eth0
    
  • centos-outer ~]# ip route
    192.168.40.0/24 dev eth0  proto kernel  scope link  src 192.168.40.20
    10.0.0.0/16 dev eth1  proto kernel  scope link  src 10.0.0.20
    169.254.0.0/16 dev eth1  scope link
    default via 192.168.40.1 dev eth0
    

ubuntu-outer

  • ubuntu-outer:~$ cat /etc/network/interfaces
    auto lo
    iface lo inet loopback
    
    auto eth0
    iface eth0 inet static
            address 192.168.40.10
            netmask 255.255.255.0
            network 192.168.40.0
    
    auto eth1
    iface eth1 inet static
            address 10.0.0.10
            netmask 255.255.0.0
            network 10.0.0.0
            gateway 10.0.0.254
    
  • ubuntu-outer:~$ route
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    192.168.40.0    *               255.255.255.0   U     0      0        0 eth0
    10.0.0.0        *               255.255.0.0     U     0      0        0 eth1
    default         10.0.0.254      0.0.0.0         UG    100    0        0 eth1
    
  • ubuntu-outer:~$ ip route
    192.168.40.0/24 dev eth0  proto kernel  scope link  src 192.168.40.10
    10.0.0.0/16 dev eth1  proto kernel  scope link  src 10.0.0.10
    default via 10.0.0.254 dev eth1  metric 100
    

ubuntu-router

  • ubuntu-router:~$ cat /etc/network/interfaces
    auto lo
    iface lo inet loopback
    
    auto eth0
    iface eth0 inet static
            address 10.0.0.254
            netmask 255.255.0.0
            network 10.0.0.0
            gateway 10.0.0.20
    
    auto eth1
    iface eth1 inet static
            address 10.1.0.254
            netmask 255.255.0.0
            network 10.1.0.0
    
    auto eth2
    iface eth2 inet static
            address 10.2.0.254
            netmask 255.255.0.0
            network 10.2.0.0
    
  • ubuntu-router:~$ route
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    10.2.0.0        *               255.255.0.0     U     0      0        0 eth2
    10.0.0.0        *               255.255.0.0     U     0      0        0 eth0
    10.1.0.0        *               255.255.0.0     U     0      0        0 eth1
    default         10.0.0.20       0.0.0.0         UG    100    0        0 eth0
    
  • ubuntu-router:~$ ip route
    10.2.0.0/16 dev eth2  proto kernel  scope link  src 10.2.0.254
    10.0.0.0/16 dev eth0  proto kernel  scope link  src 10.0.0.254
    10.1.0.0/16 dev eth1  proto kernel  scope link  src 10.1.0.254
    default via 10.0.0.20 dev eth0  metric 100
    

ubuntu-inner-AA

  • ubuntu-inner-AA:~$ cat /etc/network/interfaces
    auto lo
    iface lo inet loopback
    
    auto eth0
    iface eth0 inet static
            address 10.1.0.10
            netmask 255.255.0.0
            network 10.1.0.0
            gateway 10.1.0.254
    
    auto eth1
    iface eth1 inet static
            address 10.1.0.20
            netmask 255.255.0.0
            network 10.1.0.0
    
  • ubuntu-inner-AA:~$ route
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    10.1.0.0        *               255.255.0.0     U     0      0        0 eth0
    10.1.0.0        *               255.255.0.0     U     0      0        0 eth1
    default         10.1.0.254      0.0.0.0         UG    100    0        0 eth0
    
  • ubuntu-inner-AA:~$ ip route
    10.1.0.0/16 dev eth0  proto kernel  scope link  src 10.1.0.10
    10.1.0.0/16 dev eth1  proto kernel  scope link  src 10.1.0.20
    default via 10.1.0.254 dev eth0  metric 100
    

ubuntu-inner-AB

  • ubuntu-inner-AB:~$ cat /etc/network/interfaces

{{{auto lo iface lo inet loopback

auto eth0 iface eth0 inet static

address 10.1.0.30 netmask 255.255.0.0 network 10.1.0.0

auto eth1 iface eth1 inet static

address 10.2.0.30 netmask 255.255.0.0 network 10.2.0.0 gateway 10.2.0.254

}}}

  • ubuntu-inner-AB:~$ route
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    10.2.0.0        *               255.255.0.0     U     0      0        0 eth1
    10.1.0.0        *               255.255.0.0     U     0      0        0 eth0
    default         10.2.0.254      0.0.0.0         UG    100    0        0 eth1
    
  • ubuntu-inner-AB:~$ ip route
    10.2.0.0/16 dev eth1  proto kernel  scope link  src 10.2.0.30
    10.1.0.0/16 dev eth0  proto kernel  scope link  src 10.1.0.30
    default via 10.2.0.254 dev eth1  metric 100
    

ubuntu-inner-BB

  • ubuntu-inner-BB:~$ cat /etc/network/interfaces
    auto lo
    iface lo inet loopback
    
    auto eth0
    iface eth0 inet static
            address 10.2.0.10
            netmask 255.255.0.0
            network 10.2.0.0
            gateway 10.2.0.254
    
    auto eth1
    iface eth1 inet static
            address 10.2.0.20
            netmask 255.255.0.0
            network 10.2.0.0
    
  • ubuntu-inner-BB:~$ route
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    10.2.0.0        *               255.255.0.0     U     0      0        0 eth0
    10.2.0.0        *               255.255.0.0     U     0      0        0 eth1
    default         10.2.0.254      0.0.0.0         UG    100    0        0 eth0
    
  • ubuntu-inner-BB:~$ ip route
    10.2.0.0/16 dev eth0  proto kernel  scope link  src 10.2.0.10
    10.2.0.0/16 dev eth1  proto kernel  scope link  src 10.2.0.20
    default via 10.2.0.254 dev eth0  metric 100
    

centos-inner

  • centos-inner ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
    DEVICE=eth0
    BOOTPROTO=static
    IPADDR=192.168.50.110
    NETMASK=255.255.255.0
    NETWORK=192.168.50.0
    GATEWAY=192.168.50.1
    ONBOOT=yes
    
  • centos-inner ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1
    DEVICE=eth1
    BOOTPROTO=static
    IPADDR=10.1.0.110
    NETMASK=255.255.0.0
    NETWORK=10.1.0.0
    ONBOOT=yes
    
  • centos-inner ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth2
    DEVICE=eth2
    BOOTPROTO=static
    IPADDR=10.2.0.110
    NETMASK=255.255.0.0
    NETWORK=10.2.0.0
    ONBOOT=yes
    
  • centos-inner ~]# route
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    192.168.50.0    *               255.255.255.0   U     0      0        0 eth0
    10.2.0.0        *               255.255.0.0     U     0      0        0 eth2
    10.1.0.0        *               255.255.0.0     U     0      0        0 eth1
    169.254.0.0     *               255.255.0.0     U     0      0        0 eth2
    default         192.168.50.1    0.0.0.0         UG    0      0        0 eth0
    
  • centos-inner ~]# ip route
    192.168.50.0/24 dev eth0  proto kernel  scope link  src 192.168.50.110
    10.2.0.0/16 dev eth2  proto kernel  scope link  src 10.2.0.110
    10.1.0.0/16 dev eth1  proto kernel  scope link  src 10.1.0.110
    169.254.0.0/16 dev eth2  scope link
    default via 192.168.50.1 dev eth0
    
Last modified 15 years ago Last modified on Sep 17, 2009 2:44:28 PM