You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.8 KiB

  1. #!/bin/bash
  2. apt-get install lxc -y --force-yes </dev/null
  3. ## required to access the created lxc !
  4. if ! [ -e ~/.ssh/id_rsa ]; then
  5. ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa -q
  6. fi
  7. ## From: https://wiki.debian.org/LXC#Independent_bridge_setup
  8. lxc_net="$(cat /etc/lxc/default.conf |
  9. grep ^lxc.net.0.type |
  10. cut -f 2 -d = |
  11. xargs echo)"
  12. if [ "$lxc_net" == "empty" ]; then
  13. ## Boggers, we are on default unconfigured networks for lxc
  14. sed -ri 's/^lxc.net.0.type = empty/lxc.net.0.type = veth\nlxc.net.0.link = lxcbr0\nlxc.net.0.flags = up\nlxc.net.0.hwaddr = 00:16:3e:xx:xx:xx/g' /etc/lxc/default.conf
  15. [ -e "/etc/default/lxc-net" ] || {
  16. cat <<EOF > /etc/default/lxc-net
  17. USE_LXC_BRIDGE="true"
  18. # If you change the LXC_BRIDGE to something other than lxcbr0, then
  19. # you will also need to update your /etc/lxc/default.conf as well as the
  20. # configuration (/var/lib/lxc/<container>/config) for any containers
  21. # already created using the default config to reflect the new bridge
  22. # name.
  23. # If you have the dnsmasq daemon installed, you'll also have to update
  24. # /etc/dnsmasq.d/lxc and restart the system wide dnsmasq daemon.
  25. LXC_BRIDGE="lxcbr0"
  26. LXC_ADDR="172.101.0.1"
  27. LXC_NETMASK="255.255.255.0"
  28. LXC_NETWORK="172.101.0.0/24"
  29. LXC_DHCP_RANGE="172.101.0.2,172.101.0.254"
  30. LXC_DHCP_MAX="253"
  31. # Uncomment the next line if you'd like to use a conf-file for the lxcbr0
  32. # dnsmasq. For instance, you can use 'dhcp-host=mail1,172.46.0.100' to have
  33. # container 'mail1' always get ip address 172.46.0.100.
  34. LXC_DHCP_CONFILE=/etc/lxc/dnsmasq.conf
  35. # Uncomment the next line if you want lxcbr0's dnsmasq to resolve the .lxc
  36. # domain. You can then add "server=/lxc/172.46.0.1' (or your actual )
  37. # to /etc/dnsmasq.conf, after which 'container1.lxc' will resolve on your
  38. # host.
  39. #LXC_DOMAIN="lxc"
  40. EOF
  41. }
  42. service lxc-net restart
  43. fi