| 100 | |
| 101 | = USE_LXC_BRIDGE="false" = |
| 102 | * 手動でLXCコンテナのNAT設定を行う |
| 103 | * eth0 -> br0にブリッジされていて、KVMで使用 |
| 104 | * LXCとKVMの共存のテスト |
| 105 | |
| 106 | == ip forwarding == |
| 107 | * mitty@precise:~$ cat /etc/sysctl.d/60-ip_forward.conf |
| 108 | {{{ |
| 109 | net.ipv4.ip_forward=1 |
| 110 | net.ipv6.conf.all.forwarding=1 |
| 111 | }}} |
| 112 | |
| 113 | * mitty@precise:~$ cat /etc/network/interfaces |
| 114 | {{{ |
| 115 | # This file describes the network interfaces available on your system |
| 116 | # and how to activate them. For more information, see interfaces(5). |
| 117 | |
| 118 | # The loopback network interface |
| 119 | auto lo |
| 120 | iface lo inet loopback |
| 121 | |
| 122 | # The primary network interface |
| 123 | auto eth0 |
| 124 | iface eth0 inet manual |
| 125 | |
| 126 | auto br0 |
| 127 | iface br0 inet dhcp |
| 128 | bridge_ports eth0 eth0 |
| 129 | bridge_maxwait 0 |
| 130 | |
| 131 | auto lxcbr0 |
| 132 | iface lxcbr0 inet static |
| 133 | bridge_ports none |
| 134 | bridge_maxwait 0 |
| 135 | address 10.0.0.254 |
| 136 | netmask 255.255.255.0 |
| 137 | post-up iptables -A POSTROUTING -s 10.0.0.0/24 -t nat -j MASQUERADE |
| 138 | pre-down iptables -D POSTROUTING -s 10.0.0.0/24 -t nat -j MASQUERADE |
| 139 | }}} |
| 140 | |
| 141 | == change apt repository mirror and disable auto start lxcbr0 == |
| 142 | * デフォルトのミラーが遅いので、ftp.tsukubaに変更 |
| 143 | * lxcの起動スクリプトによるlxcbr0の作成を抑制 |
| 144 | |
| 145 | * mitty@precise:~$ cat /etc/default/lxc |
| 146 | {{{ |
| 147 | MIRROR="http://ftp.tsukuba.wide.ad.jp/Linux/ubuntu" |
| 148 | |
| 149 | USE_LXC_BRIDGE="false" |
| 150 | }}} |
| 151 | |
| 152 | == host settings == |
| 153 | |
| 154 | * mitty@precise:~$ ifconfig -a |
| 155 | {{{ |
| 156 | br0 Link encap:Ethernet HWaddr 52:54:00:bc:53:bc |
| 157 | inet addr:192.168.10.172 Bcast:192.168.10.255 Mask:255.255.255.0 |
| 158 | inet6 addr: fe80::5054:ff:febc:53bc/64 Scope:Link |
| 159 | UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 |
| 160 | RX packets:1340 errors:0 dropped:0 overruns:0 frame:0 |
| 161 | TX packets:948 errors:0 dropped:0 overruns:0 carrier:0 |
| 162 | collisions:0 txqueuelen:0 |
| 163 | RX bytes:116870 (116.8 KB) TX bytes:111171 (111.1 KB) |
| 164 | |
| 165 | eth0 Link encap:Ethernet HWaddr 52:54:00:bc:53:bc |
| 166 | UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 |
| 167 | RX packets:1400 errors:0 dropped:0 overruns:0 frame:0 |
| 168 | TX packets:945 errors:0 dropped:0 overruns:0 carrier:0 |
| 169 | collisions:0 txqueuelen:1000 |
| 170 | RX bytes:150975 (150.9 KB) TX bytes:110725 (110.7 KB) |
| 171 | |
| 172 | lo Link encap:Local Loopback |
| 173 | inet addr:127.0.0.1 Mask:255.0.0.0 |
| 174 | inet6 addr: ::1/128 Scope:Host |
| 175 | UP LOOPBACK RUNNING MTU:16436 Metric:1 |
| 176 | RX packets:0 errors:0 dropped:0 overruns:0 frame:0 |
| 177 | TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 |
| 178 | collisions:0 txqueuelen:0 |
| 179 | RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) |
| 180 | |
| 181 | lxcbr0 Link encap:Ethernet HWaddr 4a:5a:12:a4:0a:ac |
| 182 | inet addr:10.0.0.254 Bcast:10.0.0.255 Mask:255.255.255.0 |
| 183 | inet6 addr: fe80::485a:12ff:fea4:aac/64 Scope:Link |
| 184 | UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 |
| 185 | RX packets:0 errors:0 dropped:0 overruns:0 frame:0 |
| 186 | TX packets:4 errors:0 dropped:0 overruns:0 carrier:0 |
| 187 | collisions:0 txqueuelen:0 |
| 188 | RX bytes:0 (0.0 B) TX bytes:408 (408.0 B) |
| 189 | }}} |
| 190 | |
| 191 | * mitty@precise:~$ ip route |
| 192 | {{{ |
| 193 | default via 192.168.10.254 dev br0 metric 100 |
| 194 | 10.0.0.0/24 dev lxcbr0 proto kernel scope link src 10.0.0.254 |
| 195 | 192.168.10.0/24 dev br0 proto kernel scope link src 192.168.10.172 |
| 196 | }}} |
| 197 | |
| 198 | * mitty@precise:~$ brctl show |
| 199 | {{{ |
| 200 | bridge name bridge id STP enabled interfaces |
| 201 | br0 8000.525400bc53bc no eth0 |
| 202 | lxcbr0 8000.000000000000 no |
| 203 | }}} |
| 204 | |
| 205 | === iptables on host === |
| 206 | * mitty@precise:~$ sudo iptables -L -t nat -vx |
| 207 | {{{ |
| 208 | Chain PREROUTING (policy ACCEPT 30 packets, 10827 bytes) |
| 209 | pkts bytes target prot opt in out source destination |
| 210 | |
| 211 | Chain INPUT (policy ACCEPT 4 packets, 323 bytes) |
| 212 | pkts bytes target prot opt in out source destination |
| 213 | |
| 214 | Chain OUTPUT (policy ACCEPT 83 packets, 5999 bytes) |
| 215 | pkts bytes target prot opt in out source destination |
| 216 | |
| 217 | Chain POSTROUTING (policy ACCEPT 83 packets, 5999 bytes) |
| 218 | pkts bytes target prot opt in out source destination |
| 219 | 0 0 MASQUERADE all -- any any 10.0.0.0/24 anywhere |
| 220 | }}} |
| 221 | |
| 222 | * MASQUERADEが正しく設定されている |
| 223 | |
| 224 | == make LXC container with ubuntu template == |
| 225 | * mitty@precise:~$ sudo lxc-create -t ubuntu -n lxc-test |
| 226 | {{{ |
| 227 | |
| 228 | No config file specified, using the default config |
| 229 | debootstrap is /usr/sbin/debootstrap |
| 230 | Checking cache download in /var/cache/lxc/precise/rootfs-amd64 ... |
| 231 | installing packages: vim,ssh |
| 232 | Downloading ubuntu precise minimal ... |
| 233 | I: Retrieving Release |
| 234 | I: Retrieving Release.gpg |
| 235 | I: Checking Release signature |
| 236 | |
| 237 | .... |
| 238 | |
| 239 | I: Checking component main on http://ftp.tsukuba.wide.ad.jp/Linux/ubuntu... |
| 240 | |
| 241 | .... |
| 242 | |
| 243 | Processing triggers for initramfs-tools ... |
| 244 | Download complete |
| 245 | Copy /var/cache/lxc/precise/rootfs-amd64 to /var/lib/lxc/lxc-test/rootfs ... |
| 246 | Copying rootfs to /var/lib/lxc/lxc-test/rootfs ... |
| 247 | |
| 248 | ## |
| 249 | # The default user is 'ubuntu' with password 'ubuntu'! |
| 250 | # Use the 'sudo' command to run tasks as root in the container. |
| 251 | ## |
| 252 | |
| 253 | 'ubuntu' template installed |
| 254 | 'lxc-test' created |
| 255 | }}} |
| 256 | |
| 257 | === set container IP with LXC/config === |
| 258 | * LXCコンテナのconfigファイルからIPアドレスを指定する |
| 259 | * 結論としては、デフォルトゲートウェイなどを設定できないので、不便 |
| 260 | |
| 261 | * mitty@precise:~$ sudo vim /var/lib/lxc/lxc-test/config |
| 262 | {{{ |
| 263 | lxc.network.ipv4 = 10.0.0.10/24 |
| 264 | }}} |
| 265 | |
| 266 | * mitty@precise:~$ sudo lxc-start -n lxc-test -d |
| 267 | * mitty@precise:~$ ping 10.0.0.10 -c 1 |
| 268 | {{{ |
| 269 | PING 10.0.0.10 (10.0.0.10) 56(84) bytes of data. |
| 270 | 64 bytes from 10.0.0.10: icmp_req=1 ttl=64 time=0.060 ms |
| 271 | |
| 272 | --- 10.0.0.10 ping statistics --- |
| 273 | 1 packets transmitted, 1 received, 0% packet loss, time 0ms |
| 274 | rtt min/avg/max/mdev = 0.060/0.060/0.060/0.000 ms |
| 275 | }}} |
| 276 | |
| 277 | * mitty@precise:~$ ssh 10.0.0.10 -l ubuntu |
| 278 | * ubuntu@lxc-test:~$ ifconfig |
| 279 | {{{ |
| 280 | eth0 Link encap:Ethernet HWaddr 00:16:3e:ba:3e:ef |
| 281 | inet addr:10.0.0.10 Bcast:10.0.0.255 Mask:255.255.255.0 |
| 282 | }}} |
| 283 | * ubuntu@lxc-test:~$ ip route |
| 284 | {{{ |
| 285 | 10.0.0.0/24 dev eth0 proto kernel scope link src 10.0.0.10 |
| 286 | }}} |
| 287 | * ubuntu@lxc-test:~$ ping 8.8.8.8 |
| 288 | {{{ |
| 289 | connect: Network is unreachable |
| 290 | }}} |
| 291 | |
| 292 | === set container IP with interfaces === |
| 293 | * ホストOS上から、あらかじめコンテナのinterfacesファイルを設定して、起動する |
| 294 | * 間違いが無く、かつ楽そう |
| 295 | |
| 296 | * mitty@precise:~$ sudo vim /var/lib/lxc/lxc-test/rootfs/etc/network/interfaces |
| 297 | {{{ |
| 298 | auto eth0 |
| 299 | iface eth0 inet static |
| 300 | address 10.0.0.1 |
| 301 | netmask 255.255.255.0 |
| 302 | gateway 10.0.0.254 |
| 303 | }}} |
| 304 | |
| 305 | * mitty@precise:~$ ssh 10.0.0.1 -l ubuntu |
| 306 | * ubuntu@lxc-test:~$ ifconfig |
| 307 | {{{ |
| 308 | eth0 Link encap:Ethernet HWaddr 00:16:3e:ba:3e:ef |
| 309 | inet addr:10.0.0.1 Bcast:10.0.0.255 Mask:255.255.255.0 |
| 310 | }}} |
| 311 | * ubuntu@lxc-test:~$ ip route |
| 312 | {{{ |
| 313 | default via 10.0.0.254 dev eth0 metric 100 |
| 314 | 10.0.0.0/24 dev eth0 proto kernel scope link src 10.0.0.1 |
| 315 | }}} |
| 316 | * ubuntu@lxc-test:~$ ping 8.8.8.8 -c 1 |
| 317 | {{{ |
| 318 | PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data. |
| 319 | 64 bytes from 8.8.8.8: icmp_req=1 ttl=52 time=7.66 ms |
| 320 | |
| 321 | --- 8.8.8.8 ping statistics --- |
| 322 | 1 packets transmitted, 1 received, 0% packet loss, time 0ms |
| 323 | rtt min/avg/max/mdev = 7.667/7.667/7.667/0.000 ms |
| 324 | }}} |