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.

118 lines
2.3 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 bind9-host </dev/null
  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. bind-interfaces
  19. no-negcache
  20. log-queries
  21. log-facility=/var/log/dnsmasq.log
  22. " >> /etc/dnsmasq.conf
  23. echo "
  24. server=${HOST_IP}
  25. bind-interfaces
  26. log-queries
  27. no-negcache
  28. log-facility=/var/log/lxc-dnsmasq.log
  29. no-resolv
  30. " >> /etc/lxc/dnsmasq.conf
  31. (
  32. cp "src/etc/bind/named.conf.options" "/etc/bind/named.conf.options" &&
  33. sed -ri "s/%%EXTERNAL_IP%%/$HOST_IP/g" "/etc/bind/named.conf.options"
  34. )
  35. ## XXXvlab: Maybe we could change this in the service start/stop of the named daemon
  36. mkdir /var/log/named -p &&
  37. chown bind:bind /var/log/named
  38. /etc/init.d/bind9 stop
  39. /etc/init.d/dnsmasq stop
  40. service lxc restart
  41. service lxc-net restart ## had to 'brctl delbr lxcbr0' myself
  42. /etc/init.d/bind9 start
  43. /etc/init.d/dnsmasq start
  44. cp /etc/resolv.conf{,.orig}
  45. cat <<EOF > /etc/resolv.conf
  46. nameserver 127.0.0.1
  47. #domain . ## didn't work on 12.04
  48. search localdomain ## imperfect, we don't want to search www.localdomain
  49. EOF
  50. ##
  51. ## Logrotate for dnsmasq and named
  52. ##
  53. cat <<EOF > /etc/logrotate.d/dnsmasq
  54. /var/log/dnsmasq.log {
  55. missingok
  56. copytruncate
  57. notifempty
  58. compress
  59. postrotate
  60. kill -s SIGUSR2 "\$(cat /var/run/dnsmasq/dnsmasq.pid)"
  61. endscript
  62. }
  63. EOF
  64. cat <<EOF > /etc/logrotate.d/lxc-dnsmasq
  65. /var/log/lxc-dnsmasq.log {
  66. missingok
  67. copytruncate
  68. notifempty
  69. compress
  70. postrotate
  71. kill -s SIGUSR2 "\$(cat /var/run/lxc/dnsmasq.pid)"
  72. endscript
  73. }
  74. EOF
  75. cat <<EOF > /etc/logrotate.d/named
  76. /var/log/named/*.log {
  77. missingok
  78. copytruncate
  79. notifempty
  80. compress
  81. }
  82. EOF
  83. ##
  84. ## Testing
  85. ##
  86. # lsof -i4tcp:53 -n
  87. # netstat -ltnp | grep :53
  88. # ping HOST
  89. # host HOST
  90. # tcpdump