---
title: "config ufw for router purpose"
author: "mathgl"
date: "2014-01-03T11:22:14Z"
tags: []
categories: ["非技术"]
slug: "config-ufw-for-router-purpose"
draft: false
lastmod: "2014-01-03T11:23:06Z"
id: 1998627
url: "https://mathgl.iteye.com/blog/1998627"
---

sometimes we need to share our internect connection without losing any protection, here ufw can help us.

 

1:

open /etc/default/ufw

change DEFAULT\_FORWARD\_POLICY = "ACCEPT"

             DEFAULT\_INCOMING\_POLICY = "ACCEPT"

 

2: open /etc/ufw/sysctl.conf and uncomment

   net/ipv4/ip\_forward=1

  for ipv6 net/ipv6/conf/default/forwarding=1

 

3: add rules to the /etc/ufw/before.rules

right beneath \*filter rules

add

\*nat

:POSTROUTING ACCEPT \[0:0]

-A POSTROUTING -s 192.168.2.0/24 -o ppp0 -j MASQUERADE

 

sudo ufw disable & enable

 

done.