fork 0k-charms
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.

111 lines
2.2 KiB

  1. #!/bin/bash
  2. [ "$LXC_NETWORK" ] || {
  3. echo "You must set \$LXC_NETWORK (to something like 172.160.0 ) before using this script."
  4. exit 1
  5. }
  6. HOST_EXTERNAL_DEVICE=${HOST_EXTERNAL_DEVICE:-eth0}
  7. apt-get install -y bind9 dnsmasq
  8. echo HOST_EXTERNAL_DEVICE="$HOST_EXTERNAL_DEVICE" >> /etc/default/lxc
  9. sed -ri "s%10\.0\.3\.%$LXC_NETWORK.%g;s%^#LXC_DHCP_CONFILE=%LXC_DHCP_CONFILE=%g" /etc/default/lxc-net
  10. LXC_ADDR=$(. /etc/default/lxc && echo "$LXC_ADDR")
  11. if [ -z "$LXC_ADDR" ]; then
  12. LXC_ADDR=$(. <(cat /usr/lib/x86_64-linux-gnu/lxc/lxc-net | grep ^LXC_ADDR | head -n 1) && echo "$LXC_ADDR")
  13. fi
  14. HOST_IP=$(. /etc/default/lxc && ifip "$HOST_EXTERNAL_DEVICE")
  15. echo "
  16. server=$LXC_ADDR
  17. interface=lo
  18. no-negcache
  19. log-queries
  20. log-facility=/var/log/dnsmasq.log
  21. " >> /etc/dnsmasq.conf
  22. echo "
  23. server=${HOST_IP}
  24. log-queries
  25. no-negcache
  26. log-facility=/var/log/lxc-dnsmasq.log
  27. " >> /etc/lxc/dnsmasq.conf
  28. (
  29. cp "src/etc/bind/named.conf.options" "/etc/bind/named.conf.options" &&
  30. sed -ri "s/%%EXTERNAL_IP%%/$HOST_IP/g" "/etc/bind/named.conf.options"
  31. )
  32. ## XXXvlab: Maybe we could change this in the service start/stop of the named daemon
  33. mkdir /var/log/named -p &&
  34. chown bind:bind /var/log/named
  35. /etc/init.d/bind9 restart
  36. /etc/init.d/dnsmasq restart
  37. service lxc restart
  38. service lxc-net restart ## had to 'brctl delbr lxcbr0' myself
  39. cp /etc/resolv.conf{,.orig}
  40. cat <<EOF > /etc/resolv.conf
  41. nameserver 127.0.0.1
  42. #domain . ## didn't work on 12.04
  43. search localdomain ## imperfect, we don't want to search www.localdomain
  44. EOF
  45. ##
  46. ## Logrotate for dnsmasq and named
  47. ##
  48. cat <<EOF > /etc/logrotate.d/dnsmasq
  49. /var/log/dnsmasq.log {
  50. missingok
  51. copytruncate
  52. notifempty
  53. compress
  54. postrotate
  55. kill -s SIGUSR2 "\$(cat /var/run/dnsmasq/dnsmasq.pid)"
  56. endscript
  57. }
  58. EOF
  59. cat <<EOF > /etc/logrotate.d/lxc-dnsmasq
  60. /var/log/lxc-dnsmasq.log {
  61. missingok
  62. copytruncate
  63. notifempty
  64. compress
  65. postrotate
  66. kill -s SIGUSR2 "\$(cat /var/run/lxc/dnsmasq.pid)"
  67. endscript
  68. }
  69. EOF
  70. cat <<EOF > /etc/logrotate.d/named
  71. /var/log/named/*.log {
  72. missingok
  73. copytruncate
  74. notifempty
  75. compress
  76. }
  77. EOF
  78. ##
  79. ## Testing
  80. ##
  81. # lsof -i4tcp:53 -n
  82. # netstat -ltnp | grep :53
  83. # ping HOST
  84. # host HOST
  85. # tcpdump