This page (revision-12) was last changed on 23-Apr-2022 17:06 by Harry Metske

This page was created on 23-Apr-2022 17:05 by Harry Metske

Only authorized users are allowed to rename pages.

Only authorized users are allowed to delete pages.

Page revision history

Version Date Modified Size Author Changes ... Change note
12 23-Apr-2022 17:06 18 KB Harry Metske to previous
11 23-Apr-2022 17:05 17 KB Harry Metske to previous | to last
10 23-Apr-2022 17:05 17 KB Harry Metske to previous | to last
9 23-Apr-2022 17:05 16 KB Harry Metske to previous | to last
8 23-Apr-2022 17:05 14 KB Harry Metske to previous | to last
7 23-Apr-2022 17:05 13 KB Harry Metske to previous | to last
6 23-Apr-2022 17:05 13 KB Harry Metske to previous | to last
5 23-Apr-2022 17:05 12 KB Harry Metske to previous | to last
4 23-Apr-2022 17:05 11 KB Harry Metske to previous | to last
3 23-Apr-2022 17:05 5 KB Harry Metske to previous | to last
2 23-Apr-2022 17:05 2 KB Harry Metske to previous | to last
1 23-Apr-2022 17:05 2 KB Harry Metske to last

Page References

Incoming links Outgoing links

Version management

Difference between version and

At line 67 added 21 lines
! Create container on it's own lv.
%%small
{{{
root@apollo# lxc-create -t ubuntu -n cn3 -B lvm --vgname vg0 --fstype ext4
No config file specified, using the default config
Logical volume "cn3" created
mke2fs 1.42 (29-Nov-2011)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
65536 inodes, 262144 blocks
13107 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
At line 89 added 19 lines
Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
debootstrap is /usr/sbin/debootstrap
Checking cache download in /var/cache/lxc/precise/rootfs-i386 ...
Copy /var/cache/lxc/precise/rootfs-i386 to /var/lib/lxc/cn3/rootfs ...
Copying rootfs to /var/lib/lxc/cn3/rootfs ...
##
# The default user is 'ubuntu' with password 'ubuntu'!
# Use the 'sudo' command to run tasks as root in the container.
##
'ubuntu' template installed
Unmounting LVM
'cn3' created
}}} %%
At line 416 changed one line
! TODO => how to get network access to the container(s) from other hosts than the "hypervisor" host.
__Do not__ specify an {{lxc.network.ipv4}} in {{/var/lib/lxc/<cn>/config}}, and specify the following in {{/etc/network/interfaces}}:
{{{
auto lo
iface lo inet loopback
At line 461 added 11 lines
auto eth0
# iface eth0 inet dhcp
iface eth0 inet static
address 10.0.3.12
netmask 255.255.255.0
broadcast 10.0.3.255
gateway 10.0.3.1
post-up route add default gw 10.0.3.1 dev eth0
dns-nameservers 213.197.28.3 213.197.30.28
dns-search computerhok.nl
}}}
At line 473 added 64 lines
Now we have another private network for our containers. You can only reach these containers from the host itself.
If you want to reach them from another laptop over wifi, you have two options:
* you can add static routes to these containers:
{{{
metskem@athena ~ $ sudo route add 10.0.3.11 gw 10.0.0.150
metskem@athena ~ $ sudo route add 10.0.3.12 gw 10.0.0.150
metskem@athena ~ $ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.0.0.138 0.0.0.0 UG 0 0 0 wlan0
10.0.0.0 0.0.0.0 255.0.0.0 U 9 0 0 wlan0
10.0.3.11 10.0.0.150 255.255.255.255 UGH 0 0 0 wlan0
10.0.3.12 10.0.0.150 255.255.255.255 UGH 0 0 0 wlan0
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 wlan0
metskem@athena ~ $
}}}
* (better), use the firewall on the container host to forward ports:
{{{
iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 1180 -j DNAT --to 10.0.3.11:80
iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 1280 -j DNAT --to 10.0.3.12:80
iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 1122 -j DNAT --to 10.0.3.11:22
iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 1222 -j DNAT --to 10.0.3.12:22
}}}
This results in the following iptables:
{{{
root@apollo:/var/lib/lxc/cn1# iptables -vnL -t nat
Chain PREROUTING (policy ACCEPT 54 packets, 7138 bytes)
pkts bytes target prot opt in out source destination
0 0 DNAT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:1180 to:10.0.3.11:80
0 0 DNAT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:1280 to:10.0.3.12:80
2 120 DNAT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:1122 to:10.0.3.11:22
1 60 DNAT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:1222 to:10.0.3.12:22
Chain INPUT (policy ACCEPT 17 packets, 2581 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain POSTROUTING (policy ACCEPT 3 packets, 180 bytes)
pkts bytes target prot opt in out source destination
29 2037 MASQUERADE all -- * * 10.0.3.0/24 !10.0.3.0/24
root@apollo:/var/lib/lxc/cn1#
}}}
This last NATing can also be used to direct traffic from the wireless modem, for example the 22 and 80 ports :
[Single Port Forwarding.png]
!!! Remote "copying" containers.
We want to be able to have remote backup of the containers.\\
A very simple straight-forward way is :
* on the target host, remove (or rename temporary) {{/var/lib/lxc/cn1/rootfs}}
* on the source host, issue :
{{{
root@apollo:/var/lib/lxc/cn1# tar -c rootfs | ssh 10.0.0.164 tar -x -C /var/lib/lxc/cn1
}}}
This will copy the complete root filesystem of container {{cn1}} to the other host at 10.0.0.164.
There is always at least one file to change after this action, and that is the ip address in {{/etc/network/interfaces}}