xref: /netbsd-src/external/bsd/ipf/dist/rules/nat-setup (revision bc4097aacfdd9307c19b7947c13c6ad6982527a9)
1*bc4097aaSchristosConfiguring NAT on your network.
2*bc4097aaSchristos================================
3*bc4097aaSchristos
4*bc4097aaSchristosTo start setting up NAT, we need to define which is your "internal" interface
5*bc4097aaSchristosand which is your "external" interface.  The "internal" interface is the
6*bc4097aaSchristosnetwork adapter connected to the network with private IP addresses which
7*bc4097aaSchristosyou need to change for communicating on the Internet.  The "external"
8*bc4097aaSchristosinterface is configured with a valid internet address.
9*bc4097aaSchristos
10*bc4097aaSchristosFor example, your internal interface might have an IP# of 10.1.1.1 and be
11*bc4097aaSchristosconnected to your ethernet, whilst your external interface might be a PPP
12*bc4097aaSchristosconnection with an IP number of 204.51.62.176.
13*bc4097aaSchristos
14*bc4097aaSchristosThus your network might look like this:
15*bc4097aaSchristos
16*bc4097aaSchristos<Internal Network>
17*bc4097aaSchristos [pc]      [pc]
18*bc4097aaSchristos  |         |
19*bc4097aaSchristos+-+---------+------+
20*bc4097aaSchristos                   |
21*bc4097aaSchristos               [firewall]
22*bc4097aaSchristos                   |
23*bc4097aaSchristos                   |
24*bc4097aaSchristos               Internet
25*bc4097aaSchristos<External Network>
26*bc4097aaSchristos
27*bc4097aaSchristos
28*bc4097aaSchristosWriting the map-rule.
29*bc4097aaSchristos---------------------
30*bc4097aaSchristosWhen you're connected to the Internet, you will either have a block of IP
31*bc4097aaSchristosaddresses assigned to you, maybe several different blocks, or you use a
32*bc4097aaSchristossingle IP address, i.e. with dialup PPP.  If you have a block of addresses
33*bc4097aaSchristosassigned, these can be used to create either a 1:1 mapping (if you have
34*bc4097aaSchristosonly a few internal IP addresses) or N:1 mappings, where groups of internal
35*bc4097aaSchristosaddresses map to a single IP address and unless you have enough Internet
36*bc4097aaSchristosaddresses for a 1:1 mapping, you will want to do "portmapping" for TCP and
37*bc4097aaSchristosUDP port numbers.
38*bc4097aaSchristos
39*bc4097aaSchristosFor an N:1 situation, you might have:
40*bc4097aaSchristos
41*bc4097aaSchristosmap ppp0 10.1.0.0/16 -> 209.23.1.5/32 portmap tcp/udp 10000:40000
42*bc4097aaSchristosmap ppp0 10.1.0.0/16 -> 209.23.1.5/32 portmap
43*bc4097aaSchristos
44*bc4097aaSchristoswhere if you had 16 addresses available, you could do:
45*bc4097aaSchristos
46*bc4097aaSchristosmap ppp0 10.1.0.0/16 -> 209.23.1.0/28 portmap tcp/udp 10000:40000
47*bc4097aaSchristosmap ppp0 10.1.0.0/16 -> 209.23.1.0/28 portmap
48*bc4097aaSchristos
49*bc4097aaSchristosOr if you wanted to allocate subnets to each IP#, you might do:
50*bc4097aaSchristos
51*bc4097aaSchristosmap ppp0 10.1.1.0/24 -> 209.23.1.2/32 portmap tcp/udp 10000:40000
52*bc4097aaSchristosmap ppp0 10.1.2.0/24 -> 209.23.1.3/32 portmap tcp/udp 10000:40000
53*bc4097aaSchristosmap ppp0 10.1.3.0/24 -> 209.23.1.4/32 portmap tcp/udp 10000:40000
54*bc4097aaSchristosmap ppp0 10.1.1.0/24 -> 209.23.1.2/32 portmap
55*bc4097aaSchristosmap ppp0 10.1.2.0/24 -> 209.23.1.3/32 portmap
56*bc4097aaSchristosmap ppp0 10.1.3.0/24 -> 209.23.1.4/32 portmap
57*bc4097aaSchristos
58*bc4097aaSchristos*** NOTE: NAT rules are used on a first-match basis only!
59*bc4097aaSchristos
60*bc4097aaSchristos
61*bc4097aaSchristosFiltering with NAT.
62*bc4097aaSchristos-------------------
63*bc4097aaSchristosIP Filter will always translate addresses in a packet _BEFORE_ it checks its
64*bc4097aaSchristosaccess list for inbound packets and translates addresses _AFTER_ it has
65*bc4097aaSchristoschecked the access control lists for outbound packets.
66*bc4097aaSchristos
67*bc4097aaSchristosFor example (using the above NAT rules), if you wanted to prevent all hosts
68*bc4097aaSchristosin the 10.1.2.0/24 subnet from using NAT, you might use the following rule
69*bc4097aaSchristoswith ipf:
70*bc4097aaSchristos
71*bc4097aaSchristosblock out on ppp0 from 10.1.2.0/24 to any
72*bc4097aaSchristosblock in on ppp0 from any to 10.1.2.0/24
73*bc4097aaSchristos
74*bc4097aaSchristosand use these with ipnat:
75*bc4097aaSchristos
76*bc4097aaSchristosmap ppp0 10.1.0.0/16 -> 209.23.1.0/28 portmap tcp/udp 10000:40000
77*bc4097aaSchristosmap ppp0 10.1.0.0/16 -> 209.23.1.0/28 portmap
78