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.

73 lines
1.6 KiB

  1. #!/bin/bash
  2. ##
  3. ## shorewall
  4. ##
  5. apt-get install -y shorewall
  6. cat <<EOF > /etc/shorewall/zones
  7. fw firewall
  8. net ipv4
  9. lan ipv4
  10. EOF
  11. cat <<EOF > /etc/shorewall/interfaces
  12. #ZONE INTERFACE BROADCAST OPTIONS
  13. net eth0
  14. ## Uncomment to enable vpn setup
  15. #vpn tun0 detect
  16. lan lxcbr0 - routeback
  17. EOF
  18. cat <<EOF > /etc/shorewall/policy
  19. #SOURCE DEST RULE LOG
  20. fw all ACCEPT
  21. lan all ACCEPT
  22. net all DROP info
  23. all all DROP info
  24. EOF
  25. cat <<EOF > /etc/shorewall/rules
  26. SSH/ACCEPT net fw
  27. Ping/ACCEPT net fw
  28. BEGIN SHELL
  29. host_ip="\$(/sbin/ifconfig eth0 2> /dev/null | sed "s/^.*inet ad\+r://g" | grep ^[0-9] | sed "s/ .*$//g")"
  30. for name in \$(lxc-ls-running); do
  31. ip=\$(dig +short A "\$name")
  32. [ -e "/var/lib/lxc/\$name/shorewall" ] &&
  33. cat /var/lib/lxc/\$name/shorewall | sed -r "s/%%HOST_INTERNET_IP%%/\$host_ip/g" \
  34. | sed -r "s/%%IP%%/\$ip/g"
  35. done
  36. true
  37. END SHELL
  38. EOF
  39. cat <<EOF > /etc/shorewall/masq
  40. eth0 lxcbr0
  41. EOF
  42. cat <<EOF > /etc/shorewall/start
  43. ## correct a bug that prevent DHCP packet to be correctly sent between
  44. ## LXC, preventing them to receive an IP.
  45. . /etc/default/lxc
  46. if [ -d "/sys/class/net/\$LXC_BRIDGE" -a "\$(cat /sys/class/net/\$LXC_BRIDGE/operstate)" == "up" ]; then
  47. source_file=/etc/init/lxc-net.conf
  48. code=\$(egrep '^\s+iptables.*\s+-j\s+' /etc/init/lxc-net.conf | grep -v '\-D' | sed -r 's/^\s+[^-]+/run_iptables /g')
  49. echo "Adding LXC rules:"
  50. echo "\$code"
  51. eval "\$code"
  52. fi
  53. EOF