I'm doing a hardware refresh on a my Colo, I just need to copy my UFW rules from my old server to my new server. I dont seem to be able to get them copy all the active rules from my old server to my new one.

How do I copy my active UFW rules between servers?

  • 1
    I found it in /lib/ufw/user.rules and /lib/ufw/user6.rules. I copy that between server, deactivate and reactive ufw and the rules applied.
    – Squidly
    Oct 2, 2011 at 2:18
  • 2
    Squidly you can answer and accept your own answer to your question. It may help others who run into a similar problem as they may skip this question if they see it has 0 replies and doesn't have an accepted answer. Oct 2, 2011 at 2:30

4 Answers 4


I found the rules in /etc/ufw/user.rules and for ipv6 you can find the rules in /etc/ufw/user6.rules.

If you copy those files between the servers, disable and then re-enable ufw.

  • 4
    I couldn't find the rules in /lib/ufw on a recent installation of UFW. /etc/ufw seems to be the right place, Jan 12, 2018 at 5:23
  • 1
    This answer is no longer correct. The rules are in /etc/ufw/[after.init, before.init, ufw.conf, user.rules and so on]
    – Kurt
    Nov 3, 2019 at 15:44
  • where are comments kept? Feb 3, 2022 at 3:12

User configurations for UFW should be in /etc/ufw. You are not supposed to modify files in /lib nor /usr/lib nor any other similar locations, because your modifications might get overwritten by the vendor's default version after the packages upgraded.

From Ubuntu 16.04:

ls /etc/ufw

after6.rules applications.d before.rules user6.rules
after.init before6.rules sysctl.conf user.rules
after.rules before.init ufw.conf

  • Valid for Devuan 2.0 too
    – Joril
    Sep 6, 2018 at 9:07

Another solution could be:

Save current config with:

iptables-save >/to/some/filename

Then restore it with:

iptables-restore </to/some/filename

  • This is a bad approach since iptables-save would spit out all other rules not relevant to UFW rules (example: docker puts its stuff into iptables, fail2ban, custom rules like traffic shaping etc.) Much better approach would be to get "UFW only" rules from the /etc/ufw/ folder. Feb 21 at 15:25

Those /lib/ufw/user.rules /lib/ufw/user6.rules are just symlinks to /etc/ufw/user...

Copy those files from and to /etc/ufw directory

  • there are no symlinks in /bin/ufw/ in my recent ufw installation Jan 12, 2018 at 5:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.