hash 修订了这个 Gist . 转到此修订
1 file changed, 2 insertions
ufw.md
@@ -1,5 +1,7 @@ | |||
1 | 1 | # UFW | |
2 | 2 | ||
3 | + | [Found on Github Gist](https://gist.github.com/kimus/9315140) | |
4 | + | ||
3 | 5 | I use Ubuntu’s Uncomplicated firewall because it is available on Ubuntu and it's very simple. | |
4 | 6 | ||
5 | 7 |
hash 修订了这个 Gist . 转到此修订
1 file changed, 74 insertions
ufw.md(文件已创建)
@@ -0,0 +1,74 @@ | |||
1 | + | # UFW | |
2 | + | ||
3 | + | I use Ubuntu’s Uncomplicated firewall because it is available on Ubuntu and it's very simple. | |
4 | + | ||
5 | + | ||
6 | + | ## Install UFW | |
7 | + | ||
8 | + | if ufw is not installed by default be sure to install it first. | |
9 | + | ||
10 | + | ``` | |
11 | + | $ sudo apt-get install ufw | |
12 | + | ``` | |
13 | + | ||
14 | + | ||
15 | + | ## NAT | |
16 | + | If you needed ufw to NAT the connections from the external interface to the internal the solution is pretty straight forward. | |
17 | + | In the file /etc/default/ufw change the parameter DEFAULT_FORWARD_POLICY | |
18 | + | ||
19 | + | ``` | |
20 | + | DEFAULT_FORWARD_POLICY="ACCEPT" | |
21 | + | ``` | |
22 | + | ||
23 | + | Also configure /etc/ufw/sysctl.conf to allow ipv4 forwarding (the parameters is commented out by default). Uncomment for ipv6 if you want. | |
24 | + | ||
25 | + | ``` | |
26 | + | net.ipv4.ip_forward=1 | |
27 | + | #net/ipv6/conf/default/forwarding=1 | |
28 | + | #net/ipv6/conf/all/forwarding=1 | |
29 | + | ``` | |
30 | + | ||
31 | + | ||
32 | + | The final step is to add NAT to ufw’s configuration. Add the following to /etc/ufw/before.rules just before the filter rules. | |
33 | + | ||
34 | + | ``` | |
35 | + | # NAT table rules | |
36 | + | *nat | |
37 | + | :POSTROUTING ACCEPT [0:0] | |
38 | + | ||
39 | + | # Forward traffic through eth0 - Change to match you out-interface | |
40 | + | -A POSTROUTING -s 192.168.1.0/24 -o eth0 -j MASQUERADE | |
41 | + | ||
42 | + | # don't delete the 'COMMIT' line or these nat table rules won't | |
43 | + | # be processed | |
44 | + | COMMIT | |
45 | + | ``` | |
46 | + | ||
47 | + | ||
48 | + | Now enable the changes by restarting ufw. | |
49 | + | ||
50 | + | ``` | |
51 | + | $ sudo ufw disable && sudo ufw enable | |
52 | + | ``` | |
53 | + | ||
54 | + | ||
55 | + | ## FORWARD | |
56 | + | ||
57 | + | For port forwardind just do something like this. | |
58 | + | ||
59 | + | ``` | |
60 | + | # NAT table rules | |
61 | + | *nat | |
62 | + | :PREROUTING ACCEPT [0:0] | |
63 | + | :POSTROUTING ACCEPT [0:0] | |
64 | + | ||
65 | + | # Port Forwardings | |
66 | + | -A PREROUTING -i eth0 -p tcp --dport 22 -j DNAT --to-destination 192.168.1.10 | |
67 | + | ||
68 | + | # Forward traffic through eth0 - Change to match you out-interface | |
69 | + | -A POSTROUTING -s 192.168.1.0/24 -o eth0 -j MASQUERADE | |
70 | + | ||
71 | + | # don't delete the 'COMMIT' line or these nat table rules won't | |
72 | + | # be processed | |
73 | + | COMMIT | |
74 | + | ``` |
上一页
下一页