| 1 | [[PageOutline]] |
| 2 | |
| 3 | = static route = |
| 4 | * see also wiki:TipAndDoc/network/iproute |
| 5 | |
| 6 | * wiki:TipAndDoc/network/vmtest#networkmap のネットワークを使用 |
| 7 | |
| 8 | = centos-inner = |
| 9 | * see wiki:TipAndDoc/network/vmtest/ping#centos-inner-ubuntu-outer |
| 10 | |
| 11 | * 10.0.0.0/16に対するルートを設定するだけでよい |
| 12 | |
| 13 | == 失敗例 == |
| 14 | * GWを指定しない例 |
| 15 | |
| 16 | * centos-inner ~]$ sudo route add -net 10.0.0.0/16 dev eth1 |
| 17 | * centos-inner ~]$ route |
| 18 | {{{ |
| 19 | Kernel IP routing table |
| 20 | Destination Gateway Genmask Flags Metric Ref Use Iface |
| 21 | 192.168.50.0 * 255.255.255.0 U 0 0 0 eth0 |
| 22 | 10.2.0.0 * 255.255.0.0 U 0 0 0 eth2 |
| 23 | 10.0.0.0 * 255.255.0.0 U 0 0 0 eth1 |
| 24 | 10.1.0.0 * 255.255.0.0 U 0 0 0 eth1 |
| 25 | 169.254.0.0 * 255.255.0.0 U 0 0 0 eth2 |
| 26 | default 192.168.50.1 0.0.0.0 UG 0 0 0 eth0 |
| 27 | }}} |
| 28 | * centos-inner ~]$ ping 10.0.0.10 -c 1 |
| 29 | {{{ |
| 30 | PING 10.0.0.10 (10.0.0.10) 56(84) bytes of data. |
| 31 | From 10.1.0.110 icmp_seq=1 Destination Host Unreachable |
| 32 | |
| 33 | --- 10.0.0.10 ping statistics --- |
| 34 | 1 packets transmitted, 0 received, +1 errors, 100% packet loss, time 0ms |
| 35 | }}} |
| 36 | |
| 37 | * ルート削除 |
| 38 | * centos-inner ~]$ sudo route del -net 10.0.0.0/16 dev eth1 |
| 39 | |
| 40 | == 正しい設定 == |
| 41 | * GWを指定 |
| 42 | |
| 43 | * centos-inner ~]$ sudo route add -net 10.0.0.0/16 gw 10.1.0.254 dev eth1 |
| 44 | * centos-inner ~]$ route |
| 45 | {{{ |
| 46 | Kernel IP routing table |
| 47 | Destination Gateway Genmask Flags Metric Ref Use Iface |
| 48 | 192.168.50.0 * 255.255.255.0 U 0 0 0 eth0 |
| 49 | 10.2.0.0 * 255.255.0.0 U 0 0 0 eth2 |
| 50 | 10.0.0.0 10.1.0.254 255.255.0.0 UG 0 0 0 eth1 |
| 51 | 10.1.0.0 * 255.255.0.0 U 0 0 0 eth1 |
| 52 | 169.254.0.0 * 255.255.0.0 U 0 0 0 eth2 |
| 53 | default 192.168.50.1 0.0.0.0 UG 0 0 0 eth0 |
| 54 | }}} |
| 55 | * centos-inner ~]$ ip route |
| 56 | {{{ |
| 57 | 192.168.50.0/24 dev eth0 proto kernel scope link src 192.168.50.110 |
| 58 | 10.2.0.0/16 dev eth2 proto kernel scope link src 10.2.0.110 |
| 59 | 10.0.0.0/16 via 10.1.0.254 dev eth1 |
| 60 | 10.1.0.0/16 dev eth1 proto kernel scope link src 10.1.0.110 |
| 61 | 169.254.0.0/16 dev eth2 scope link |
| 62 | default via 192.168.50.1 dev eth0 |
| 63 | }}} |
| 64 | |
| 65 | * 同じ作用を持つコマンド例 |
| 66 | * sudo route add -net 10.0.0.0/16 gw 10.1.0.254 |
| 67 | * sudo route add -net 10.0.0.0 netmask 255.255.0.0 gw 10.1.0.254 |
| 68 | * sudo ip route add 10.0.0.0/16 via 10.1.0.254 |
| 69 | * => wiki:TipAndDoc/network/iproute |
| 70 | |
| 71 | === 結果 === |
| 72 | * centos-inner ~]$ ping 10.0.0.10 -c 1 |
| 73 | {{{ |
| 74 | PING 10.0.0.10 (10.0.0.10) 56(84) bytes of data. |
| 75 | 64 bytes from 10.0.0.10: icmp_seq=1 ttl=63 time=7.59 ms |
| 76 | |
| 77 | --- 10.0.0.10 ping statistics --- |
| 78 | 1 packets transmitted, 1 received, 0% packet loss, time 0ms |
| 79 | rtt min/avg/max/mdev = 7.595/7.595/7.595/0.000 ms |
| 80 | }}} |
| 81 | 1. centos-inner:eth1 |
| 82 | {{{ |
| 83 | 23:30:59.173104 IP 10.1.0.110 > 10.0.0.10: ICMP echo request, id 36879, seq 1, length 64 |
| 84 | 23:30:59.177896 IP 10.0.0.10 > 10.1.0.110: ICMP echo reply, id 36879, seq 1, length 64 |
| 85 | }}} |
| 86 | 1. ubuntu-router:eth1 |
| 87 | {{{ |
| 88 | 23:30:59.228193 IP 10.1.0.110 > 10.0.0.10: ICMP echo request, id 36879, seq 1, length 64 |
| 89 | 23:30:59.231724 IP 10.0.0.10 > 10.1.0.110: ICMP echo reply, id 36879, seq 1, length 64 |
| 90 | }}} |
| 91 | 1. ubuntu-router:eth0 |
| 92 | {{{ |
| 93 | 23:30:59.229467 IP 10.1.0.110 > 10.0.0.10: ICMP echo request, id 36879, seq 1, length 64 |
| 94 | 23:30:59.231524 IP 10.0.0.10 > 10.1.0.110: ICMP echo reply, id 36879, seq 1, length 64 |
| 95 | }}} |
| 96 | 1. ubuntu-outer:eth1 |
| 97 | {{{ |
| 98 | 23:30:59.230167 IP 10.1.0.110 > 10.0.0.10: ICMP echo request, id 36879, seq 1, length 64 |
| 99 | 23:30:59.230345 IP 10.0.0.10 > 10.1.0.110: ICMP echo reply, id 36879, seq 1, length 64 |
| 100 | }}} |
| 101 | |
| 102 | === 不十分な点 === |
| 103 | * パケットの往路と復路が異なったまま |
| 104 | * see also wiki:TipAndDoc/network/vmtest/ping#ubuntu-outerrouterubuntu-inner-AB |
| 105 | * iprouteでruleを設定しないと解決できない |
| 106 | |
| 107 | * ubuntu-outer <=(router)=> centos-inner |
| 108 | |
| 109 | * パケット経路 |
| 110 | 1. ubuntu-outer:eth1 |
| 111 | 1. router:eth0 |
| 112 | 1. router:eth2 |
| 113 | 1. centos-inner:eth2 |
| 114 | 1. centos-inner:eth1 |
| 115 | 1. router:eth1 |
| 116 | 1. router:eth0 |
| 117 | 1. ubuntu-outer:eth1 |
| 118 | |
| 119 | * ubuntu-outer:~$ ping 10.2.0.110 -c 1 |
| 120 | {{{ |
| 121 | PING 10.2.0.110 (10.2.0.110) 56(84) bytes of data. |
| 122 | 64 bytes from 10.2.0.110: icmp_seq=1 ttl=63 time=3.79 ms |
| 123 | |
| 124 | --- 10.2.0.110 ping statistics --- |
| 125 | 1 packets transmitted, 1 received, 0% packet loss, time 0ms |
| 126 | rtt min/avg/max/mdev = 3.792/3.792/3.792/0.000 ms |
| 127 | }}} |
| 128 | 1. ubuntu-outer:eth1 |
| 129 | {{{ |
| 130 | 03:31:52.084210 IP 10.0.0.10 > 10.2.0.110: ICMP echo request, id 14881, seq 1, length 64 |
| 131 | 03:31:52.087987 IP 10.2.0.110 > 10.0.0.10: ICMP echo reply, id 14881, seq 1, length 64 |
| 132 | }}} |
| 133 | 1. ubuntu-router:eth0 |
| 134 | {{{ |
| 135 | 03:31:52.086225 IP 10.0.0.10 > 10.2.0.110: ICMP echo request, id 14881, seq 1, length 64 |
| 136 | 03:31:52.088104 IP 10.2.0.110 > 10.0.0.10: ICMP echo reply, id 14881, seq 1, length 64 |
| 137 | }}} |
| 138 | 1. ubuntu-router:eth2 |
| 139 | {{{ |
| 140 | 03:31:52.086987 IP 10.0.0.10 > 10.2.0.110: ICMP echo request, id 14881, seq 1, length 64 |
| 141 | }}} |
| 142 | 1. centos-inner:eth2 |
| 143 | {{{ |
| 144 | 03:31:51.922144 IP 10.0.0.10 > 10.2.0.110: ICMP echo request, id 14881, seq 1, length 64 |
| 145 | }}} |
| 146 | 1. centos-inner:eth1 |
| 147 | {{{ |
| 148 | 03:31:51.924352 IP 10.2.0.110 > 10.0.0.10: ICMP echo reply, id 14881, seq 1, length 64 |
| 149 | }}} |
| 150 | 1. ubuntu-router:eth1 |
| 151 | {{{ |
| 152 | 03:31:52.088093 IP 10.2.0.110 > 10.0.0.10: ICMP echo reply, id 14881, seq 1, length 64 |
| 153 | }}} |
| 154 | |
| 155 | = centos-outer = |
| 156 | * 上記のようにcentos-inner側のみ設定しても、centos-outerのGW設定が正しくないので通信できない |
| 157 | * centos-inner -> 10.0.0.20(centos-outer) |
| 158 | * 100% packet loss |
| 159 | |
| 160 | * centos-outer ~]$ sudo route add -net 10.1.0.0 netmask 255.255.0.0 gw 10.0.0.254 |
| 161 | * centos-outer ~]$ route |
| 162 | {{{ |
| 163 | Kernel IP routing table |
| 164 | Destination Gateway Genmask Flags Metric Ref Use Iface |
| 165 | 192.168.40.0 * 255.255.255.0 U 0 0 0 eth0 |
| 166 | 10.0.0.0 * 255.255.0.0 U 0 0 0 eth1 |
| 167 | 10.1.0.0 10.0.0.254 255.255.0.0 UG 0 0 0 eth1 |
| 168 | 169.254.0.0 * 255.255.0.0 U 0 0 0 eth1 |
| 169 | default 192.168.40.1 0.0.0.0 UG 0 0 0 eth0 |
| 170 | }}} |
| 171 | * centos-inner ~]$ ping 10.0.0.20 -c 1 |
| 172 | {{{ |
| 173 | PING 10.0.0.20 (10.0.0.20) 56(84) bytes of data. |
| 174 | 64 bytes from 10.0.0.20: icmp_seq=1 ttl=63 time=11.2 ms |
| 175 | |
| 176 | --- 10.0.0.20 ping statistics --- |
| 177 | 1 packets transmitted, 1 received, 0% packet loss, time 0ms |
| 178 | rtt min/avg/max/mdev = 11.297/11.297/11.297/0.000 ms |
| 179 | }}} |
| 180 | 1. centos-inner:eth1 |
| 181 | {{{ |
| 182 | 02:37:22.195583 IP 10.1.0.110 > 10.0.0.20: ICMP echo request, id 36626, seq 1, length 64 |
| 183 | 02:37:22.201576 IP 10.0.0.20 > 10.1.0.110: ICMP echo reply, id 36626, seq 1, length 64 |
| 184 | }}} |
| 185 | 1. ubuntu-router:eth1 |
| 186 | {{{ |
| 187 | 02:37:22.301243 IP 10.1.0.110 > 10.0.0.20: ICMP echo request, id 36626, seq 1, length 64 |
| 188 | 02:37:22.310362 IP 10.0.0.20 > 10.1.0.110: ICMP echo reply, id 36626, seq 1, length 64 |
| 189 | }}} |
| 190 | 1. ubuntu-router:eth0 |
| 191 | {{{ |
| 192 | 02:37:22.304480 IP 10.1.0.110 > 10.0.0.20: ICMP echo request, id 36626, seq 1, length 64 |
| 193 | 02:37:22.310159 IP 10.0.0.20 > 10.1.0.110: ICMP echo reply, id 36626, seq 1, length 64 |
| 194 | }}} |
| 195 | 1. centos-outer:eth1 |
| 196 | {{{ |
| 197 | 02:37:22.012423 IP 10.1.0.110 > 10.0.0.20: ICMP echo request, id 36626, seq 1, length 64 |
| 198 | 02:37:22.013349 IP 10.0.0.20 > 10.1.0.110: ICMP echo reply, id 36626, seq 1, length 64 |
| 199 | }}} |
| 200 | |
| 201 | * 同様に、10.2.0.0/16側のルート設定も必要 |
| 202 | * ubuntu-inner-AB:~$ ping 10.0.0.20 -c 1 => loss |
| 203 | 1. centos-outer:eth1 |
| 204 | {{{ |
| 205 | 02:41:53.171490 IP 10.2.0.30 > 10.0.0.20: ICMP echo request, id 9759, seq 1, length 64 |
| 206 | }}} |
| 207 | 1. centos-outer:eth0 |
| 208 | {{{ |
| 209 | 02:41:53.172303 IP 10.0.0.20 > 10.2.0.30: ICMP echo reply, id 9759, seq 1, length 64 |
| 210 | }}} |
| 211 | * centos-outer ~]$ sudo route add -net 10.2.0.0/16 gw 10.0.0.254 |
| 212 | * centos-outer ~]$ route |
| 213 | {{{ |
| 214 | Kernel IP routing table |
| 215 | Destination Gateway Genmask Flags Metric Ref Use Iface |
| 216 | 192.168.40.0 * 255.255.255.0 U 0 0 0 eth0 |
| 217 | 10.2.0.0 10.0.0.254 255.255.0.0 UG 0 0 0 eth1 |
| 218 | 10.0.0.0 * 255.255.0.0 U 0 0 0 eth1 |
| 219 | 10.1.0.0 10.0.0.254 255.255.0.0 UG 0 0 0 eth1 |
| 220 | 169.254.0.0 * 255.255.0.0 U 0 0 0 eth1 |
| 221 | default 192.168.40.1 0.0.0.0 UG 0 0 0 eth0 |
| 222 | }}} |
| 223 | * centos-outer ~]$ ip route |
| 224 | {{{ |
| 225 | 192.168.40.0/24 dev eth0 proto kernel scope link src 192.168.40.20 |
| 226 | 10.2.0.0/16 via 10.0.0.254 dev eth1 |
| 227 | 10.0.0.0/16 dev eth1 proto kernel scope link src 10.0.0.20 |
| 228 | 10.1.0.0/16 via 10.0.0.254 dev eth1 |
| 229 | 169.254.0.0/16 dev eth1 scope link |
| 230 | default via 192.168.40.1 dev eth0 |
| 231 | }}} |
| 232 | * これで正常に通信できるようになる |
| 233 | |
| 234 | = static route + IP MASQUERADE = |
| 235 | * see also wiki:TipAndDoc/network/vmtest/masquerade#needroute |
| 236 | |
| 237 | * centos-outer ~]$ sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE |
| 238 | * これでWANと通信できるようになる |
| 239 | * ubuntu-inner-AB:~$ ping 202.12.27.33 -c 1 |
| 240 | {{{ |
| 241 | PING 202.12.27.33 (202.12.27.33) 56(84) bytes of data. |
| 242 | 64 bytes from 202.12.27.33: icmp_seq=1 ttl=238 time=16.5 ms |
| 243 | |
| 244 | --- 202.12.27.33 ping statistics --- |
| 245 | 1 packets transmitted, 1 received, 0% packet loss, time 0ms |
| 246 | rtt min/avg/max/mdev = 16.543/16.543/16.543/0.000 ms |
| 247 | }}} |
| 248 | |
| 249 | == DNS == |
| 250 | * /etc/resolv.conf |
| 251 | {{{ |
| 252 | nameserver 130.158.XY.ZZ5 |
| 253 | nameserver 130.158.XY.ZZ6 |
| 254 | }}} |
| 255 | |
| 256 | * 何故か名前解決できない |
| 257 | * ubuntu-router:~$ ping www.coins.tsukuba.ac.jp -c 1 |
| 258 | {{{ |
| 259 | ping: unknown host www.coins.tsukuba.ac.jp |
| 260 | }}} |
| 261 | * ubuntu-router:eth0 |
| 262 | {{{ |
| 263 | 03:00:02.915007 IP 10.0.0.20 > 10.0.0.254: ICMP host 130.158.XY.ZZ5 unreachable - admin prohibited, length 77 |
| 264 | 03:00:02.918149 IP 10.0.0.20 > 10.0.0.254: ICMP host 130.158.XY.ZZ6 unreachable - admin prohibited, length 77 |
| 265 | 03:00:02.920515 IP 10.0.0.20 > 10.0.0.254: ICMP host 130.158.XY.ZZ5 unreachable - admin prohibited, length 77 |
| 266 | 03:00:02.922796 IP 10.0.0.20 > 10.0.0.254: ICMP host 130.158.XY.ZZ6 unreachable - admin prohibited, length 77 |
| 267 | 03:00:02.925276 IP 10.0.0.20 > 10.0.0.254: ICMP host 130.158.XY.ZZ5 unreachable - admin prohibited, length 77 |
| 268 | 03:00:02.928189 IP 10.0.0.20 > 10.0.0.254: ICMP host 130.158.XY.ZZ6 unreachable - admin prohibited, length 77 |
| 269 | 03:00:07.924515 IP 10.0.0.20 > 10.0.0.254: ICMP host 130.158.XY.ZZ6 unreachable - admin prohibited, length 77 |
| 270 | }}} |
| 271 | * centos-outer ~]$ sudo iptables -L |
| 272 | {{{ |
| 273 | Chain INPUT (policy ACCEPT) |
| 274 | target prot opt source destination |
| 275 | RH-Firewall-1-INPUT all -- anywhere anywhere |
| 276 | |
| 277 | Chain FORWARD (policy ACCEPT) |
| 278 | target prot opt source destination |
| 279 | RH-Firewall-1-INPUT all -- anywhere anywhere |
| 280 | |
| 281 | Chain OUTPUT (policy ACCEPT) |
| 282 | target prot opt source destination |
| 283 | |
| 284 | Chain RH-Firewall-1-INPUT (2 references) |
| 285 | target prot opt source destination |
| 286 | ACCEPT all -- anywhere anywhere |
| 287 | ACCEPT icmp -- anywhere anywhere icmp any |
| 288 | ACCEPT esp -- anywhere anywhere |
| 289 | ACCEPT ah -- anywhere anywhere |
| 290 | ACCEPT udp -- anywhere 224.0.0.251 udp dpt:mdns |
| 291 | ACCEPT udp -- anywhere anywhere udp dpt:ipp |
| 292 | ACCEPT tcp -- anywhere anywhere tcp dpt:ipp |
| 293 | ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED |
| 294 | ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh |
| 295 | REJECT all -- anywhere anywhere reject-with icmp-host-prohibited |
| 296 | }}} |
| 297 | * おそらくreject-with icmp-host-prohibitedがネックなのだが、とりあえずfilterをflushして対応(FW無効と同義なので注意) |
| 298 | * centos-outer ~]$ sudo iptables -F |
| 299 | * centos-outer ~]$ sudo iptables -L |
| 300 | {{{ |
| 301 | Chain INPUT (policy ACCEPT) |
| 302 | target prot opt source destination |
| 303 | |
| 304 | Chain FORWARD (policy ACCEPT) |
| 305 | target prot opt source destination |
| 306 | |
| 307 | Chain OUTPUT (policy ACCEPT) |
| 308 | target prot opt source destination |
| 309 | |
| 310 | Chain RH-Firewall-1-INPUT (0 references) |
| 311 | target prot opt source destination |
| 312 | }}} |
| 313 | * これで名前解決も出来るようになった |
| 314 | * ubuntu-inner-BB:~$ host M.ROOT-SERVERS.NET. |
| 315 | {{{ |
| 316 | M.ROOT-SERVERS.NET has address 202.12.27.33 |
| 317 | M.ROOT-SERVERS.NET has IPv6 address 2001:dc3::35 |
| 318 | }}} |