Hallo,
für gelegentliches Programmieren möchte ich auf meinem PC nun lighty+php und mysql in LXC-Container verfrachten. Mein PC verwendet Ubuntu Gnome 14.04. - hat also den NetworkManager und nur das Paket dnsmasq-base ist installiert. Mein PC verfügt über eine normale Netzwerkkarte eth0 die an meine Fritzbox angeschlossen ist.
Meine Container sollen nun Zugriff ins Internet haben (um Pakete installieren zu können) und auch auf mein LAN haben.
Das Erstellen von Ubuntu-Container(trusty) klappt ohne Probleme.
IP meines PC: 192.168.177.20 (manuell festgelegt) IP der Fritzbox: 192.168.177.1 DCHP-Bereich der Fritzbox: 192.168.177.70-99
Die /etc/default/lxc-net habe ich folgendermaßen abgeändert:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | # This file is auto-generated by lxc.postinst if it does not # exist. Customizations will not be overridden. # Leave USE_LXC_BRIDGE as "true" if you want to use lxcbr0 for your # containers. Set to "false" if you'll use virbr0 or another existing # bridge, or mavlan to your host's NIC. USE_LXC_BRIDGE="true" # If you change the LXC_BRIDGE to something other than lxcbr0, then # you will also need to update your /etc/lxc/default.conf as well as the # configuration (/var/lib/lxc/<container>/config) for any containers # already created using the default config to reflect the new bridge # name. # If you have the dnsmasq daemon installed, you'll also have to update # /etc/dnsmasq.d/lxc and restart the system wide dnsmasq daemon. LXC_BRIDGE="lxcbr0" LXC_ADDR="192.168.177.130" LXC_NETMASK="255.255.255.0" LXC_NETWORK="192.168.177.0/24" LXC_DHCP_RANGE="192.168.177.132,192.168.177.139" LXC_DHCP_MAX="8" # Uncomment the next line if you'd like to use a conf-file for the lxcbr0 # dnsmasq. For instance, you can use 'dhcp-host=mail1,10.0.3.100' to have # container 'mail1' always get ip address 10.0.3.100. #LXC_DHCP_CONFILE=/etc/lxc/dnsmasq.conf # Uncomment the next line if you want lxcbr0's dnsmasq to resolve the .lxc # domain. You can then add "server=/lxc/10.0.3.1' (or your actual $LXC_ADDR) # to your system dnsmasq configuration file (normally /etc/dnsmasq.conf, # or /etc/NetworkManager/dnsmasq.d/lxc.conf on systems that use NetworkManager). # Once these changes are made, restart the lxc-net and network-manager services. # 'container1.lxc' will then resolve on your host. LXC_DOMAIN="lxc" |
/etc/NetworkManager/dnsmasq.d/lxc.conf
1 | server=/lxc/192.168.177.130 |
Config des Containers unter /var/lib/lxc/ubu14lts/config
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | # Template used to create this container: /usr/share/lxc/templates/lxc-ubuntu # For additional config options, please look at lxc.container.conf(5) # Uncomment the following line to support nesting containers: #lxc.include = /usr/share/lxc/config/nesting.conf # (Be aware this has security implications) # Common configuration lxc.include = /usr/share/lxc/config/ubuntu.common.conf # Container specific configuration lxc.rootfs = /var/lib/lxc/ubu14lts/rootfs lxc.rootfs.backend = dir lxc.utsname = ubu14lts lxc.arch = amd64 # Network configuration lxc.network.type = veth lxc.network.link = lxcbr0 lxc.network.flags = up lxc.network.hwaddr = 00:16:3e:54:9d:5f |
Container-Info + ping-test
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | lxc-info -n ubu14lts Name: ubu14lts State: RUNNING PID: 2956 IP: 192.168.177.97 CPU use: 1.15 seconds Memory use: 27.73 MiB KMem use: 0 bytes Link: veth0S1NXH TX bytes: 3.42 KiB RX bytes: 8.88 KiB Total bytes: 12.30 KiB lxc-attach -n ubu14lts root@ubu14lts:/# ping 192.168.177.1 PING 192.168.177.1 (192.168.177.1) 56(84) bytes of data. 64 bytes from 192.168.177.1: icmp_seq=1 ttl=64 time=0.400 ms 64 bytes from 192.168.177.1: icmp_seq=2 ttl=64 time=0.396 ms ^C --- 192.168.177.1 ping statistics --- 2 packets transmitted, 2 received, 0% packet loss, time 999ms rtt min/avg/max/mdev = 0.396/0.398/0.400/0.002 ms root@ubu14lts:/# ping 8.8.8.8 PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data. 64 bytes from 8.8.8.8: icmp_seq=1 ttl=46 time=50.0 ms 64 bytes from 8.8.8.8: icmp_seq=2 ttl=46 time=49.9 ms ^C --- 8.8.8.8 ping statistics --- 2 packets transmitted, 2 received, 0% packet loss, time 1001ms rtt min/avg/max/mdev = 49.925/49.975/50.026/0.229 ms |
ifconfig Mein Host-PC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | eth0 Link encap:Ethernet Hardware Adresse bc:ee:7b:9b:2c:98 UP BROADCAST RUNNING MULTICAST MTU:1500 Metrik:1 RX-Pakete:116 Fehler:0 Verloren:0 Überläufe:0 Fenster:0 TX-Pakete:126 Fehler:0 Verloren:0 Überläufe:0 Träger:0 Kollisionen:0 Sendewarteschlangenlänge:1000 RX-Bytes:19251 (19.2 KB) TX-Bytes:15588 (15.5 KB) lo Link encap:Lokale Schleife inet Adresse:127.0.0.1 Maske:255.0.0.0 inet6-Adresse: ::1/128 Gültigkeitsbereich:Maschine UP LOOPBACK RUNNING MTU:65536 Metrik:1 RX-Pakete:333 Fehler:0 Verloren:0 Überläufe:0 Fenster:0 TX-Pakete:333 Fehler:0 Verloren:0 Überläufe:0 Träger:0 Kollisionen:0 Sendewarteschlangenlänge:1 RX-Bytes:26556 (26.5 KB) TX-Bytes:26556 (26.5 KB) lxcbr0 Link encap:Ethernet Hardware Adresse 00:16:3e:00:00:00 inet Adresse:192.168.177.130 Bcast:0.0.0.0 Maske:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metrik:1 RX-Pakete:115 Fehler:0 Verloren:0 Überläufe:0 Fenster:0 TX-Pakete:126 Fehler:0 Verloren:0 Überläufe:0 Träger:0 Kollisionen:0 Sendewarteschlangenlänge:1000 RX-Bytes:17551 (17.5 KB) TX-Bytes:15588 (15.5 KB) |
ifconfig Container
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | root@ubu14lts:/# ifconfig eth0 Link encap:Ethernet Hardware Adresse 00:16:3e:54:9d:5f inet Adresse:192.168.177.97 Bcast:192.168.177.255 Maske:255.255.255.0 inet6-Adresse: fe80::216:3eff:fe54:9d5f/64 Gültigkeitsbereich:Verbindung UP BROADCAST RUNNING MULTICAST MTU:1500 Metrik:1 RX-Pakete:69 Fehler:0 Verloren:0 Überläufe:0 Fenster:0 TX-Pakete:38 Fehler:0 Verloren:0 Überläufe:0 Träger:0 Kollisionen:0 Sendewarteschlangenlänge:1000 RX-Bytes:9026 (9.0 KB) TX-Bytes:3828 (3.8 KB) lo Link encap:Lokale Schleife inet Adresse:127.0.0.1 Maske:255.0.0.0 inet6-Adresse: ::1/128 Gültigkeitsbereich:Maschine UP LOOPBACK RUNNING MTU:65536 Metrik:1 RX-Pakete:0 Fehler:0 Verloren:0 Überläufe:0 Fenster:0 TX-Pakete:0 Fehler:0 Verloren:0 Überläufe:0 Träger:0 Kollisionen:0 Sendewarteschlangenlänge:1 RX-Bytes:0 (0.0 B) TX-Bytes:0 (0.0 B) |
Lösche ich nun das hinterlegte Profil der eth0-Netzwerkkarte im Networkmanager und aktiviere ich die Netzwerkbrücke (lxcbr0; Verbindung an eth0 ist angegeben) kam es vor, dass ich vom Container aus auf LAN und Internet zugreifen konnte, mein Host-PC aber nur LAN und kein Internet mehr hatte.
Für weitere Hinweise oder Beispielkonfigurationen wäre ich sehr dankbar, ich denke da besteht noch Konfigurationsbedarf bei dnsmasq oder muss ich noch eine ipv4-Route im Host-PC/Fritzbox festlegen?? Wenn die Container ein eigenes Subnetz aber mit Zugang zum LAN/Internet hätten wäre das auch gut.