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.

116 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 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/dnsmasq start
  43. /etc/init.d/bind9 start
  44. cp /etc/resolv.conf{,.orig}
  45. cat <<EOF > /etc/resolv.conf
  46. nameserver 127.0.0.1
  47. EOF
  48. ##
  49. ## Logrotate for dnsmasq and named
  50. ##
  51. cat <<EOF > /etc/logrotate.d/dnsmasq
  52. /var/log/dnsmasq.log {
  53. missingok
  54. copytruncate
  55. notifempty
  56. compress
  57. postrotate
  58. /bin/kill -s SIGUSR2 "\$(cat /var/run/dnsmasq/dnsmasq.pid)"
  59. endscript
  60. }
  61. EOF
  62. cat <<EOF > /etc/logrotate.d/lxc-dnsmasq
  63. /var/log/lxc-dnsmasq.log {
  64. missingok
  65. copytruncate
  66. notifempty
  67. compress
  68. postrotate
  69. /bin/kill -s SIGUSR2 "\$(cat /var/run/lxc/dnsmasq.pid)"
  70. endscript
  71. }
  72. EOF
  73. cat <<EOF > /etc/logrotate.d/named
  74. /var/log/named/*.log {
  75. missingok
  76. copytruncate
  77. notifempty
  78. compress
  79. }
  80. EOF
  81. ##
  82. ## Testing
  83. ##
  84. # lsof -i4tcp:53 -n
  85. # netstat -ltnp | grep :53
  86. # ping HOST
  87. # host HOST
  88. # tcpdump