Debian Codegraph @

docs/example/router-firewall.md

raw
1 # Router Firewall
2
3
4 ## localhost - public - internal
5
6 This example is for small corporate firewall:
7
8 * Single firewall computer that runs:
9 * DHCP server
10 * DNS resolver
11 * Email and all other services are run on cloud
12 * Multiple laptops and workstations in internal network
13 * Bidirectional firewalling
14
15 ``` mermaid
16 flowchart LR
17 public@{shape: cloud} <--> localhost@{shape: stadium}
18 subgraph Local Network
19 localhost <--> internal
20 end
21 ```
22
23 ```
24 zone {
25 localhost
26 public eth0
27 internal eth1
28 }
29
30 snat {
31 # Masquerade traffic from internal to public.
32 saddr 10.0.0.0/8 oifname eth0 masquerade
33 }
34
35 public-localhost {
36 # Allow only ping and SSH to localhost.
37 ping saddr_rate "5/second burst 20"
38 ssh saddr_rate "5/minute burst 5"
39 # If localhost gets its public IP with DHCP, add "dhcp-client" here.
40 drop log
41 }
42
43 internal-localhost {
44 # localhost runs DHCP (IPv4 and IPv6) server and DNS resolver for internal
45 # network, plus basic SSH etc. rules.
46 dhcp-server
47 dhcpv6-server
48 domain
49 domain-s
50 ntp
51 ping
52 ssh
53 reject log
54 }
55
56 template outgoing_services {
57 # Shared list of services for localhost-public and internal-public.
58 domain
59 domain-s
60 http
61 https
62 ntp
63 ping
64 smtp
65 ssh
66 }
67
68 localhost-public {
69 # Basic services from localhost to internet: DNS queries, HTTPS, SSH, etc.
70 # Allow also SMTP so that localhost can send email.
71 template outgoing_services
72 # If localhost gets its public IP with DHCP, add "dhcp-server" here and
73 # "dhcp-client" to public-localhost.
74 reject log
75 }
76
77 internal-public {
78 # Laptops and workstations in internal network can access web and
79 # email services in internet. This ruleset is similar as localhost-public
80 # in host firewall example. This is the most important zone-zone
81 # section to configure.
82 template outgoing_services
83 googlemeet
84 imap
85 reject log
86 }
87
88 public-internal {
89 # No traffic is allowed from internet to internal network.
90 drop log
91 }
92
93 localhost-internal {
94 # DHCP server reply packets
95 dhcp-client
96 dhcpv6-client
97 # Very limited access from localhost to internal network.
98 ping
99 ssh
100 reject log
101 }
102 ```
103
104
105 ### Enable packet forwarding
106
107 For public-internal and other forwarding you must enable IP packet forwarding
108 on Linux kernel. That can be done by creating
109 `/etc/sysctl.d/50-ip.forwarding.conf` file with following lines:
110
111 ```
112 # Enable IP packet forwarding
113
114 net.ipv4.conf.all.forwarding = 1
115 net.ipv6.conf.all.forwarding = 1
116 ```
117
118
119 ## localhost - public - dmz - internal
120
121 This example is for larger corporate firewall:
122
123 * Single firewall computer that runs:
124 * DHCP server
125 * DNS resolver
126 * Single dmz computer that runs:
127 * Web server
128 * Email server
129 * Multiple laptops and workstations in internal network
130 * Bidirectional firewalling
131
132 See also note about enabling IP packet forwarding above.
133
134 ``` mermaid
135 flowchart LR
136 public@{shape: cloud} <--> localhost@{shape: stadium}
137 subgraph Local Network
138 localhost <--> internal
139 localhost <--> dmz
140 end
141 ```
142
143 ```
144 zone {
145 localhost
146 public eth0
147 internal eth1
148 dmz eth2
149 }
150
151 snat {
152 # Masquerade traffic from internal to public.
153 saddr 10.0.0.0/8 oifname eth0 masquerade
154 }
155
156 dnat {
157 # DNAT incoming SMTP and HTTPS traffic from public to dmz server. This
158 # section is needed only if dmz server doesn't have public IP address.
159 iifname eth0 smtp http https dnat 10.1.0.2 # public -> dmz
160 iifname eth1 daddr 192.0.2.32 smtp http https dnat 10.1.0.2 # internal -> dmz
161 }
162
163 macro {
164 # Define rate limits as macros as same limits are used in public-localhost
165 # and in public-dmz.
166 http_rate saddr_rate "100/second burst 400" saddr_rate_name http_limit
167 mail_rate saddr_rate "1/second burst 10"
168 ping_rate saddr_rate "5/second burst 20"
169 ssh_rate saddr_rate "5/minute burst 5"
170 }
171
172 template localhost_services {
173 # Shared list of services running on localhost. It runs DHCP server and DNS
174 # resolver for internal and dmz networks, plus basic SSH etc. rules.
175 dhcp-server
176 dhcpv6-server
177 domain
178 domain-s
179 ntp
180 ping
181 ssh
182 }
183
184 public-localhost {
185 # Allow only ping and SSH from internet to localhost.
186 ping ping_rate
187 ssh ssh_rate
188 drop log
189 }
190
191 internal-localhost {
192 # Servers on internal network can access localhost's basic services.
193 template localhost_services
194 reject log
195 }
196
197 dmz-localhost {
198 # Servers on dmz can access localhost's basic services, similar to
199 # internal-localhost.
200 template localhost_services
201 reject log
202 }
203
204 template public_services {
205 # Shared list of services that run on internet.
206 domain
207 domain-s
208 http
209 https
210 ntp
211 ping
212 ssh
213 }
214
215 localhost-public {
216 # Basic services from localhost to internet: DNS queries, HTTPS, SSH, etc.
217 template public_services
218 reject log
219 }
220
221 internal-public {
222 # Basic services from internal to internet: DNS queries, HTTPS, SSH, etc.
223 template public_services
224 googlemeet
225 reject log
226 }
227
228 dmz-public {
229 # Basic services from dmz to internet, plus SMTP for email transfer..
230 template public_services
231 smtp
232 reject log
233 }
234
235 public-internal {
236 # No traffic is allowed from internet to internal network.
237 drop log
238 }
239
240 localhost-internal {
241 # DHCP server reply packets
242 dhcp-client
243 dhcpv6-client
244 # Very limited access from localhost to internal network.
245 ping
246 ssh
247 reject log
248 }
249
250 dmz-internal {
251 # Servers on dmz don't need any access to internal network.
252 reject log
253 }
254
255 template dmz_services {
256 # Shared list of services that run on dmz.
257 http
258 https
259 ping
260 smtp
261 ssh
262 }
263
264 localhost-dmz {
265 # DHCP server reply packets
266 dhcp-client
267 dhcpv6-client
268 # localhost can access dmz server services.
269 template dmz_services
270 reject log
271 }
272
273 public-dmz {
274 # Allow traffic from internet to dmz server with rate limits.
275 http http_rate
276 https http_rate
277 smtp mail_rate
278 ping ping_rate
279 ssh ssh_rate
280 drop log
281 }
282
283 internal-dmz {
284 # Laptops and workstations in internal network can access dmz server
285 # services, plus IMAP for reading email.
286 template dmz_services
287 imap
288 reject log
289 }
290 ```