ansible-ufw icon indicating copy to clipboard operation
ansible-ufw copied to clipboard

Add example for port forwarding

Open egeexyz opened this issue 6 years ago • 5 comments

The examples in the readme are quite good, however there is not an example that features Port Forwarding.

It would be great for folks looking for a comprehensive ufw role that supports port forwarding to see one in the examples because it is not clear from the readme if this role supports it.

egeexyz avatar Nov 21 '18 11:11 egeexyz

I have no idea too, do you have a terminal (or generic ansible) example?

tersmitten avatar Nov 21 '18 11:11 tersmitten

I have managed to do it with

- name: insert port forwarding for ufw
  lineinfile:
    dest: /etc/ufw/before.rules
    line: "{{ item }}"
  with_items:
    - '*nat'
    - ':POSTROUTING ACCEPT [0:0]'
    - "-A POSTROUTING -s {{  }} -o ens5 -j MASQUERADE \nCOMMIT"

oneslash avatar Jan 04 '19 13:01 oneslash

I think it would be better to template /etc/ufw/before.rules. See https://github.com/Oefenweb/ansible-dnsmasq/blob/master/templates/etc/default/dnsmasq.j2 for instance

tersmitten avatar Jan 07 '19 08:01 tersmitten

But there're probably more files that (might) need templating:

-rw-r-----   1 root root  915 jul 19  2017 after6.rules
-rw-r-----   1 root root 1,1K jul 19  2016 after.init
-rw-r-----   1 root root 1004 jul 19  2017 after.rules
drwxr-xr-x   2 root root 4,0K dec 11 06:14 applications.d
-rw-r-----   1 root root 6,3K jul 19  2017 before6.rules
-rw-r-----   1 root root 1,2K jul 19  2016 before.init
-rw-r-----   1 root root 2,7K jul 19  2017 before.rules
-rw-r--r--   1 root root 1,9K apr 15  2016 sysctl.conf
-rw-r--r--   1 root root  313 mrt 26  2018 ufw.conf
-rw-r-----   1 root root 1,6K jul  6  2018 user6.rules
-rw-r-----   1 root root 1,6K jul  6  2018 user.rules

tersmitten avatar Jan 07 '19 08:01 tersmitten

See #21

tersmitten avatar Jan 07 '19 08:01 tersmitten