main.yml 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. ---
  2. - name: Install iptables
  3. ansible.builtin.package:
  4. name:
  5. - iptables
  6. - iptables-persistent
  7. state: present
  8. - name: Enable masquerading on egress interface
  9. ansible.builtin.iptables:
  10. table: nat
  11. chain: POSTROUTING
  12. out_interface: "{{ router_egress_interface }}"
  13. jump: MASQUERADE
  14. notify: Save iptables rules
  15. - name: Allow incoming established connections from egress interface
  16. ansible.builtin.iptables:
  17. chain: FORWARD
  18. in_interface: "{{ router_egress_interface }}"
  19. out_interface: "{{ router_ingress_interface }}"
  20. ctstate: RELATED,ESTABLISHED
  21. jump: ACCEPT
  22. notify: Save iptables rules
  23. - name: Forward traffic from ingress to egress interfaces
  24. ansible.builtin.iptables:
  25. chain: FORWARD
  26. in_interface: "{{ router_ingress_interface }}"
  27. out_interface: "{{ router_egress_interface }}"
  28. jump: ACCEPT
  29. notify: Save iptables rules
  30. - name: Drop traffic not going over egress interface
  31. ansible.builtin.iptables:
  32. chain: FORWARD
  33. jump: DROP
  34. notify: Save iptables rules
  35. - name: Enable IP forwarding
  36. ansible.posix.sysctl:
  37. name: net.ipv4.ip_forward
  38. value: '1'