C.2. ���������������� ���� pf.conf(5)

[+]C.2.1. ������ ���������������� ��������� �������
[+]C.2.1.1. ������
[+]C.2.1.2. �������
[+]C.2.1.3. �������
[+]C.2.1.3.1. ��������������� ��������� � ������� ������� pfctl(8)
[+]C.2.1.3.2. ������
[+]C.2.1.3.3. ������������ �������
[+]C.2.1.4. ���������� �������
[+]C.2.1.4.1. ��������� ������
[+]C.2.1.4.2. ��������
[+]C.2.1.4.3. ���������� ������
[+]C.2.1.4.4. �������� ����� quick
[+]C.2.1.4.5. ������������ ��������� ����������
[+]C.2.1.4.6. �������� ��������� ��� UDP
[+]C.2.1.4.7. ����� ������� ���������
[+]C.2.1.4.8. TCP �����
[+]C.2.1.4.9. TCP SYN proxy
[+]C.2.1.4.10. ������ �� ���������
[+]C.2.1.4.11. Unicast Reverse Path Forwarding
[+]C.2.1.4.12. ��������� �������������� ������������ �������
[+]C.2.1.4.13. ����� IP
[+]C.2.1.4.14. ������
[+]C.2.1.5. NAT
[+]C.2.1.5.1. ��� �������� NAT
[+]C.2.1.5.2. NAT � ����������
[+]C.2.1.5.3. IP forward, ������� �������
[+]C.2.1.5.4. ���������������� NAT
[+]C.2.1.5.5. Bidirectional mapping (������������ 1:1)
[+]C.2.1.5.6. ���������� �� ����������
[+]C.2.1.5.7. �������� ��������� ������ NAT
[+]C.2.1.6. ��������������� �������, ������� ������
[+]C.2.1.6.1. ��������
[+]C.2.1.6.2. ��������������� � ���������� �������
[+]C.2.1.6.3. ������� ������������
[+]C.2.1.6.4. ��������������� � ���������
[+]C.2.1.7. ��ɣ�� ������������ ��� ��������� ����� pf.conf(5)
[+]C.2.1.7.1. ������������� ��������
[+]C.2.1.7.2. ������������� �������
[+]C.2.1.7.3. ���������� ��������� �������
[+]C.2.2. �����̣���� ���������������� ��������� �������
[+]C.2.2.1. ����� � �������� �������
[+]C.2.2.2. ������������ ������� (Scrub)
[+]C.2.2.3. Anchors
[+]C.2.2.3.1. ����������� ������ ������
[+]C.2.2.3.2. ����� �����
[+]C.2.2.3.3. ���������� ������������ ��������
[+]C.2.2.4. �������, ���������� (����������� ������ �����������)
[+]C.2.2.4.1. �������
[+]C.2.2.4.2. ������������
[+]C.2.2.4.3. ���������������� �������
[+]C.2.2.4.4. ������ 1: ��������� �������� ����
[+]C.2.2.4.5. ������ 2: ������������� ����
[+]C.2.2.5. �������� ����, ������������ ��������
[+]C.2.2.5.1. �������� ���� NAT
[+]C.2.2.5.2. ������������ �������� ��������� �������
[+]C.2.2.5.3. ������������ �������� ���������� �������
[+]C.2.2.6. ������������ �������, ���������� �� ������ �������
[+]C.2.2.6.1. ������������ ������� �������
[+]C.2.2.6.2. �������� ��������
[+]C.2.2.6.3. ���������� �� ������ �������
[+]C.2.2.6.4. ������������ ������ ethernet (��������� ������� OSI)
[+]C.2.3. �������������� �������
[+]C.2.3.1. �������������� � �������� �������
[+]C.2.3.1.1. ��������� ������� � ������
[+]C.2.3.1.2. ������ �������
[+]C.2.3.1.3. ���������� ���������� ������
[+]C.2.3.1.4. �������������� ��� ������ syslogd(8)
[+]C.2.3.2. ������������������
[+]C.2.3.3. FTP
[+]C.2.3.3.1. ������ FTP
[+]C.2.3.3.2. FTP ������ �� ������������
[+]C.2.3.3.3. FTP ������ ����ݣ���� �������� �������� ���������� ��������������� �� Σ�
[+]C.2.3.3.4. FTP ������ ����ݣ���� ������� �������� �������� � ���������� �� Σ� NAT
[+]C.2.3.3.5. ������������� TFTP
[+]C.2.3.4. Authpf: ����������� � �������� �������
[+]C.2.3.4.1. ���������������� authpf(8)
[+]C.2.3.4.2. �������� ������ authpf ��� /etc/login.conf(5)
[+]C.2.3.4.3. ��� ��ۣ� � ������� ����� authpf(8)?
[+]C.2.3.4.4. ������
[+]C.2.3.5. CARP � pfsync
[+]C.2.3.5.1. �������� � CARP
[+]C.2.3.5.2. ��� �������� CARP
[+]C.2.3.5.3. ��������� CARP
[+]C.2.3.5.4. ������ CARP
[+]C.2.3.5.5. �������� � pfsync(4)
[+]C.2.3.5.6. ������������� � pfsync(4)
[+]C.2.3.5.7. ���������������� pfsync
[+]C.2.3.5.8. ������ ������������� pfsync
[+]C.2.3.5.9. ���������� ������������� CARP � pfsync ��� ������������������
[+]C.2.3.5.10. ��������� �� ������������� CARP � pfsync
[+]C.2.4. ������: ���������� ��� ���� ��� ���������� �����
[+]C.2.4.1. ��������
[+]C.2.4.1.1. ����
[+]C.2.4.1.2. ������
[+]C.2.4.1.3. ���������������� ��������
[+]C.2.4.2. ��������� �������� ������ ����������
[+]C.2.4.2.1. �������
[+]C.2.4.2.2. �����
[+]C.2.4.2.3. ������������ �������
[+]C.2.4.2.4. ���������� NAT
[+]C.2.4.2.5. ���������������
[+]C.2.4.2.6. ����������
[+]C.2.4.3. ������ ������� ������

������ ������ �� 80% ������� �� �������� ����������� ������������ �� ��������� ������� OpenBSD. ��������� 20%�— ��� ���������� �� ������ ����������.

C.2.1. ������ ���������������� ��������� �������

�������� ������ OpenBSD ��� ������� ��������� ������� �� ����������������� �����. �� ��������� ��� ���� /etc/pf.conf(5). ���� �� ������ ��� ���������.

C.2.1.1. ������

������ ��������� ������� ������� ������ ��������� ������� ��������� � ����� �������. ��������: ������ ����, ����� ������ �� ������ ������� �� ������ IP-�����, ������� �� ����� �������������, �� ����� ������������ ���� ������� � �������� � ���� ������ ����������� �������. ����� pfctl(8) ��������� � ���������������� ����� ������, �� ������������� ���������� �� ��������� ������. ��������:

block out on fxp0 from { 192.168.0.1, 10.5.32.6 } to any
          

���������� ��

block out on fxp0 from 192.168.0.1 to any
block out on fxp0 from 10.5.32.6 to any
          

� ����� ������� ����� ����������� ��������� �������:

rdr on fxp0 proto tcp from any to any port { 22 80 } -> 192.168.0.6
block out on fxp0 proto { tcp udp } from { 192.168.0.1, 10.5.32.6 } \
        to any port { ssh telnet }
          

������ ����� ���� ����������:

trusted = "{ 192.168.1.2 192.168.5.36 }"
pass in inet proto tcp from { 10.10.0.0/24 $trusted } to port 22
          

������ ��������� � ����������� � �������. ��������� ������ ������������� �������������� ������:

pass in on fxp0 from { 10.0.0.0/8, !10.1.2.3 }
          

��� ������ �������� �� «����� ����� �� ���� 10.0.0.0/8 ����� 10.1.2.3», � ������������ � ��������� ��� �������:

pass in on fxp0 from 10.0.0.0/8
pass in on fxp0 from !10.1.2.3
          

���� ������ ��� ������� ������ �������������� ������, ����� ��������� �����ģ� � ����, ��� ����� ��������� ������ ��� ������ ����� ������ � ������ 10.1.2.3. ��� ������� ����� ������ ����� ��������� ������� (��. �����̚C.2.1.3, «�������»).

C.2.1.2. �������

�������, ��� ������̣���� ������������� ����������, ������� ����� ��������� IP-������, ������ ������, ����� ����������� ɚ�.�. ��� ������� ����������� ������������ ��� ����������� ������ ���������������� ��������: ���������� ��� ������ � �����, � �� ��� ������ ���� �����, ����� ��� ������� ��������. ��� �� ������ ���� ����������������� ������, ����� ��� pass, out ��� queue.

ext_if = "fxp0"
block in on $ext_if from any to any
          

����� ������ ������ ext_if. ����� ���� ��������� �� ������, ��� ��� �������� �� ����� $.

������� ����� ������������ � ������:

friends = "{ 192.168.1.1, 10.0.2.5, 192.168.43.53 }"
          

������� ����� ���������� ���� � �����, ��, ��������� � ������� �������� ������ ��������� ������, ������� ������������ ��������� �������:

host1 = "192.168.1.1"
host2 = "192.168.1.2"
all_hosts = "{" $host1 $host2 "}"
          

������ $all_hosts � ���� ������� ����� ������� � ������ { 192.168.1.1, 192.168.1.2 }.

��� ������ ������� pfctl(8) ����� �������������� �������� �������� � ������� ����� -D. ��������:

# pfctl -D friends="{ 192.168.1.1, 10.1.2.3 }"
          

C.2.1.3. �������

������� ������������ ��� �������� ������� IPv4 �/��� IPv6. ����� � ��� �������������� ����� ������, ��� ��������� ����������� ������ ������ � ������������� �������, ��� ������. �������, ����� �������, �������� ��� �������� ������� �������� �������, ��������� ����� � ������� � 50�000 ������� ���������� �� �� ����� ���������, ��� � ������� � 50 ��������. ������� ����� ������������ ��������� �������:

  • ��� IP ������ ��������� ��� ���������� ������ � �������� ����������, ������������ (scrub), NAT � �������� ���������������;
  • ��� ������ �� ������� ���������� ���������� � �������� NAT;
  • ��� ������ �� ������� ���������� ��������������� �������;
  • ��� ������ ���������� � �������� ���������� ��� ����� route-to, reply-to, dup-to,

������� ����� ��������� ��� � ���������������� ����� pf.conf(5), ��� � ��� ������ ����������� ������� pfctl(8).

� ��������������� ����� pf.conf(5) ������� ��������� ��� ������ ��������� table. � ������� ����� ���� ��������� ��������:

const, persist
���������� ������� �� ����� ���� �������� ����� ����, ��� ������� �������. ���� ���� ������� �����������, ���������� ������� ����� ������������� ��� ������ pfctl(8). ��������� ����, ��� ������ ������� ������ ������� �� ������ ���� ���� �� ��� �� ����������� �� � ����� �������. ��� ���� ������� �� ������, ���� ������������� ������ ������� �� ������, ����� ��������� ������� ������������ ������� ����� ��������.

������ (��� ������� ����������� � ������� ������� <...>):

table <goodguys> { 192.0.2.0/24 }
table <rfc1918> const { 192.168.0.0/16, 172.16.0.0/12, 10.0.0.0/8 }
table <spammers> persist

block in on fxp0 from { <rfc1918>, <spammers> } to any
pass  in on fxp0 from <goodguys> to any
          

������ ��� �� ����� ����������� � ������������� ������ (!), ��� � �������� ������ not:

table <goodguys> { 192.0.2.0/24, !192.0.2.5 }
          

������� <goodguys>, ����� �������, �������� � ���� ��� ���� 192.0.2.0/24 ����� ������ 192.0.2.5.

���������� ������� ����� ����� �� �����:

table <spammers> persist file "/etc/spammers"
block in on fxp0 from <spammers> to any
          

���� /etc/spammers ������ ��������� IP-������ �/��� ����� ����� � ������� CIDR �� ������ �� ������. ������ ������������ � # ��������� ������������ � ������������.

C.2.1.3.1. ��������������� ��������� � ������� ������� pfctl(8)

�������� ����� �������������� ��� ������ ������� pfctl(8). ��������, ��������� ������� ��������� � ������� <spammers> �ݣ ���� ����:

# pfctl -t spammers -T add 218.70.0.0/16
            

����� ����, ��������� ������� ������� ������� <spammers>, ���� ţ �ݣ ���. ����� ����������� ��� ��������� � ������� ����� ������������ ��������� �������:

# pfctl -t spammers -T show
            

����� -v ����� ������������� ������ � -Tshow ��� ����, ����� ������� ���������� �� ������� ������ � �������:

# pfctl -t crackers -Ts -v
    222.122.26.172
        Cleared:     Sun Jan 21 18:45:49 2007
        In/Block:    [ Packets: 0                  Bytes: 0                  ]
        In/Pass:     [ Packets: 0                  Bytes: 0                  ]
        Out/Block:   [ Packets: 0                  Bytes: 0                  ]
        Out/Pass:    [ Packets: 0                  Bytes: 0                  ]
    222.175.172.2
        Cleared:     Sun Jan 21 18:45:49 2007
        In/Block:    [ Packets: 0                  Bytes: 0                  ]
        In/Pass:     [ Packets: 0                  Bytes: 0                  ]
        Out/Block:   [ Packets: 0                  Bytes: 0                  ]
        Out/Pass:    [ Packets: 0                  Bytes: 0                  ]
....................
            

����� ������� ����� �� ������� ����� ������������ �������

# pfctl -t spammers -T delete 218.70.0.0/16
            

��. ��� �� �����̚C.3, «���������� �������� �������� OpenBSD ��� ������ ������� pfctl(8)».

C.2.1.3.2. ������

����� � �������� ����� ��������� �� ������ � ���� IP-������, �� ��� �� � �� �����. � ���� ������ ����� ����� ��������� � ��� ������, ��������������� ������� �����, ������� � �������. ����� ����, ����� ��������� ��� ���������� ��� �������� ����� self. � ���� ������ � ������� ���� ��������� ��� ������, ��������������� ������� ����������, ��� ��� ������ ������ ������ (������� ��������� ���������) ��������������.

�����������: ������ 0.0.0.0/0 � 0/0 � �������� �� ��������. ����������� ������.

C.2.1.3.3. ������������ �������

��� ������ � ������� ��������� «�������� ����������» �����, �.�. ���� � ����� ������� ������. (���������� ����� � ����� «�����» ����.) ��������:

table <goodguys> { 172.16.0.0/16, !172.16.1.0/24, 172.16.1.100 }
block in on dc0 all
pass  in on dc0 from <goodguys> to any
            

����� ��������� ������� ������ ���������� ����� ��������� dc0 ����� �������� � ������� <goodguys>:

172.16.50.5
���� � ���������� �����ʚ— 172.16.0.0/16; ����� ������������� ������� � ����� ��������.
172.16.1.25
���� � ���������� �����ʚ— !172.16.1.0/24; ����� �� ������������� ������� � ����� ��������.
172.16.1.100
���� � ���������� ������ (� ������ ����)�— 172.16.1.100; ����� ������������� ������� � ����� ��������.
10.1.4.55
���������� ������� � ������� ���. ����� �� ������������� ������� � ����� ��������.

C.2.1.4. ���������� �������

���������� ������� ����������� � ���, ��� ������ ������������ ��� ������������� ��� ����������� ����� ������� ��������� � ������������ � ���������. ������� �������� �� ���������� ������� �������� � ������������� ������� ������ OSI (��. OSI). �������� ����� ������������ �������ɚ— ������ ��������� � ����������, ������ ������ ��������� � ����������, ���������.

������� ������� ������� �� �������� � ��������, ������� ���� �����������, ���� ����� ������������� ��������. �������� ����� ���� ��� block ��� pass. ������� ����������� �� ������� �� ������� � ����������, ��� ���� ��������� ������� ���������� ���� ������ �� ���������� ������� ����� quick. ����� �������, ���� � ����� ������ ����������������� ����� ������ ������� «���������� ��� ������», ��� «����������� ��� ������», �� ��� �� ��� ����, ��� �������� �� ����������— ������ ��� ������� ����� ��������� � ������, ������� �� ������������� �� ������ ������� ���� �� ���� �����.

C.2.1.4.1. ��������� ������

���� ��������� ����ݣ���� �������������� �����:

action [direction] [log] [quick] [on interface] [af] [proto protocol] \
    [from src_addr [port src_port]] [to dst_addr [port dst_port]] \
    [flags tcp_flags] [state]
            
action
�������� ����� ���� ���� pass, ���� block. �������� pass �������� � ����, ��� ����� ������������ � ���� � ������������ �� ������ �������. �������� block �������� � ����, ��� ����������� ��������� �� �������� block-policy (��. �����̚C.2.2.1, «����� � �������� �������», ��� ��������� ������̣���� ��� ������ ����� if-bound). (���������� ������ �������� ������� � ���, ����� ������ ��������� �����, ��� ������� ����� �����-������ �����: TCP � ������ reset ��� ICMP Unreachable.) �������� ����� ���� �������������� � �������: block drop ��� block return.
direction
����������� ������ ��� ����������� ����� ���������: in ��� out.
log
���������, ��� ����� ������ ���� ������������ ��� ������ ������� pflog(8). ���� ������� ����� keep�state, modulate�state ��� synproxy�state�— � ������ �������� ������ ������ ��������� ����������. ���� ����, ����� � ������ ������ ������ ��� ������, ���������� ������� log�(all).
quick
���� ����� ������������� ������� � �������� ������ quick, �� ������ ������� ��������� ��������� � � ������ ���������� ����������� �������� action. (�.�. ���� � ���� ������ ����� ��������� ����� quick, �� �� ����� ����� ���� � ������������ � ������� ������ ������� ����������.)
interface

��� �������� ����������, ����� ������� �������� �����, ��� ��� ������ ������� �����������. ������ ����� ��������� ��� ������ ������� ifconfig(8) (������ � OpenBSD). ����� ����, ��������� ������ ��������� ����� �������������:

  • ������ egress, ������� �������� ��� ����������, ����� ������� �������� �������� �� ���������.
  • ������ «�������������» ����������� (ppp ��� carp).
af
Address family�— inet ��� ������� IPv4 � inet6 ��� ������� IPv6. ������ �������� ������ ����� ���������� ��������� �������� �� ��������� � ������� �������.
protocol

�������� ������������� ������. ��������� ��������:

  • tcp
  • udp
  • icmp
  • ��� ��������� �� ����� /etc/protocols.
  • ����� ��������� �� 0 �� 255
  • ��������� ���������� �������� ��� ������ ������.
src_addr, dst_addr

����� ��������� ��� ���������� ������. ��������� ��������:

  • ������ ��������� ����� IPv4, ��� IPv6
  • ���� � ������� CIDR
  • ��������� �����ۣ���� �������� ��� (FQDN), ������� ����� ���������� � IP-����� ����� DNS ��� �������� �������. ��� ������ ��������������� ������� ����� ����� �������� � ������ �������.
  • ��� ���������� ��� ������. ��� ������, ������̣���� �� �����������, ����� ����������� � �������.
  • ��� ���������� � ��������� /netmask (�������� /24). �� ���� ������� ������̣���� �� ������ �����������, ����� ��������� ������ ������� �����, � ���������� ���� CIDR ����� ��������� � ������ �������.
  • ��� �������� ���������� ��� ������, ������ � ������� ������ (...). ������ ������� ����� ������������� �������� ��� ����� ������ ������̣����� �� �����������. ��� ������� ��� DHCP ��������.
  • ��� �������� ����������, �� ������� �ģ� ���� �� ��������� �������������:

    :network
    ���������� ����� CIDR ������̣���� �� ������ �����������
    :broadcast
    ���������� ����������������� ������� ������̣���� �� ������ �����������
    :peer
    ���������� ������� ������ ��� point-to-point ����������.

    ����� ����, �� ������ ���������� ��� �� ����� �� ������������� ���� �������������, ����� ��������� ����������� :0, ����������� �� ��, ��� ��� �� ���������� ������, �.�. �������������� ������, ������ ����� �������� � �������� ���������� (��. �����̚6.15, «������ ��� � ����� ������������� ��� ������� ������ �������� ����������»). ��������: fxp0:network:0.

  • �������
  • ����� �� �����ģ���� ���� ����������� � �������� ��������њ— !.
  • �������� ����������� � �������������� ������.
  • �������� ����� any, ���������� ��� ������.
  • �������� ����� all, ������� �������� ������������ ����������� from any to any.
src_port, dst_port

���� ��������� ��� ���������� � ��������� ������������� ������. �������� ��������� ��������:

  • ����� �� 1 �� 65535
  • ��� ��������� �� ����� /etc/services.
  • �������� ����������� � �������������� ������.
  • ��������� ������ � ����������� ��������� ����������:

    !=
    �������
    <
    ������ ���
    >
    ������ ���
    <=
    ������ ��� �����
    >=
    ������ ��� �����
    ><
    �������� (����������� �����)
    <>
    ��������������� ��������
    :
    �������� ���������� �����

    ��������� ��� ��������� �������� (��������� ��� ���������). ��� ���� <>>< �� �������� ��������� � ��������, � : ��������.

tcp_flags
��������� ����� ����� TCP ������ ���� ���������� � ������, ���� ������� proto�tcp. ����� �������� ��� flags�check/mask. mask�— ������ ����������� ������, check�— ������ ������, ������� ������ ���� ��������. �������� ��������� flags�S/SA ��������, ��� �� ���� ����� � �������� �������� ���� ACK, � ����ޣ� ���� SYN, � ��������� ����� ��� �� ����������.
state

��������� ����������� �� ������ �������� ���������� � ��������� ����������. ��������� ��������:

keep state
�������� ��� ���������� TCP, UDP � ICMP
modulate state
�������� ������ � TCP. �������� ������ ���������� ���������� � ������ ������ ������������������� (ISN) ��� ������� ��������������� ������� �������.
synproxy state
������������ �������� ������ TCP ������� �������� ������� �� SYN ����� (����� ��������� �������� ������� ���������� ������� � ������ SYN, ����������� ����������, ��� ����� ������� ������������ DOS ����� �� ������). ������ ����� �������� � ���� ���������� ����� keep�statemodulate�state.

������ �������������� ����� ��������� � ���������� �������� man(1) �� pf.conf(5). � �ţ ������ �� ���������� ����� �����. ���� �� ������ �������� �������� ������, �������� ��� ����� ���������� ���������� ������ � ������� � ������� �����̚C.2.1.4.2, «��������», ��� ������ ������ ������������ � ������������� �������.

[��������]��������
� ������ �������� BSD ������������ ������ ������ ��������� ������� � �� ��� ����������� ��������� ����� ����� ���� ����������� � ����� �������. ������ ����, �� ��� ����������� ��������� � ����� man �� pf.conf(5) ����������� � ����� �������, ��� ��� ��� ������������ man, ���, �� �����������.
[���������]���������
������ � ����, ��� ������ ���� ������ ����� ��������������� �������� � ����� ����������� ��� ������� ���������� � ���������� � ����� �������� man �� pf.conf(5)
user <user>
����� ������������� �������, ���� �� ����������� ������, ������� ������� <user>.
group <group>;
����������.
icmp-type <type> code <code>
������� ������������� ������ ICMP � ��������� ����� � �����.
icmp6-type <type> code <code>
����������.
tos <string|number>

������� ������������� ������� � ��������� ��������� TOS. ��������� ��������: lowdelay, throughput, reliability ��� ���������� ��� ����������������� ��������. ��������, ��������� ������ ������������:

pass all tos lowdelay
pass all tos 0x10
pass all tos 16
                  
allow-opts
������, ������ ���������� ����� IP �����������. ������ �������� ��������� �������� ��� ���������.
label <string>

������� ������� ��� ������ ����� <string>. ����������� ���������� �� ���������� �������� ����� ��� ������ ������� pfctl(8) � ������ -s label. ����� ����� ������������ ��� �������������� �����������, ��� ����� ��� ��������� ����������� �������.

��� ���������� ����� ����� ������������ ��������� �������:

$if
���������
$srcaddr
����� ���������
$dstaddr
����� ����������
$srcport
���� ���������
$dstport
���� ����������
$proto
�������� ���������
$nr
����� �������

��������:

ips = "{ 1.2.3.4, 1.2.3.5 }"
pass in proto tcp from any to $ips \
     port > 1023 label "$dstaddr:$dstport"
                  

������������

pass in proto tcp from any to 1.2.3.4 \
      port > 1023 label "1.2.3.4:>1023"
pass in proto tcp from any to 1.2.3.5 \
      port > 1023 label "1.2.3.5:>1023"
                  
queue <queue> | (<queue>, <queue>)
���������� ������� � ��������� ��������. ��. �����̚C.2.2.4, «�������, ���������� (����������� ������ �����������)»
tag <string>
������������ ������ ���������� �������. ��. �����̚C.2.2.6.1, «������������ ������� �������»
tagged <string>
������ �� ���������� �����. ��. �����̚C.2.2.6.2, «�������� ��������»
fastroute
����� ����� ��������������� ������� �������
route-to <interface> [nexthop]
����������� ��������� ����� ������� ���� ��������� ����� �, �������������, ����� ���������� �����. ������� ����������� � ������� ���������� ���������� � �� ��������� � �������.
reply-to <interface> [nexthop]
��������� ����� ����� ��������� ���� ��������� �������� ������. ����� ����� ������ ��� ������� ������������� ������� ��������� ����������. ����� ������������ �� ������ � ����������� �������� ����������� ��� ������������� ��������.
dup-to <interface> [nexthop]
������� ����� ������ � �������������� ţ ��� ���� �� ���� ��������� ����� route-to. ������������ ����� ���������������� ������� �������.
rtable <number>
������ �� ��������� ���������� ������� �������������. ����� ����� ������ �� ����, ��� ������������ �������������, �.�. ��� ��������� �������.
probability <num>

����������� ������������ �������. �������� ��� ����� �� 0 �� 1 ��� � ���������. ��������, ��������� ������� ����������� ������ ICMP � ������������ 20%:

block in proto icmp probability 20%
                  
C.2.1.4.2. ��������

������������� �������� ��� ��������� �����������ך— ������ �������� «default deny», �.�. �� ��������� ����������� ��� ������, � ����� ���������� ��������� �����ۣ���� ������. ��� �������� �������� «default deny» ���� ������� ��������� ������ ��� �������:

block in  all
block out all
            

��� ������� ��������� ���� ������ �� ���� ����������� ��� ����������� �� �����������.

C.2.1.4.3. ���������� ������

������ ��� ���� ���� ��������� ����������� �������, ����� �� �� ��� ������������ ���������. ����� ����������� ����� �������� ��� ������ ������ ��������� � ����������, ������ ��������� � ����������, ���������. ������� ������ ���� ��������� ��������, ��������� ��� ��������, ��� ����, ����� ����� ���������� �������� ������ ������ ������.

��������:

# ���������� ������ �� ��������� ���� (192.168.0.0/24) ������ �����
# ��������� dc0 �� ������ OpenBSD (FreeBSD, NetBSD) � ������� 192.168.0.1,
# � ��� �� ��������� �������� ������.
pass in  on dc0 from 192.168.0.0/24 to 192.168.0.1
pass out on dc0 from 192.168.0.1 to 192.168.0.0/24

# ���������� TCP ������ �� ���������� fxp0 ������������ �� web ������
# ���������� �� ����� OpenBSD (FreeBSD, NetBSD) ������. ��� ����������
# ������������ � �������� ������ ����������, ������� �������
# ������������� ������ ������ ������������ � ���.
pass in on fxp0 proto tcp from any to fxp0 port www
            
C.2.1.4.4. �������� ����� quick

��� ���� �������� ����, ������ �������� ����� ��� ������� �� ������ �� �����. �����, ������� ��������� �������� ��� ���������� (pass) ����� ����������� ������� �������� � pass �� block � �������, � �������� ����������� ����� �������. ��������� ������� ����������, ���� ������ ����� �� �������� ������� � �������� ������ quick, ������� ������������� ����������� ������ �� ��������.

��� ���� ��������:

������������ ������:�

block in on fxp0 proto tcp from any to any port ssh
pass  in all
              

� ���� ������ ������� block �������� ����������� � ������� ssh, �� � ����� ������� �� �����������, ��� ��� ������ �ģ� �������, ������� ��������� ���� ������.

���������� ������:�

block in quick on fxp0 proto tcp from any to any port ssh
pass  in all
              

� ������ ������� ������ ssh ����� �������� ����������, ��� ��� ����������� �������� ����� quick, � ��� ������ ������� ����������� � ������� ssh ����� ���������������.

������������� ������:�

pass  in all
block in on fxp0 proto tcp from any to any port ssh
              

����� ��� ������� �������� �������� � ������������ �������, � ����� ���� � ���. � ����������� �� ����, ����� ������� �������� ���� �� ������.

C.2.1.4.5. ������������ ��������� ����������

���� �� ������ ������������ ��������� ��������— ������������ ��������� ���������� («stateful inspection»). Stateful inspection �������� ��������� ����������� ��������� ������� ����������� ��������� ������� ����������. ��������� ������� ���������� �������� � ������� ���������. �������� ������ ����� ������ ���������� ����������� �� ����� ��� ��������� ����������. ���� ����� ����������� ��� ��������� ����������, �� ��� ����������, �� ��������� �� ������ ����������� �������.

������������� ������� ��������� ����� ����� �����������: �� ��������� ������ ����������, �� ���������� ������������������ �����������. �������� ������ ����� ���������� �������������� ������ ��������� ���������� ���������� �� ����������� � ������� �ģ� �����. ��� ����������� �� ������������� ��������� ������ ������������ �������� ������. � ��������� ����� �� ������������ �� �� ����� �������, ����� ����������� ������ ����� ���������� ����������� �����������.

���� � ������� ����������� ����� keep�state, ������ ����� ��������������� ������� ������� ������ � ������� ��������� ����������� �������� � ���������� ������. ������ �� ������ ������ ������ �� ��������� � ����������, �� � �������� ������ ����� ��������������� ��������� ������ � ������� ��������� � �� ����� ������������ ��������. ��������:

pass out on fxp0 proto tcp from any to any keep state
            

��� ������� ��������� ����� ��������� ������ �� ���������� fxp0, � ��� �� ��������� ����������� ����� ��������� ������� ����� ����������. ������� keep�state ������������ ��� �� ���, ��� ����������� �������� ������������������ �����������, ��� ��� ����� � ������� ��������� ������� ������� ��� �������� ������ ��� ������ ������ ����������.

������� modulate�state �������� ��� �� ��� keep�state, �� ��������� ������ � ������� TCP. ��� ������������� modulate�state, ��������� ����� ������������������ (ISN) ��������� ���������� ���������� ��������� �������. ��� ������� ��� ������ ���������� ������������������ ������������� ���������, �������������� ����� ������ ������ �� ������ ������ ISN. ������� � OpenBSD�3.5 ������� modulate�state ����� ����������� �� ������ ��� ��������� TCP (������������ ������������������ ��� ���� ����� �������� ��� TCP ���������, � ��� UDP � ICMP ����� �������� keep�state).

��������� ��������� TCP, UDP � ICMP �������, � ��������������� ISN � TCP:

pass out on fxp0 proto { tcp, udp, icmp } from any to any modulate state
            

������ ������������ ������� ��������� ������� � ���, ��� ������ ICMP ��������������� ��������� ���������� ���� ������������ ����� ����������. ��������: ���� keep�state ������ ��� ���������� TCP, � �������� ��������� ICMP source-quench ����������� � ������� ���������� TCP, �� ��� ����� ��������� ����� ���������� (ICMP ����� source-quench ��������� �������� �������� ������� ����� ������������� � ���������� ��������������� ��� �������� ������ ����, ��������, � ��� ���������� �����).

������� �������� ������ � ������� ��������� �������������� ���������� ��������� ������ state-policy (��. �����̚C.2.2.1, «����� � �������� �������», ��� ��� ������ ����� if-bound), group-boundfloating, ���������� ��������������� � ��������. ��� ����� �� �� ��������, ��� � �������� ��������� �������� state-policy. ������:

pass out on fxp0 proto { tcp, udp, icmp } from any \
  to any modulate state (if-bound)
            

��� ������� ������, ��� ����� ����� ��������������� ������ � ������� ��������� ������ ���� �� �ģ� ����� ��������� fxp0.

������� nat, binatrdr ���� ������� ������ � ������� ���������.

C.2.1.4.6. �������� ��������� ��� UDP

���-�� ����� ��������, ��� ��� ��������� UDP ������ ������ ������ � ������� ���������, ��� ��� ��� «stateless» ��������. ������ �������� ������ ����� ����������� ��� ���������. �������� �� ���������� «����������» ������, �������� ������ ������ �� �������� �� ��������� ��������� � ������� ������ ��������� � ����������. �� ���������� �������� ������� ��������� ��������� �� ��������������� ������. �������� �������� ����� ������ � ������� «�����» pf.conf, ��. �����̚C.2.2.1, «����� � �������� �������»

C.2.1.4.7. ����� ������� ���������

����� ������������ ��������� ����� ��� ���������� ���������� ������� � ������� ���������, ��������� ��� ������ ������ keep�state, modulate�state ��� synproxy�state. ��� ������ ���� �����:

max number
����������� ������������� ���������� ������� � ������� ���������, ������� ����� ������� ������ �������. �� ���������� ����� �������, ����� �������� ����� �����, ������� ������ ��� �� ������� ����� ������ � ������� ���������. ������ ����� ������������� �� ��� ���, ���� ����� ������� � ������� ��������� �� ����������.
source-track

��� ����� ���� ����������� ����������� ���������� ������� � ������� ��������� � �����ޣ�� �� ������ ����� ���������. ��������� ������� �����:

  • source-track�rule�— ������������ ���������� ������� � ������� ��������� ��������� ������ �������� �������������� ������� max-src-nodesmax-src-states, ��������� � ���� �������. �ޣ����� ��������� �� ����������, � ���������.
  • source-track�global�— �� �� ��� � � ���������� ������, �� �ޣ����� ������� ���������. ��� ���� ������ ������� ����� ����� ���� ������� max-src-nodesmax-src-states, ������ �ޣ����� ����� ������ ��� ���� ������.

����� ���������� ������� ����������, ��� ������� �������������� ���������� �������� ���������� ����� � ������� ���������, �������������� ��� ������ ����� src-nodes. (��. �����̚C.2.2.1, «����� � �������� �������»)

max-src-nodes number
��� ������������� ����� source-track ����� max-src-nodes ������������ ���������� IP-������� � ������� ����� ������������ ������� ����������.
max-src-states number
��� ������������� ����� source-track ����� max-src-states ������������ ���������� ���������� � ������ IP-������.

��������:

pass in on $ext_if proto tcp to $web_server \
    port www flags S/SA keep state \
    (max 200, source-track rule, max-src-nodes 100, max-src-states 3)
            

��� ������� �������� ���������:

  • ������ ������� ����� ������� �� ����� 200 ������� � ������� ���������.
  • ���������� ������������ ��������� IP-�������. ����������� ��������� ������ �� ������ �������.
  • ������������ ���������� ������������ ������ޣ���� � ������� IP-������ך— 100 ����.
  • � ������ IP ������ ����� ������� �� ����� 3-� ����������.

��������� ����������� ����� ������ ��� TCP ���������� ��������� ������� ����������� (��. �����̚B.1.4.3.2, «�������� ���������� TCP, ������� �����������»):

max-src-conn number
����������� ������������� ���������� TCP ���������� ��������� ������� �����������, ������� ����� ������� � ������ IP-������.
max-src-conn-rate number / interval
����������� �������� � ������� ����� ��������� ����� ����������. �������� ���������� ���������� �� �������� �������.

��� ����� ������������� �������� ����� state-track rule � �� ���������� � state-track global.

� ���������� � ������� ������� ����� ����������� ����� ����������� �����, ��� «���������» «�������������».

overload <table>
��� ���������� ������� ������� ����� ��������� � �������.
flash [global]
���������� ��� ������ � ������� ��������� ��������������� ����������� � ������� IP-������. ��� �������� ����� global ������ � ������� ��������� ������������ ���������� �� ����, ����� ������� ţ �������.

������:

table <abusive_hosts> persist
block in quick from <abusive_hosts>

pass in on $ext_if proto tcp to $web_server \
    port www flags S/SA keep state \
    (max-src-conn 100, max-src-conn-rate 15/5, overload <abusive_hosts> flush)
            

��� ������� ������ ���������:

  • ������������ ���������� ���������� � ������ IP-�������— 100 ����.
  • �������� � ������� ����� ������ ����� ���������� �����������— �� ����� 15 ���������� �� 5 ������.
  • ������ ������, ������� ��������� ��� ������ ��������� � ������� <abusive_hosts>. ��� �����ģ� � ����, ��� ������ ������ ������ �� ������ ��������� ���������� � ������� (��. ������� block).
  • ��� ������� «����������������» ������ ��������� ��� ������ �� ������� ��������� ����������� ��� ��������� ������� �������.
C.2.1.4.8. TCP �����

��� �������� ���������� TCP �������� ������ ������ ������� ����� TCP ������������ � ��������� ������. �������� ������ ���� � ��������B.3, «����� TCP». ��� �������� ������ ����������� �������� ����� flags�check/mask. mask ��������� �������, ��� �� ������� ������ ��������� � ���� ���� �����, � ���� check ��������� ����� ����� ������ ���� ��������, ����� ������������� ������� �������.

pass in on fxp0 proto tcp from any to any port ssh flags S/SA
            

�������� ������� ���������� ���� TCP ������ c ������������� ������ SYN, ��� ���� ��������� ����� SYN � ACK. ����� � ������� SYN � ECE ����� �������� ������ ��������, � ����� � ������� ���������� ����� SYN � ACK ��� ������ ACK �� ����� ��������.

[���������]���������
� ������ ������� ������������� ��������� ...�flags�S, � ����� ������� ������� ����� ������ ������ �����������.

����� ����� ����������� ������ � �������� keep�state ��� �������� ������ � ������� ���������:

pass out on fxp0 proto tcp all flags S/SA keep state
            

������ ������� ��������� ��������� ���������� ������������ � ������ � ������� ���������� ���� SYN, � ����� ACK ���.

������ ����������� ��� ������������� ������. ��������� ��� �� ������� � �����, �������� ����� ����������� �����-�� ��������. ��������� ���� ���������� ��������� ���������� ���� ������ ���� SYN � ������� ������:

. . . flags S/FSRPAUEW  ������ ����!!
            

������������ ������ ����� ������ ��������� ���� SYN � ������� ������, ������ ��������� ����� ���������� ���� ECN � ����� ���������� ������ ��������. ����� �������� ����� ��������� �������:

. . . flags S/SAFR
            

��� ��������� � ���������, ������ � ���� ��� �������������, ���� ������ ��� ������������ ��� ������ scrub. ������� ������������ ������� ���������� �������� ������ ����������� ������ � ������������� ����������� ������ (����� SYN+RST) ��� �������������� ��������� (SYN+FIN). ������ ���������� ������ ���������� ������ ������������:

scrub in on fxp0
.
.
.
pass in on fxp0 proto tcp from any to any port ssh flags S/SA keep state
            
C.2.1.4.9. TCP SYN proxy

� ������� �������� ������ ��������� ������� ����������� � �������� (��. �����̚B.1.4.3.2, «�������� ���������� TCP, ������� �����������»). �������� ������ ����� ��������� � ���� ��������� ������� ����������. ��� ���� ������ ��������� ������� ����������� � ��������, ����� �������� ����������� � ��������, � ��� ����� ����� �������� ������������ ������ ����� �������� � ��������. ���� ����� ��������� �������� TCP SYN ����� (������������� ������� DOS �����, ����� ������ ����������� ������ �������� �� �������� ����������, �� ���������� �� ���������. � ���������� � ������� ����� ����������� ������. ��. ��� �� DOS �����).

������������� ����������� ���������� ��� ������ ��������� ����� synproxy�state:

pass in on $ext_if proto tcp from any to $web_server port www \
    flags S/SA synproxy state
            

� ���� ������� ������������ �������� ���������� � web-�������.

synproxy�state �������� � ���� ���������� keep�statemodulate�state.

[���������]���������
SYN proxy ����������, ���� �������� ������ �������� �� �����. (��. bridge.)
C.2.1.4.10. ������ �� ���������

IP-������ǚ— �������� ��������� ������� � ��������� IP ������ (��. spoofing).

�������� ������ ����� ������������ ������ �� �������� ��� ������ ������ ������������ � ��������� ����� antispoof:

antispoof [log] [quick] for interface [af]
            
log
������ ����� ���������� � ������ ��� ������ pflogd(8)
quick
����� ��������������� ������� ����� ���������� �������� � �� ���ģ� �� ������ �������, ������� ����� ��� ����������.
interface
������� ��������� �� ������� ������������ ������ �� �������� (����� ����� ���� ������ ������)
af
�������� ��� �������� �������������� ������. ����� ���� ��� IPv4, ��� � IPv6. �������������� inetinet6.

������:

antispoof for fxp0 inet
            

������ ������� antispoof ������������ � ��� ������� �������. ��������, ���� �� ����������� fxp0 ������̣� ����� 10.0.0.1 � ������� ����� 255.255.255.0 (�.�. /24), �� ���������� ������� ����������� � ��������� ��� �������:

block in on ! fxp0 inet from 10.0.0.0/24 to any
block in inet from 10.0.0.1 to any
            

��� ������� �������� ���������:

  • ����������� ���� �������� ������ �� ���� 10.0.0.1/24 (��������� �� ����� ���� ����� ������ ����� ���� ������ ���������).
  • ����������� ���� ������ � ������ 10.0.0.1. ������ �� ������ �������� ������ ���� ����, ����� ��� �� ��������� ����������. ����� �������, ���� �������� ������ � �������� ��������� IP 10.0.0.1 ������ ��������������� ��� �������������.
[���������]���������

������� antispoof ����� ������������� ������ ���������� ����������. ��� �������, �� ��������� ���������� ������ ������ �� ���������:

set skip on lo0
antispoof for fxp0 inet
              
[���������]���������

������������� ������� antispoof �� ����������, �������� �� �������� IP-����� ������������ � ������� ����:

block drop in on ! fxp0 inet all
block drop in inet all
              

� ����� ������������� ���� �������� ������ �� ���� �����������.

C.2.1.4.11. Unicast Reverse Path Forwarding

������� � OpenBSD�4.0 � �������� ������� ��������� ����������� ��������� ��������� ������ ��� ������ ������� �������������. ���� ����� ������������ �������� uRPF, ��������� IP ����� ������������� � ������� �������������, � ���� ��������� � ��� ��������� ������������� ����������, ����� ������� ���ۣ� �����, �� ����� �������� ��������, � ���� ��Ԛ— �� �� ����� ���� � IP-���������.

�������� uRPF �������������� ��� ������ ��������� ����� urpf-failed:

block in quick from urpf-failed label uRPF
            

�������� uRPF �������� ������ ��� ������������ �������������. � ��������� ������ ������ ����� ������������.

���� ������ �������� �������� ������ IPSec �������, ������ �������� �������� uRPF �� ���������� enc0, ����� ����� ������������ ���� ����������������� ������. ������������� ���������� ��� ������ �� ���������� enc0: set�skip�on�enc0 ��� ������ ���:

block in quick on ! enc0 from urpf-failed label uRPF
            
[���������]���������
FreeBSD uRPF ���� �� ����������.
[���������]���������
FreeBSD ��������� ����������� ����������� ����� ���������� OpenBSD enc0 ����� ���������� gif0.
C.2.1.4.12. ��������� �������������� ������������ �������

�������� ������ �������� ������������ ���������� �� ����� ������������ ������� ��� ��������� SYN �����. �������� ��� �� ������ ��������� ����������� ������������ ������ TCP ����� ������ ������. ���, ��������, ��� ������������ ������� Windows�NT ������� ���������� ���� TTL � 128, ����� ��� Linux, FreeBSD�— 64. ����������� ������ ����� ��������� � ����� /etc/pf.os. ��� ������� ��������� ����, ������ �������� ������ � Σ� �� � ������������. ������� ������ fingerprint'�� ����� ������� ��� ������ �������

# pfctl -s osfp
Class   Version Subtype(subversion)
-----   ------- -------------------
AIX
AIX     4.3
AIX     4.3     2
AIX     4.3     2-3
AIX     4.3     3
AIX     5.1
AIX     5.1-5.2
AIX     5.2
AIX     5.3
AIX     5.3     ML1
.......
            

� ���� ������� ������������� 330 fingerprint'��. ������� Zaurus (���������� ����� SharpLinux'��) 2-� ������.

���������� ����� ������������ ��� ������ ��������� ����� os:

pass  in on $ext_if from any os OpenBSD keep state
block in on $ext_if from any os "Windows 2000"
block in on $ext_if from any os "Linux 2.4 ts"
block in on $ext_if from any os unknown
            

�������� ����� unknown �������� ����� �� ������� ��� �������������� ��������� ������� �����������.

[���������]���������
  • fingerprint ������������ ������� ����� ���������.
  • ��� ������ ������ � ������������ ������� ��� ��� ������ ����� �������, ��������� TCP ����� ����� ��������.
  • �������� OSFP �������� ������ ��� TCP SYN �������. ��� �� �������� � ������� ����������� � � ��� �������������� ������������.
C.2.1.4.13. ����� IP

�� ��������� �������� ������ ����������� IP ������ � ������������� �������, ��� ����������� ������ �������� ���������� ������ ��� ����� ������������ �������, �������� nmap(1). ���� � ��� ���� ���������� ����������� � ����������� ������ �������, �������� multicast ��� IGMP, ����������� ����� allow-opts:

pass in quick on fxp0 all allow-opts
            
C.2.1.4.14. ������

���� �����ģ� ������� ������ ����������������� ����� ��� ����������� ����� ��������� ���������� ����� � ����������. ����� ��������� ������ ������� ����������, nat, rdr, queue �������.

ext_if  = "fxp0"
int_if  = "dc0"
lan_net = "192.168.0.0/24"

# ������� �������� ��� IP ������ ������������� �����������
table <firewall> const { self }

# �� ��������� ������ �� ��������� ����������
set skip on lo0

# ����������� �������� ������
scrub in all

# �������� �� ���������
block all

# �������� ������ �� �������� �� ���������� ����������
antispoof quick for $int_if inet

# ��������� ssh ���������� �� ��������� ���� ������ � �����������
# ���������� 192.168.0.15. ������������� "block return" �����ģ�  ����,
# ��� ����� ������������ ����� TCP RST ��� ����, ����� ���������������
# ���������� ����������� ���������� �������. "quick" ������������ ���
# ����, ����� ������ ���� ������� pass �� �������������� ������
# ��������.
block return in quick on $int_if proto tcp from ! 192.168.0.15 \
    to $int_if port ssh flags S/SA

# ��������� ���� ������ �� ��������� ���� � ����������� � �������
pass in  on $int_if from $lan_net to any
pass out on $int_if from any to $lan_net

# ���������� ��������� tcp, udp � icmp ������ �� ������� ����������.
# ��������� ��������� ����������.
pass out on $ext_if proto tcp all modulate state flags S/SA
pass out on $ext_if proto { udp, icmp } all keep state

# ��������� ��������� ssh �� ������� ���������� ���� ��� ���������� ��
# �����������, � ������ ������ (�� ���������� ����). ������ �����
# �������� � ������, ����� ����� ����� ���� ������� ��� ����� �������
# ����������. ������������ syn proxy ��� ������ �� syn �����.
pass in log on $ext_if proto tcp from any to ! <firewall> \
    port ssh flags S/SA synproxy state
            

C.2.1.5. NAT

C.2.1.5.1. ��� �������� NAT

���� ���������� ������� NAT ������� � ���������: NAT.

����� ������ �� ���������� ���� �������� ������� IP ����� � �������� � ���� ������ ����������� ��������� IP ����� �� ����� �����, � ��� ��, ��� �������������, ����������� ����� ����� ��������� � ������� TCP � UDP. �������� ������ � ������� ���������.

�������� ������ ��������� � ������� ��������� � � ���� ������������� ����������� �������� ��������������.

�� ���������� ������, �� ������� �� ����� � ������������� NAT. �ӣ ���������� ���������. ��� ���������� ������ NAT ��� ������ ����, � ������� ������ ������ �� ����� � ���������� � �������, ��� ���������� ������� ������. ���������� NAT ����� ������ �� ��������� ���������.

C.2.1.5.2. NAT � ����������

������ ������������ ���������� �������� ����� ������ � ����� ��������� ��� ��������� � ����������� �� ������ ������� ��� ����������. ������������ ���������ڗ ���� � ������� NAT ���������� �������� ����� pass, �� � ���� ������ ����� �� ����� ���������� ����������.

���������� �������������� �� ����������. ������� ������� ������ ��� ����������������� ������.

C.2.1.5.3. IP forward, ������� �������

��������� NAT ������ ������������ �� ������ � ���������������, ���������� �������� ������� �������. ��� ����� ���� ��������� ���������� ���� net.inet.ip.forwarding � ������. ��� ����� �� ���� �������� BSD ������������ ��������� sysctl(8)

# sysctl -w net.inet.ip.forwarding=1
# sysctl -w net.inet6.ip6.forwarding=1   <==(���� ������������� IPv6)
            

����� ������� ��� ��������� ����������� ������� �������� � ���� /etc/sysctl.conf ����� ������:

net.inet.ip.forwarding=1
net.inet6.ip6.forwarding=1
            
C.2.1.5.4. ���������������� NAT

�������������� ��������� ������� NAT � pf.conf(5) �������� ��������� �������:

nat [pass [log]] on interface [af] from src_addr [port src_port] to \
    dst_addr [port dst_port] -> ext_addr [pool_type] [static-port]
            
nat
�������� ����� � �������� ���������� ������� NAT.
pass
���������, ��� ����� �� ������ ������������ �� ����������� �������.
log
���� ������� �������� ����� pass, ������ ��������� � ������ ��� ������ pflogd(8). � ����� � ������ �������� ������ ������ �����, ��� ������������� ������������� ��� ������ ����������� log (all).
interface
��� �������� ���������� (��� ��� ������ ������� �����������) �� ������� �������������� ����������.
af
Address family�— inet ��� ������� IPv4 � inet6 ��� ������� IPv6. ������ �������� ������ ����� ���������� ��������� �������� �� ��������� � ������� �������.
src_addr, dst_addr

����� ��������� ��� ���������� ������. ��������� ��������:

  • ������ ��������� ����� IPv4, ��� IPv6
  • ���� � ������� CIDR
  • ��������� �����ۣ���� �������� ��� (FQDN), ������� ����� ��������� ����� DNS ��� �������� �������. ��� ������ ��������������� ������� ����� ����� �������� � ������ �������.
  • ��� ���������� ��� ������. ��� ������ ������̣���� �� ����������� ����� ����������� � �������.
  • ��� ����������, �� ������� �ģ� /netmask (�������� /24). �� ���� ������� ������̣���� �� ������ �����������, ����� ��������� ������ ������� �����, � ���������� ���� CIDR ����� ��������� � ������ �������.
  • ��� �������� ���������� ��� ������, ������ � ������� ������ (...). ������ ������� ����� ������������� �������� ��� ����� ������ ������̣����� �� �����������. ��� ����� ���� �������, ��������, ��� DHCP ��������.
  • ��� �������� ����������, �� ������� �ģ� ���� �� ��������� �������������:

    :network
    ���������� ����� CIDR ������̣���� �� ������ �����������
    :broadcast
    ���������� ����������������� ������� ������̣���� �� ������ �����������
    :peer
    ���������� ������� ������ ��� point-to-point ����������.

    ����� ����, �� ������ ���������� ��� �� ����� �� ������������� ���� �������������, ����� ��������� ����������� :0, ����������� �� ��, ��� ��� �� ���������� ������, �.�. �������������� ������, ������ ����� �������� � �������� ���������� (��. �����̚6.15, «������ ��� � ����� ������������� ��� ������� ������ �������� ����������»). ��������: fxp0:network:0.

  • �������
  • ����� �� �����ģ���� ���� ����������� � �������� ��������њ— !.
  • �������� ����������� � �������������� ������.
  • �������� ����� any, ���������� ��� ������.
  • �������� ����� all, ������� �������� ������������ ����������� from any to any.
src_port, dst_port

���� ��������� ��� ���������� � ��������� ������������� ������. �������� ��������� ��������:

  • ����� �� 1 �� 65535
  • ��� ��������� �� ����� /etc/services.
  • �������� ����������� � �������������� ������.
  • ��������� ������ � ����������� ��������� ����������:

    !=
    �������
    <
    ������ ���
    >
    ������ ���
    <=
    ������ ��� �����
    >=
    ������ ��� �����
    ><
    �������� (����������� �����)
    <>
    ��������������� ��������
    :
    �������� ���������� �����

    ��������� ��� ��������� �������� (��������� ��� ���������). ��� ���� <>>< �� �������� ��������� � ��������, � : ��������.

ext_addr
������� ����� NAT �����, � �������� ���������� ����� ��������� ��� ����������. ��������� �� �� ��������, ��� � ��� src_addrdst_addr, ����� ������, ��������� � ������� ! � ��������� ����� any. ������ ������������ ����������� :broadcast.
pool_type
�������� ��� ��������� ���� (��. �����̚C.2.2.5, «�������� ����, ������������ ��������»).
static-port
��������� ������� �� ������������� ������ ������ ���������.

� ����������� ������� ��� NAT ���������� ������� �������� ����� ������:

nat on tl0 from 192.168.1.0/24 to any -> 24.5.0.5
            

��� ������� ���������, ��� ���� ����������� NAT ���������� �� ���������� tl0 ��� ������� ������ ���������� �� ���� 192.168.1.0/24 �������� ����� ��������� �� 24.5.0.5.

���������� ������ ���������, �� ������������� ��� ���������� ��������� ����������� ������������ ������ ����� ������ (� ������� dc0 ���������� ���������, � tl0 �������):

nat on tl0 from dc0:network to any -> tl0
            

��� ������������� ����� ����������, ��� ������� ����, ����� ����� ������̣� � ���������� ����� pf.conf �����������, �� �� �� ����. ��� ����� ������� ��������, ���� ����� ���������� ������������� �� DHCP � �������� �� ����� ������. ����� �������� ���� �������� ���� ��������� ����� ���������� � ������� �������.

nat on tl0 from dc0:network to any -> (tl0)
            

���������� �������� ��� ��� IPv4 ��� � ��� IPv6.

C.2.1.5.5. Bidirectional mapping (������������ 1:1)

������������ ����� ����� ������� 1:1 ����� ������� ��� ������ ������� binat. ��� ������� ������ � ������������ ���� IP ����� �������. ��� ����� ������������, ��������, ��� ����, ����� ������������ ������ � web-������� �� ���������� ���� �� �������� IP-������. ���������� �� ��������� � �������� ������ ����� ����� �������������� �� ���������� web-������, � ���������� �� ������� (�������� DNS �������) ����� ���������� � ������� �����. binat ������� �� ������ ������ ������ TCP � UDP.

������:

web_serv_int = "192.168.1.100"
web_serv_ext = "24.5.0.6"
binat on tl0 from $web_serv_int to any -> $web_serv_ext
            
C.2.1.5.6. ���������� �� ����������

����� ������� ���������� �� ���������� ��� ������ ��������� ����� no. ��������, ������� NAT ���������� �� ������� ���� ����� �������� ��������� �������:

no nat on tl0 from 192.168.1.208 to any
nat on tl0 from 192.168.1.0/24 to any -> 24.2.74.79
            

��� ���� 192.168.1.0/24 ����� ��������������� � ������ 24.2.74.79, ����� ������� ������ �� ����� 192.168.1.208.

����� ������ ������� ����������. ���� ���� �������� ����� no ���������� �� ������������. �������� ����� no ����� ����������� � ��������� binatrdr.

C.2.1.5.7. �������� ��������� ������ NAT

����� ������� ��������� ���������� ������������ NAT ���������� ����� ��������������� �������� pfctl(8) � ���������� -s�state.

# pfctl -s state
fxp0 TCP 192.168.1.35:2132 -> 24.5.0.5:53136 -> 65.42.33.245:22 TIME_WAIT:TIME_WAIT
fxp0 UDP 192.168.1.35:2491 -> 24.5.0.5:60527 -> 24.2.68.33:53   MULTIPLE:SINGLE
            

���� ��ޣ� (������ �����) �������� ���������:

fxp0
��������� �� ������� ���������� ����������.
TCP
��������
192.168.1.35:2132
IP ����� ���������� ������ (192.168.1.35) � ���� �������� �� ���� ������ (2132). ��� ��������� ����������� ��� ����������.
24.5.0.5:53136
������� IP ����� ����� (24.5.0.5) � ���� �������� �� ����� (53136). ��� ��������� ������������� ��� ���������� �� ����� ��������� ������ � ��������� �����.
65.42.33.245:22
IP ����� ���������� (65.42.33.245) � ���� ���������� (22).
TIME_WAIT:TIME_WAIT
�������� ������ �������, ��� TCP ���������� ��������� � ��������� ���������.

C.2.1.6. ��������������� �������, ������� ������

C.2.1.6.1. ��������

���� � ��� �������� NAT, ��� �������� ���� ��������, �� ��� ���� ���� �� ������ � NAT, � ��������� ���� ��������� ������ ������ � ������� ����� �������? ����� ��� ������� ������� ������. � ��� ������� �� ����� �������������� �������� ������ �� ������ ������������� �� ������ � NAT.

������:

rdr on tl0 proto tcp from any to any port 80 -> 192.168.1.20
            

� ������� ����� ������� ��� ��������� � 80 ����� ����� �������������� �� ������ 192.168.1.20. (� Linux netfilter ��� �������� ���������� DNAT, ��� ��� � ������ ����������� �� source IP, � destination IP.)

��������� from any to any �������, �� ���� �� ������ �� ����� ����� ����� ��������� �������, �� ������ ������ �������:

rdr on tl0 proto tcp from 27.146.49.0/24 to any port 80 -> \
   192.168.1.20
            

����� �������, ����� ���������� ������ ��������� �������. ������ ������ ��������� ��� �� ������������ ������ ������� �� ������ �����. �� ����� ������������ ��� �������� ��� ����, ����� ������ ������������� ������ � �� ����������� � ��������� ���� �� ��������� ������ � �������� ��� ���������� � �����:

rdr on tl0 proto tcp from 27.146.49.14 to any port 80 -> \
   192.168.1.20
rdr on tl0 proto tcp from 16.114.4.89 to any port 80 -> \
   192.168.1.22
rdr on tl0 proto tcp from 24.2.74.178 to any port 80 -> \
   192.168.1.23
            

��� �� ����� ������������ ��������� ������:

rdr on tl0 proto tcp from any to any port 5000:5500 -> \
   192.168.1.20 1
rdr on tl0 proto tcp from any to any port 5000:5500 -> \
   192.168.1.20 port 6000 2
rdr on tl0 proto tcp from any to any port 5000:5500 -> \
   192.168.1.20 port 7000:* 3
            
1 ������� ��������� �� ����� � 5000 �� 5500 ������������ �������������� �� ���� 192.168.1.20 ���� � ������ �.�. 5000 �� 5000, 5001 �� 5001 ɚ�.�.
2 ������� ��������� �� ����� � 5000 �� 5500 ������������ �������������� �� ���� 192.168.1.20, ���ޣ� ��� �� ���� 6000.
3 ������� ��������� �� ����� � 5000 �� 5500 ������������ �������������� �� ���� 192.168.1.20 �� ������� ������ �����, �.�. 5000 �� 7000, 5001 �� 7001 ɚ�.�.
C.2.1.6.2. ��������������� � ���������� �������

��������������� ������, ��� � � ������ � NAT, ������������ �� ������� ������� � ����� ���� ��� �������, ��� � ���������.

������������ ����������: ���� � ������� rdr ������������ �������� ����� pass. � ���� ������ ����� �� ������������ � ������. �� ������ �������, ��� ��� ����� �������� ������ �������� ��� �������, � ����� �� ������� �������������� ����������, � � ������ ������������� �������� ����� passkeep state. ������, ���� �� ������ ������������ �����-�� ������ ����������� ��������� �������, �������� modulate state ��� synproxy state, ��� ����� ����������� ��� ��������, �.�. rdr pass � ���� ������ �� ��������.

����� ����, ������ � ����, ��� �� ������ ������ ���������� ����� ����������.

���������� ��������� ��������:

  • 192.0.2.1�— ���� � ��������
  • 24.65.1.13�— ������� ����� OpenBSD (��� FreeBSD) �����
  • 192.168.1.5�— ���������� IP ����� web-�������.

������� ���������������:

rdr on tl0 proto tcp from 192.0.2.1 to 24.65.1.13 port 80 \
   -> 192.168.1.5 port 8000
            

��� ������ ����� �����������:

  • ��������� ����Ӛ— 192.0.2.1
  • ��������� ���Ԛ— 4028
  • ����� ���������њ— 24.65.1.13
  • ���� ���������њ— 80

��� ������ ����� ����������:

  • ��������� ����Ӛ— 192.0.2.1
  • ��������� ���Ԛ— 4028
  • ����� ���������њ— 192.168.1.5
  • ���� ���������њ— 8000

������� ������� ������ ��� ����� �ģ� �� ������ 192.168.1.5 �� ���� 8000

C.2.1.6.3. ������� ������������

�������� �������� ��������� � ����������� ������� � ����������� ������������ �������. ��������, ���� � ��� �� ���������� ���� ��������� web-������ � �� ���������� �� ���� ������ �� ��������, �� ������������� ����� ��������� ���������� � ������ web-������� ��� CGI ��������, �������� ������ � web-������� �, ����� �������, ��������� � ����ݣ���� ���� ��������� ����.

������� ���� ������������� �������� �������� ����� ��ԣ� ���������� ������������������ ���� DMZ (��. DMZ).

C.2.1.6.4. ��������������� � ���������

��������������� ����� ������������ ��� �������������� ������� ������� ������� � ����������� �������:

server = 192.168.1.40
rdr on $ext_if proto tcp from any to $ext_if port 80 -> $server \
   port 80
            

������ ��� ������������ ������ ��������������� �� ���������� ���� ��� �� ��������. ���� � ���, ��� ������ �� ���������� ���� �� �������� ����� ������� ��������� ����� ($ext_if � �������) � ������ �� ������������ ����������.

���������� ������� rdr ������� �� ������� ��������: ����� �������� ����� ���������� ���������, ��� �������� ����� ���������� � �� ������������ �� ������, ������ ��������� ����� ��� ���� �� ������������ � ������� ������ ����� ������� ��������������� ������� ����� ����. ������ ��� ���� �ģ� ������ �� �����, � �� �� �������. ����� �������, ���������� ��� � �� ����� �����������.

� �ӣ ���� ���������� �� ���������� ���� ������ ������ ��� �� ��� �� ����� �� ������� � ���, ����� ��� ������� �ӣ ���� ���������. ���������� ��������� �������� ������� ���� ��������.

C.2.1.6.4.1. �������� ���������� DNS

������ DNS ����� ��������� ���, ��� �� ����� ������ ������ ������ � ������ ����. ����� ������� ���, ����� ��������� ������� ������ �� ������ ���������������, ��� ������ �����. ����� �������, � ���� ��, ������� �������� �� ����.

C.2.1.6.4.2. ����������� ������� � ��������� ����

����� ����������� ������ � ��������� ���� (��. ��� �� DMZ) � �������� ����� ������� ��������� � ����.

C.2.1.6.4.3. TCP proxy

����� ���������� ������������� TCP ���������� ��� ������ ���������� �� userspace. ���������� ������������� ����������, ������������� ���������� � �������� � ����� ������������ ������ ����� ����. ���������� ������ ����� ������� ��� ������ inetd(8) (��. �����̚5.17.2, «����������� inetd(8)»)� nc(1) (��. �����̚6.4.4, «telnet(1), nc(1)»). ��������� ������ � /etc/inetd.conf(5) ������� ����� ����������� � ���������� ����������, ���� ����� 5000. ���������� �������������� �� 80-� ���� ������ 192.168.1.10:

127.0.0.1:5000 stream tcp nowait nobody /usr/bin/nc nc -w 20 192.168.1.10 80
              

������ �� ���������� ���������� �� ����� ������� 80-� ���� � ����� proxy-��������:

rdr on $int_if proto tcp from $int_net to $ext_if port 80 -> \
   127.0.0.1 port 5000
              
C.2.1.6.4.4. RDR � ���������� � NAT

� �������, � ���������� � �������� NAT ����� ������� ����, ��� ���������� ������� ��������� ��� �� ����� �������������� � ���������� ����� ��������������� ��������� �������.

rdr on $int_if proto tcp from $int_net to $ext_if port 80 -> $server 
no nat on $int_if proto tcp from $int_if to $int_net
nat on $int_if proto tcp from $int_net to $server port 80 -> $int_if
              

��� ������� �������� � ����, ��� ������ ����� ����������� �� ������� ����� ������ ������������, ����� ����� ��������� ����� ���������� ���������, ��� ���� � ���� ����� �����Σ� ����� ��������� �� ���������� ����� �����. ���������� ������ ������� �����, ������� ���Σ� ������ ������� ��������� NAT � RDR ����������� � ����� ���������� � �������. ��� ���������� ������� ��ɣ�. ����� ������������, ����� �� ��������� ������� NAT � ������� �������, �������� � ������� ����������� (��������� ����� ������ ������� rdr) ��� � ����������� ������ �����. ��� �� ������ �����, ��� ��� �������������� �������� � ����, ��� TCP/IP ���� ����� ������ ������, ���������� ���������� �����������, ��� �������������� ������ ����.

������ ������������ � ��������� ������� ����������� � ����� ������ ������������ �����-������ �� ���������� ������� ������ ����������.

C.2.1.7. ��ɣ�� ������������ ��� ��������� ����� pf.conf(5)

�������� ������ ������������� ��������� ������� ��������� ����������������� �����. ������� �������� �������� ������������� ������� � ��������. �������� ���� � ���������� pf.conf(5) ������ ����� � ��������� � ���� ������� �������� �������� ����� � ����������� �� � ������ �������, ����� ������� ������������� �� ������ ������� ��������� ����� pf.conf(5). � ����� ����� �������, ��� ��� ����� �������, ��� ����� ������������ ��������� �����������.

C.2.1.7.1. ������������� ��������

������� ������� ��� ��� ��������� ������������ �������� ����� ������ �ͣ� ����������� � �������. ���� �������� IP ����� ������� ����� ������ �������������� ������ ������ ����, ����� ������������ ���� ����. ����������� ����������� �������� �ͣ� �����������. ������� ��������� ��������� ��������������� pf.conf(5) � ������ ������ ������� ����� ��� ��� ������������� �������� ������ � ���� �� ����� � ����� ������ �� ������.

������:

# define macros for each network interface
IntIF = "dc0"
ExtIF = "fxp0"
DmzIF = "fxp1" 

# define our networks
IntNet = "192.168.0.0/24"
ExtAdd = "24.65.13.4"
DmzNet = "10.0.0.0/24"
            

���� � LAN �������� ����� ����, ��� ���� ����� ��������������, ���������� ����� �������� ���� ������:

IntNet = "{ 192.168.0.0/24, 192.168.1.0/24 }"
            

������ ����� ������������ ������ �ӣ ����� �������� ��-��������.

C.2.1.7.2. ������������� �������

��������� 8������ ������ ��� ����, ����� ����������� ������ ��������� � ���������� ������, ��������� � [RFC-1918], ���������� ����� ������� � ���������� ���� ����� ������� ��������.

block in  quick on tl0 inet from 127.0.0.0/8 to any
block in  quick on tl0 inet from 192.168.0.0/16 to any
block in  quick on tl0 inet from 172.16.0.0/12 to any
block in  quick on tl0 inet from 10.0.0.0/8 to any
block out quick on tl0 inet from any to 127.0.0.0/8
block out quick on tl0 inet from any to 192.168.0.0/16
block out quick on tl0 inet from any to 172.16.0.0/12
block out quick on tl0 inet from any to 10.0.0.0/8
            

�������� ��� ������� ��� ������ �������:

block in  quick on tl0 inet from { 127.0.0.0/8, 192.168.0.0/16, \
   172.16.0.0/12, 10.0.0.0/8 } to any
block out quick on tl0 inet from any to { 127.0.0.0/8, \
   192.168.0.0/16, 172.16.0.0/12, 10.0.0.0/8 }
            

�ݣ �����, ���� �� ������� ��� � �������������� ��������:

NoRouteIPs = "{ 127.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12, \
   10.0.0.0/8 }" 
ExtIF = "tl0"
block in  quick on $ExtIF from $NoRouteIPs to any
block out quick on $ExtIF from any to $NoRouteIPs
            

��������, ��� ������� � ������ �������� ���� pf.conf, ������ ���������� ������ �ӣ ����� ������������ � �� �� 8�������.

������� ����� ������������ �� ������ ��� �������� �������, ����������� � ������, �� ������ �����:

pre = "pass in quick on ep0 inet proto tcp from "
post = "to any port { 80, 6667 } keep state"

# David's classroom
$pre 21.14.24.80 $post

# Nick's home
$pre 24.2.74.79 $post
$pre 24.2.74.178 $post
            

��� ������� ������������ � ���������:

pass in quick on ep0 inet proto tcp from 21.14.24.80 to any \
   port = 80 keep state
pass in quick on ep0 inet proto tcp from 21.14.24.80 to any \
   port = 6667 keep state
pass in quick on ep0 inet proto tcp from 24.2.74.79 to any \
   port = 80 keep state
pass in quick on ep0 inet proto tcp from 24.2.74.79 to any \
   port = 6667 keep state
pass in quick on ep0 inet proto tcp from 24.2.74.178 to any \
   port = 80 keep state
pass in quick on ep0 inet proto tcp from 24.2.74.178 to any \
   port = 6667 keep state
            
C.2.1.7.3. ���������� ��������� �������

�������� ������ �������� ������ � ���� ����� ���������� �����������. ��� ������������� ������ ������� ������� �������� ���� � ������ �������������� ������-�� ������̣����� �����.

C.2.1.7.3.1. ����� �������� �������� �����

��� ����������� �������� ������������� �� ��������� ������, ������� ������ ��� �������:

block in  all
block out all
              

��� ����� ��������� ��

block all
              

����� ����������� �� �������, �������� ������ �������, ��� ������ ������� � ��� �������.

���������� ����� �� ������ from any to anyall, ��������:

block in on rl0 all
pass  in quick log on rl0 proto tcp from any to any port 22 keep state
              

����� ��������� ��

block in on rl0
pass  in quick log on rl0 proto tcp to port 22 keep state
              

������ ������� ��������� ��� ������ �������� ����� ��������� rl0. ������ ���������� �������� ������, ���� ��� ���� �� 22-� ����.

������� ����������� ������ � ���������� ������ TCP RST � ICMP Unreachable ������ ��������� ���:

block in all
block return-rst in proto tcp all
block return-icmp in proto udp all
block out all
block return-rst out proto tcp all
block return-icmp out proto udp all
              

�� ����� ��������� �� ����� ������:

block return
              

����� �������� ������ ����� �������� �����return, �� ��� ������������ �� ����� �������� ����� ������� ������� ��������, � �� ����� ��������� ������ �� ������� �������� �������� ������ ��� ������������ ����������.

C.2.1.7.3.2. ������� ���������� �������� ����

������� ���������� �������� ���� � ����������� ������� �����. ��������, ��������� �������:

pass in log quick on rl0 proto tcp to port 22 \
   flags S/SA keep state queue ssh label ssh
              

����� ���������� ���:

pass in quick log on rl0 proto tcp to port 22 \
   queue ssh keep state label ssh flags S/SA
              

������ ������� �������� ���� ����� ��������.

C.2.2. �����̣���� ���������������� ��������� �������

C.2.2.1. ����� � �������� �������

����� � pf.conf(5) ��������������� ��� ������ ��������� set.

[���������]���������
������� � OpenBSD�3.7 ��������� ��������� ��������� ������� ������������ �����: ������, ���� ����� ���������������, ��� ��� ������� �� ��������� ������ �������� �� ���������. ������, ����� ��������� �������� �� ���������, ���� ţ ������� �� ������, � ����� ������������� �������.

������ ������� ����� � �������� �������:

set timeout interval 10
set timeout frag 30
set limit { frags 5000, states 2500 }
set optimization high-latency
set block-policy return
set loginterface dc0
set fingerprints "/etc/pf.os.test"
set skip on lo0
set state-policy if-bound
          
set block-policy option

���������� ��������� �� ��������� ��� ������ �������, ����� ����������� ������� block. ��������� ��������:

  • drop�— ����� ����� �������������;
  • return�— ��� ����������� ������� TCP ���������� ����� TCP RST, ��� ������ ICMP Unreachable.

� ���������� �������� �������� ����� ����� ���� ��������������. ��������ڗ drop

set debug option

���������� ������� ������� ��� ��������� �������:

  • none�— �� ���������� ���������� ���������;
  • urgent�— ���������� ��������� ������������ ��� ���أ���� ������.
  • misc�— ���������� ��������� ��������� ��� ��������� ������ (�������� ������ ��������� ������� ������������ ������� (scrub) � ������ � ������ ������� ���������);
  • loud�— ���������� ��������� ������ ����� (��������� ������� ��������� �� ������� osfp).

��������Ś— urgent. ������� ������� ����� ����� �������� ��� ������ ������� pfctl(8) (����� -x, ��. �����̚C.3, «���������� �������� �������� OpenBSD ��� ������ ������� pfctl(8)»).

set fingerprints file
���������� ����, �� �������� ����� ����� ���������� ��� ������� osfp. ��������ڗ /etc/pf.os.
set limit option value

���������� ������ ��� ��������� �����:

  • frags�— ������������ ���������� ������� � ���� ���������� �� ������������ ������� (scrub). �� ����������— 100.
  • src-nodes�— ������������ ���������� ������� � ���� ���������� �� ������������ ��������� IP �������. (��� ������������ ��������� � ��������� ������� sticky-addresssource-track). ��������Ś— 10000.
  • states�— ������������ ���������� ��������� � ��� ���������� �� ��������� ������� ��������� ���������� (������� ��������� ��� ������ ������ � �������� ������ keep�state, ��. �����̚C.2.1.4, «���������� �������»). ��������� 10000.

�������� ���������: set limit { states 20000, frags 20000, src-nodes 2000 }

set loginterface interface

������ ��������� ��� �������� �������� ������ �������� �������������� ����������: ���������� ��������� �������, ���������� ��������������� �������, ������� ���� �����, ������� �����. ���������� ����� �������� ������������ ������ �� ����� ����������. ��� ����, �ޣ����� match, bad-offset ɚ�.�., � ����� �ޣ����� � ������� ���������, �������� ���������� �� ���� �����. ����� ��������� ���� ���������� ������� ��������� ����� � none. �������� �� ����������— none.

����������� ���������� ����� ��� ������ ������� pfctl(8) � ������ -s�info. ��. �����ҚC.1, «�������� ���������� �� ���������� ��������� ��� ������ ����� loginterface»

set releset-optimization value

��� ������������������ ������� � OpenBSD�4.1 � ���� �ݣ ����� �� ��������. ����������� ������ ����� �������� ��������������� � pf.conf(5), � �� ������ ��� ����� pfctl(8) (��. �����̚C.3, «���������� �������� �������� OpenBSD ��� ������ ������� pfctl(8)», ����� -o).

value ����� ��������� ��������� ��������:

none
��������� �����������
basic

��������� ��������� �����������: 1)�������� ������������� �������; 2)�������� �������, ���������� ������������� ������ ������; 3)����������� ��������� ������ � �������, ��� ��� ��������; 4)�������������� ������� ��� ������ ������������������.

�� �� ����������� ��������� ����� -o ������� pfctl(8).

profile
��������� ��� ����� ����� quick. ���� �� ������� ����� �������� ��� ������ ���� ����� -oo � ��������� pfctl(8).

��� ����������� ����� ���������� ������� ������, ��� ����� �������� � ��������� � ������ ����������� �������. ��� �������������� ����������� ����� ����������� � �������� ����� label.

set optimization value

���������� ����������� ��������� ������� ��� ���������� ��������� ����:

  • normal�— �������� �� ���� �����.
  • high-latency�— �������� ��� ����� ���������� � �������� ����������, �������� ����� �������.
  • aggressive�— ���������� ������� ������� ���������. ��� ����� ����������� ��������� ���������� � ������ �� ����������� �����������, ������ ������� � ������ ���������������� ������� ����������.
  • conservative�— ������ �������������� ����������. ������������� ������ ����������, ������ �������� � �������� ������� ������.

��������ڗnormal

set skip on interface
��������� ������������ ��������� ���������. ����� ����� ����������� ��� ���������� ����������, ��� �� ��������� �� ���������� �������, �� ������������. ����� ����� ���������� ��������� ���, �� ��������� �� �����������.
set state-policy value

��������� ��������� ������� ��� ������������� ������� ��������� (��. �����̚C.2.1.4, «���������� �������»). ��� ��������� ����� ���� �������������� � ���������� �������� ����������:

  • if-bound�— ��������� ������������� � ����������� ����������, ����� ������� ���ۣ� ������ �����. ���� ����� ���ۣ� ����� ������ ���������, �� �� ����� ��������������� ������� ����������.
  • group-bound�— �� ��, �� ��������� � ������ ����������� (� OpenBSD, �� �� � FreeBSD, ���������� ����� ���������� � ������).
  • floating�— ������ � ������� ��������� �� ��������� � �����������.

��������ڗ floating

set timeout option value

������ �������� � ��������:

interval
�������� ����� ��������� �������� ������ ��� ��������� ��������� ������. �.�. ����� ����, ��� ���������� ��������� � ������ ����� ���� ������� �� ������� ���������, ����ģ� �ݣ interval ������, ������ ��� ������ ����� ������� �� ������� ���������. ��������Ś— 10
fragment
�� ��������� ������� ��������� ������� ����������������� ����� ����� ��������, ���� �� ���ģ� ��������� ��������. �� ����������— 30.
src.track
������� ������� ������� � ������ ���������� �� ��������� IP ��� ������ source tracking (��. �����̚C.2.1.4.7, «����� ������� ���������») ����� �������� ������ �� ������� ���������. �� ����������—0.
proto.modifier

����� � ������� �������� � ������� ��������� �������� ������ � ��������. ����� proto ����� ���� tcp, udp, icmp ��� ���-�� (����� other), � modifier ��������� �� ��������� ��������. ����������:

TCP:

tcp.first
��������� ����� ������� ������� ������ (SYN)
tcp.opening
��������� ����� ���� ��� ���� ���������� ������� ������� (SYN,ACK)
tcp.established
��������� TCP ESTABLISHED
tcp.closing
��������� ����� ������� ������� ������ � ������ FIN.
tcp.finwait
��������� ����� ����, ��� ��� ������� ��������� ���� ����� ������ FIN. ���������� � ���� ������ ���������, ��������, �� �� ���� �ݣ ����� ������ �������������� ������ FIN.
tcp.closed
��������� ����� ����, ��� ���� �� ������ �������� ����� � ������ RST.

UDP:

udp.first
��������� ����� ������� ������� ������
udp.single
��������� � ������� �������� ���������� ���� �������� ������ ����� ������ ������, � ���� ���������� �� ������� � ����� �� ������.
udp.multiple
��������� � ������� �������� ����������, ���� � �������� � � ���� ���������� ������������ �������� � ��� �������.

ICMP:

icmp.first
��������� ����� ������� ������� ������
icmp.error
��������� � ������� �������� ����������, ���� � ����� �� ����� ICMP �������� ��������� �� ������.

������ ��������� �������������� ��� � UDP: other.first, other.single, other.multiple

set adaptive.start value
���� ����� ������� � ������� ��������� ��������� ��������� � ������ ����� ������, ���� ���������� � ���������� ���������: ��� �������� ���������� �� �������� (adaptive.end - ����������_�������_�_�������_���������) / (adaptive.end - adaptive.start)
set adaptive.end value
���� ����� ������� ��������� ���� ��������, ��� �������� ���������� � ���� � ������� ��������� ���������. ������ ������ �� ������ ����������� � �����. �� ����������� ������ ��� scale-������, ��� ������� �������� ����.

������: ����� � pf.conf(5) ��������:

set timeout tcp.first 120
set timeout tcp.established 86400
set timeout { adaptive.start 6000, adaptive.end 12000 }
set limit states 10000
                

�����, ���� ���������� ������� � ������� �������� �������� 9000, �� ��� �������� ����� ��������� �� 50%, � ��������� tcp.first ����� ����� 30 ������, � tcp.established 43200 ������.

C.2.2.2. ������������ ������� (Scrub)

������������ ������� ����� ��� ����, ����� ��������� ��������̣������ � ��� ���� ������������ �����. ����� ����, ��� ������������ ���������� ������ ����������������� ������, ���������� ������ ������������ ������ �� ���������� ���� ���� � ������������� TCP ������ � ����������� ���������� ������. ���������� ��������� �������� ���:

scrub in all
          

��� �������� � ������������ ����� ��������� ������� �� ���� �����������.

���� �� ��������� ������ ��� ��������������� �����������ɚ— ������������� NFS. ��������� �� OpenBSD ��������� ���������� �������� �����ٚ— �����������������, �� � ������������ ����� «�����������������», ������� ������ ������������� �������� �������� ��� ������������. ��� �������� ����� ��������� ��� ������������� ����� no-df. ������ ������� ����� �������� � ���, ��� ��������� ��������������������� ������� ���� ����������� �������� �������� � ���������� ��������������. �� ���� ��������� �������, ����� �����ģ���� ������ ��������� ��������, ������������ ������� ������ ����������.

��������� ��������� scrub ������ ���������� ��������� ������ ���������� (��. �����̚C.2.1.4, «���������� �������»). ��� � � ������ � NAT �����������, ������ ������� ����������. ����� ���������� scrub ����� ����������� �������� ����� no, ����� ��������� ������ �� ���������������.

Scrub ����� ��������� �����:

no-df
������� ��� «�����������������» �� ��������� IP. ��� ��������� ������������ ������� ��������, ��� ��� ���������� ���� ��� �� ����������������� ������� ��� ������ � NFS. ������������ ����� ����������� ����� ������, ���� �� ������� ������ �����. ��������� ��������� ������������ ������� ���������� ����� ������ � ������� ��������������� IP, ������������� ����������� ������ ����� ������ � ������ random-id.
random-id
�������� ������������� IP ��������� ��������� ��� ����������� ��������� ������ ������������ ������������� ��������������. ����� ����� ����������� ������ � ������������������� �������.
min-ttl num
��������� ����������� TTL � ������ IP.
max-mss num
��������� ������������ ������ �������� � ��������� IP.
fragment reassemble
������������ �������� ������ � �������� ������ ����������������� ������ ����� ��������� �� ������� �������. ������� � ���, ��� ������ ����� ���� � �������� ������������������� �������� � ����� ����� �������. �������� � ������� ������ � ���������� ����������� ������� ����� �������� ������.
fragment crop
� �����, ��� ������������ IP ������� ��� ������ ���������� �� ����� ��� �����̣����. ���� ��������� ����������� ��� �������������, ��� �� ���������� ��������. � ����� ������ ����� ������� ���� �� ����: ���� ������� ��������, � ��������������� ��������� ��������, ���� �������� � �� � ������ �� �������������� ������������. ������ ������ ����� fragment crop, �����Ś— fragment drop-ovl. � ����� ������� ������ �� �������������� ��� � ������ fragment reassemble.
fragment drop-ovl
����������� ������ � ������� ���������� ������� � ��������� (��. ��������� � ���������� �����).
reassemble tcp

������������ ���������� TCP �� ������ ������� ���������. ��� ������������� ������ ����� ������ ��������� ����������� in/out. �������������� ��������� ������������:

  • �� ���� �� ������ �� ����� �������� TTL. ��� ����� ��� �������������� ���� �� ����������, ����� ������������� �������� TTL � ����� ���������� ������� ���������. TTL ������������ � ��������� �������� ����������� �� ����� ��������.
  • ������������ ��������� timestamp � ��������� IP, � ���, ����� ������������� �� ��� ���������� ��� ����� ����� ��������� �� ������ � NAT.

������:

scrub in on fxp0 all fragment reassemble min-ttl 15 max-mss 1400
scrub in on fxp0 all no-df
scrub    on fxp0 all reassemble tcp
          

C.2.2.3. Anchors

[���������]���������
��� ��� ������� ��������� ��� ����� �� ������ ���� ���������� ��������. ����� ��� �������� ��������� ������������, ������� � ���� ����������� ����� anchor. ���� ���, �� ��������� ������Ě— �����. ����� �������� �����: ����ؚ— ��� ����� ���� ������������ �������� ������ � ������������ ����� ��� ��� ���������. ������ ����� ����� �������� ������� �� �������� ����������� �������� ���������. ������ ������ «�����» ������� ����� �������� ������, � �������� ������ ������ ������� «����������� �������� ������». � �������� ���� ����� � ������ ����������.

�������� � ������� ������� ������ �������� ������ ����� ������������ ���������. ���� ������� ����� ������������ ��� ������������ ����� �� ���� ������� IP-�������, �� ��������� ������ ����� ������������ ��� ������������� �������������������� �����������. � �� ������� ����� ������ ������ ������ �������, nat, binat � rdr.

��������� ������ ����� ��������� ��� ������ «������»,�— anchor ���������� ������ ���� anchor'��:

��������� ����� ���� ���������� � �������� ���� ����� �� �������. ������� anchor �������������� � ��� �����, ��� ��� ����������. ��������, ������� anchor � �������� ���������������� ����� ������� ��������, ��������� �������� ��������� ������� ����� ������, ������ ��������� ����������� � ������ ��������� ��� ������ ��������� load�anchor �������� ��� ���������.

C.2.2.3.1. ����������� ������ ������

����������� ����Қ— ��� ������ ������ ����������, �/��� ������ ����������, ������� ���� ��������� ���. ����� �������� ������ ������������ ����� � ������� ������ ������, �� ���������� �������� ���� ���������� ������ ����������� � ����.

������:

ext_if = "fxp0"

block on $ext_if all
pass  out on $ext_if all keep state
anchor goodguys
            

���� ����� ������ ������������� �� ��������� �������������� �������� �� ���������� fxp0 ��� ����� ��������� � ���������� �������. ����������� ���� ��������� ������ � ������������ ����������� ����� ������ goodguys. ����� ����� ���� ������� � ��������� ����� ��������:

  • ��������� ������� load
  • ��������� pfctl(8)

�������� ������ ��������� pfctl(8) ��������� ������� �� ���������� �����. ��������:

load anchor goodguys:ssh from "/etc/anchor-goodguys-ssh"
            

����� ����� �������� ������� �����, �������, ������������� � ����� /etc/anchor-goodguys-ssh ����� ��������� � ����������� ����� ssh, ��������������� � ������ goodguys.

��������� pfctl(8) ����� �������� ������� � �����:

# echo "pass in proto tcp from 192.0.2.3 to any port 22" | pfctl -a goodguys:ssh -f -
            

����� �������, �� ��������� ������� pass � ������������ ������ ssh ���������� � ������ goodguys. �������� ������ ����� ��������� ��� �������, ����� ����ң��� �� ����� goodguys.

������� ����� ����� ���� ��������� � ��������� �� ���������� �����:

# cat >> /etc/anchor-goodguys-www
pass in proto tcp from 192.0.2.3 to any port 80
pass in proto tcp from 192.0.2.4 to any port { 80 443 }
# pfctl -a goodguys:www -f /etc/anchor-goodguys-www
            

��� �������� �������� ������� �� ����� /etc/anchor-goodguys-www � ���������� ����� ������ www ����� goodguys.

��������� ������ ������ ����� ���� ����������, ���������� ����������� ������� ��� ������� ��������� � ��������� �����:

anchor "spam/*"
            

��������� ������ � ������������ ������� ������ ����� �� ��� � � ������� ������ ������, �� ��� ������������ ������� ������ ���� ���������� � �������� ����� �� ������: �������, ������̣���� � ������� ������ �� ����� �� ������������ ������.

������ ����������� ����� ���������� ����������� �� ���������. ��������, ���������� ��� ���, ����� ��� ����� ������, �� ����� ������� ��� ����������. ����� ����, �������� ��������� �� ����� �� �������� � �������� �� ������ ����� �� ����������� � ���� ����������� ������� ������. ����������� ����� ���������� �� ��� ���, ���� ��� ��� ������� �� ����� ��������, ��������� pfctl(8). ����� ������������ ��� ������ �� �������� �� ������ ������������ � ���� ������ ������.

C.2.2.3.2. ����� �����

������� anchor ��������� ��� �� ������� ���������, ��������, ������ ��������� � ���������� � ������. ��������� ���������� ���������� ������ ����������. ���� ��� ���������� ����, �� ����� ������ ��������������� ����� ������������ ��� ������ ������ ������ �������� �������������:

ext_if = "fxp0"

block on $ext_if all
pass  out on $ext_if all keep state
anchor ssh in on $ext_if proto tcp from any to any port 22
            

������� �� ����� ssh ����� �������������� ������ ���� ����� ��� TCP � ���ۣ� �� 22-� ���� ����� ��������� fxp0. ������� � ����� ����� ����������� ���:

# echo "pass in from 192.0.2.10 to any" | pfctl -a ssh:allowed -f -
            

�������� �� ��, ��� � ������� �� ������̣� �� ����, �� ��������, �� ���������, ����� 192.0.2.10 ����� ��������� ������ ������ �� ��������� ssh, � ���� ����������� ��������� ��� ���������� �����.

C.2.2.3.3. ���������� ������������ ��������

���������� ������������ �������� ������ �������������� ��� ������ ������� pfctl(8). ��� ��������� ������� � ��������� ������� � ����� ��� ������������ �������� ������ ������.

������� ������ ������ �� ������ ssh:

# pfctl -a ssh -s rules
            

�������� ����� ������ ssh:

# pfctl -a ssh -F rules
            

C.2.2.4. �������, ���������� (����������� ������ �����������)

C.2.2.4.1. �������

��������� ���-�� � �������, ������ ��������� ��� �� ���������. ��� ������ � ����, ������ ���������� ������ ��������� � ������� � ����, ����� ��� ����� ���������� ������������ ��������, ��� ���� ��� ������, ����� ������ ������ � � ����� ������� ������������. ��������� ������� ��������� ������� ����� ������� ������� �� ������������������ ����. � ��������� ������, ������ ssh ������ �������������� � ������ �������, ��� ��� ���� �������� ����� ������������ � ���������. ��� ������� ������� � ssh-������� ��������� ����������� �����, �� ������ �������� �� ftp �������� �������� � ��������� ������. ��� ����� ��������� � ������, ����� ������ ������������ ������� ���������� ftp �������? ������ ssh ����������� � �������, � �� � ������ ������������� � ������ ������ ������ � � ���������� ssh ������ ����� ������ ����������. ��������� ��������� ����������� �������� ����� ��������� ������������ ���������� ����������� ����� ���������� ������������, �������������� � �������.

�������� ��������, ��� ����������� ������� ����� ����� ������ ��� ��������� ����������, ������ ��� ��� ������ ����� ����� �� �������� ��������� � ��� ��� ������ ���-���� ������, ��� ��� ������ ����������� ������ ���� ��� ������������. ������������ �������� ���� �������� ����� ����� ����������� ������� �� ������� �������������� ��� ��������� ����������� ������� �� ���������� ����������, ���� ���� ��� �������� ������� ���������������.

C.2.2.4.2. ������������

������������� ���������� ��, ��� �������������� ������� � ���������� ������� ��������� �������. �� ��������� � OpenBSD � �������� ������������ ������������ FIFO, �������. ������� ţ ������ ����� ����Ԛ— ������ ��ۣ̚— ������ �����. ������������� ����� ����������� � ����� �������. ��� ���������� ������������� ������� ������� ����� �������������. ��� ������� �������� ��� tail-drop (������ ������, ��� � �������).

���� � ������ ������������. OpenBSD (� FreeBSD) ������������ �ݣ ��� ������������:

  • ������� ���������� �� ������� (Class Based Queueing, CBQ)
  • ������������ ������� (Priority Queueing, PRIQ)
  • HFSC (Hierarchical Fair Service Curve). �� ������ ���� ������ ����� ����� �� CBQ. �� ������� ����������� �������� ���: ������������� ������� ���������� �� �������� ����������� ������ �������. ��. ��������� � �����̚C.2.2.4.2.3, «HFSC»
C.2.2.4.2.1. ������� ������������ �� �������

� �������� ������������ �� ������� (CBQ) �������� ����������� ������� �������� �� ���������� ������ ����������� ����� ���������� ��������� ��� ��������. ������ �������������� � ������� �� ��������� ������ ��������� ��� �����������, �����, ��������� � �.�. ������� ����� ���� ���������������� �� ������������� ������������ ������ ����������� �� ������������ �������, ���� �� �������� ���� ����� �� ���������. ������� ����� ����� �������� � �������� �����������, ��������, ��������� ssh ������ � ������ �������, �� ��������� � �������� ftp.

CBQ ������� ����������� ������������� ��������. � ����� ����՚— ������������ �������, ������������ ����� ���������� �����������. �������� �������� ����������� ��������� ����� �� ������ ����������� ������������ �������. ��������, ������� ����� ���� ���������� ��������� ��������:

Root Queue (2Mbps)

   Queue A (1Mbps)
   Queue B (500kbps)
   Queue C (500kbps)
              

����� ����� ������ ����������њ— 2 �������� � ������� (megabits per second�— Mbps), ������� ��������� �� ��� ����������.

[���������]���������
������ ����������� ������ �������� � ����� � �������. ��� ���� 1000�bps = 1�kbps, 1000�kbps = 1�Mbps. 1�Mbps = 125000 ���� � ������� ��� 122 ��������� � �������.

�������� ����� ���� ��������� � �������������� �����������. ��� ����, ����� ��������� ������ ����������� ����� ���������� ��������������, ��� ���� ������ ���, ��� �� ��������� ���� ������� �� ������ ���� �����, ����� ������� ��������� ��������� ��������:

Root Queue (2Mbps)

   UserA (1Mbps)

      ssh (50kbps)
      bulk (950kbps)

   UserB (1Mbps)

       audio (250kbps)
       bulk (750kbps)

          http (100kbps)
          other (650kbps)
              

�������� ��������, ��� �� ������ ������ ����� ����� ����������� �� ����� ���� ������ ������������.

������� ����� ���� ��������� ����� �������, ��� ����� ������������ (borrow) ������ ����������� � �������� � ������ ��������������� �� ������� ���������. ���������� ����� ����������� �������:

Root Queue (2Mbps)

   UserA (1Mbps)

      ssh (100kbps)
      ftp (900kbps, borrow)

UserB (1Mbps)
              

���� ������ � ������� ftp ��������� 900�kbps, � ������ � ������� UserA�— ������ ��� 1�Mbps (������ ��� ������� ssh ���������� ������ ��� 100�kbps), ������ ����������� ftp ����� ���� ���������. ����� ������� ������� ftp �������� ������������ ������ ��� ����������� �� 900�kbps, �� � ������ ���������� ������� ssh ������������� ������ �������������.

CBQ ����� ��������� ������ ������ ������̣���� ���������. � ������� ���������� ������������ �������� �������� � ����� ������� ����������� � ������ ������� � ��� ������ ��������. ��� ���������� ����������� ������� ������������� ����������. ��� �������:

Root Queue (2Mbps)

  UserA (1Mbps, priority 1)

     ssh (100kbps, priority 5)
     ftp (900kbps, priority 3)

UserB (1Mbps, priority 1)
              

������� UserA � UserB ����� �������������� ����������, ��� ��� �� ���������� �����. � ������ ���������� � ����, ������������ ����� ���������� ssh, ��� ��� ţ ��������� ������, ��� � ������� ftp. ��� ���� ������� ssh � ftp �� ����� ���������� ����� ��������� UserA � UserB, ��� ��� ��� ��������� �� ����� ������ ������.

��������� ���������� � CBQ ��������� � References on CBQ.

C.2.2.4.2.2. ������������ �������

������������ ������� (PRIQ) ��������� �� ������� ����������, ������ ��������� �������� �������� ������ʚ— ������ ��������� �������� �������. ������ ������������ �������� ������� � ��������� ����� ���������� �����������, � �� ��� ��� �������� �������. ��������:

Root Queue (2Mbps)

   Queue A (priority 1)
   Queue B (priority 2)
   Queue C (priority 3)
              

���������� ����������� �������� ������� ���������� ��� 2�Mbps, ������ ���� ��������.

��� ������������� PRIQ �� ������ ����� ��������� ����������� �������, ��� ��� ��� �������������� ������ �� ����������� � ���� ������ � ������� ����������� ���ͣ� ���� �����, ������ ������������� ������� � ������ ����������� ����� �������������.

C.2.2.4.2.3. HFSC

������� ������̣���� �� ����������� ������������� � ������������� �����, ������ ������� ����� ����� �������. ������ ������� ����� ����� ���� ��������� � ���� ������ �����������. ���� ��� ������� ����� �� CBQ. �������� ������� HFSC �� CBQ � ���, ��� ��� ��������� �������� ������������ �������� � ���������� ����������� �������.

CBQ ������������ �������� ������� ��� ������ �����������. ���� �� �������� «������ �������» (����������� ������� �� �������), �� ��� ����� ��������� ������. ������������ ������ ������� �������� ��� ������ ����� ������� ������� � ���, ����� ��������� ������ �����������.

HFSC ������ ������� ������� �� ���� �������� ��������:

������ service curve
������ service curve. m1�— ������ ������� ������� ������, ������������� ��������� ������ ����������� �, � ������������ � ���������� d, ��������� ������������ �������� ���������� �� ������ �����������. d�— ����� � ������� �������� ��������� ������ ����������� m1. m2�— �������� ������ �����������.

�������������� ���������� � HFSC ����� ���� ������� �� ������ http://www.cs.cmu.edu/~hzhang/HFSC/main.html.

C.2.2.4.2.4. ��������� ������ ���������� (RED)

��������� ������ ����������� (Random Early Detection, RED)�— ��� �������� ����������� ���������� ������. ��� ����� �������� �������������� ������������ �������. �������� ��� ��ԣ� ������������ ��������� ������� ����� ������� � ����������� � ������������ ��������. ���� ����������� ����� �� ��������Ԛ— ��� ������ ������������. ���� ��������� ������������ ����ǚ— ��� ������ �������������. � ���������� ������ ������������� � ������̣���� ������������, ��������� �� ������� �������. ��� ����� � ������������� �����՚— ��� ���� �����������. ������ ��� ������������ ���������� ��������� ������� �� ������ ������. ��� ������� ������ ����������� ���������� �������, ��� ���� ����������� ������ �� �ţ ������.

RED ������ �������, ��� ��� ��������� �������� ��������, ���������� «���������� ��������������», ��� ����������� � ���, ��� ����� ��������� ������������ ��-�� ������������ ������������� ������� � ������ ������. ��������, ���� ���������� ���������� �� ��������������, ������������� 10 ������������� ������ ftp � ����� ��������� ������ �� ����������� ��� ���� ������, ����� ���������� ����������� ����� ���������. RED ��������� �������� �����, ������� ������ �� ������� ������ ������ ��������� �������. ��������� ������ ���������� ������ ������ ����������� ����� ������� ���� �� ������ ������, �� ����������� ������������� ���������� �������� � ������� ������ ������� �� ����������. ����� ����, RED ��������� ���������� �������� ������� �������, ��� ��� �������� ����������� ������ �� ������������ �������.

RED ������ �������������� ������ �����, ����� ������������ �������� �������� ����������� �� ���������� ���������� ����. � ����������� ������� ��� ��������, ��� RED ������ ����������� ������ � �������� TCP, � �� � �������� UDP ��� ICMP.

��������� ���������� � RED ��������� � References on RED.

C.2.2.4.2.5. ����� ����������� � ���������� (ECN)

����� ����������� � ���������� (ECN) �������� ��������� � RED � ����������� ��� ����������� ���� ��������� ������ � ���������� ����. �������� ��� ����������� RED ���������� ���� � ��������� ������, ������ ����, ����� ��������� �����. ���� ���̣���� ���� ������������ ECN � ������ ����� ECE � CWR, �� �� �������� ������� ��������� ������ (��. ��������B.3, «����� TCP», [RFC-3168]).

C.2.2.4.3. ���������������� �������

������� � OpenBSD�3.0 Alternate Queueing (ALTQ) ���� ������ �������� �������, � � ������ OpenBSD�3.3 ALTQ ��� ������������ � �������� ������ �, �������������, ���������� ������ � ��� � � FreeBSD. ���������� ALTQOpenBSD ������������ ������������ CBQ PRIQRED ������ � ECN.

������� ��������������� � ����� /etc/pf.conf(5). ���� ��� ���� ��������, ������� ������������ ��� ���������������� ��������:

altq on
���������� ���������, �� ������� ����� ������������ ������� � ������� �������� �������.
queue
���������� �������� �������� ��������.

��������� ��������� altq:

altq on interface scheduler bandwidth bw qlimit qlim \
   tbrsize size queue { queue_list }
            
interface
������� ��������� �� ������� ������������ �������
scheduler
����� ����������� ����� �����������. ��������� �������� cbqpriq. �� ���������� � ���� ������ ������� ����� ���������� ������ ���� �����������.
bw
����� ���������� �����������, ��������� ������������. ����� ��������� ������������ b, Kb, Mb, Gb ��� ����������� bits, kilobits, megabits, � gigabits � �������, ���������� �������� ��� ������� �� ����� ���������� �����������.
qlim
������������ ����� ������� � �������. �������������� ��������. �� ����������— 50
size
������ token bucket regulator � ������. ���� �� ���������, �� ��������������� �� ������ ������ ������ �����������.
queue_list
������ �������� ��������, ����������� �� ��� ������������ �������.

�������� ����� ����� �������� ���� ��������, � �� ����� ��������� � ������������ ������������ �� ��������� �������:

��� ����������� ������ ����������� ������ ��������� ��������� �������: ���� ��������� ������� (bucket) � ������� ���������, ������ ��� � �������, ������ ����� (token). ����� ������ ������ ������� ������ ����� ����� �� ������� � ���������. ���� ������ � ������ ���, ����� �������������, ���� ������ ����� ������� �� ����, ������ ������� � �������, ���� ��� �� ������������.

����� �������, ���� ������� ����� �������, � ��� ����� ����� � ������� ����� ����������� ������ ��������. ���� ������� ��������њ— ������ ����� ����������, �� �������� ���������� � �������� ����� �������� � ������� �������.

��� ���� �������� � ����, ��-��������, token bucket regulator.

����:

altq on fxp0 cbq bandwidth 2Mb queue { std, ssh, ftp }
            

��� ������� ��������� CBQ �� ���������� fxp0, ���������� ����������� ������ 2�Mb � ��������� ��� �������� �������: std, ssh � ftp.

��������� ��������� queue:

queue name [on interface] bandwidth bw [priority pri] [qlimit qlim] \
   scheduler ( sched_options ) { queue_list }
            
name
��� �������. ��� ������ ������ ���� ��������� ������̣���� � ��������� altq ������ queue_list. ��� cbq ��� ����� ����� ���� ������ ����� ������� � ���������� ��������� queue ��������� queue_list. ��� �� ������ ���� ������� 15 ��������.
interface
������� ���������, �� ������� �������� �������. ���� ��������� �� ������̣�, ������� ����� �������� �� ���� �����������.
bw
����� ���������� �����������, ��������� ������������. ����� ��������� ������������ b, Kb, Mb, Gb ��� ����������� bits, kilobits, megabits, � gigabits � �������, ���������� �������� ��� ������� �� ����� ���������� �����������. ����������� ������ ��� ������������� ������������ cbq.
pri
��������� �������. ��� cbq ��������� ���������� �� 0 �� 7, ��� priq �������� �� 0 �� 15. ��������� 0 ��������� ����� ������. ���� ���� �������� �� ������̣�, ��� ����������� 1.
qlim
������������ ����� ������� � �������. �������������� ��������. �� ��������� - 50.
scheduler
������������ ����������˚— cbq, priq ��� hfsc. ������ ���� ����� ��, ��� � ������������ �������.
sched_options

�������������� ����� ��� ���������� ��������������:

default
������� �� ��������� (����� ���� ������ ����). ���� ����� ���������� ��� ������, �� ���������� ��� ��������� ��������.
red
�������� RED ��� �������.
rio
�������� REDIN/OUT. � ���� ������ RED ������������ ������� ��������� ����� � ��������� ��������� ��������, �� ������ �� ������ ������� IP Quality of Service.
ecn
�������� ECN (�������� ��������� � RED).
borrow
��� ������� ����� ������������ ���������� ����������� � ������ ��������. ����� ���� ���������� ������ ��� ������������� cbq.
queue_list
������ �������� ��������. ����� ���� ���������� ������ ��� ������������� cbq.

��������� ��� ����� ����������� ������ ��� ������� ���� HFSC.

realtime <sc>
����������� ������ �����������
upperlimit <sc>
������������ ������ �����������
linkshare <sc>
������, ������� ����� ������ � ������� ���������

����� <sc> ��� ���������� ��� service curve�— ������ �������. ������ ������� �� ���� �������� �������� � ����������� ����� ������� (m1, d, m2). m1�— ��������� ������ ����������� (�.�. ������ ������ ������), d ����� � ������� �������� ��������� ��������� ������ ����������� � ������������� � m2�— ������ ������� ��������� ��������— �.�. �������� ������ �����������.

����� ��������� �������� ������ ������� ��������� �������� ������������ �������� ��� ������ ������� � ������ �����������, ����� ��� � CBQ ���� ������ ����������� ������ ����������� �, �������������, ������������ ������ ������� �������� ������� � ���������� ������ �����������.

����������� �������:

queue std bandwidth 50% cbq(default)
queue ssh { ssh_login, ssh_bulk }
   queue ssh_login priority 4 cbq(ecn)
   queue ssh_bulk cbq(ecn)
queue ftp bandwidth 500Kb priority 3 cbq(borrow red)
            

����� ������������ �������� �������. ������� std ����������� 50% ���������� ����������� �� ����������� ������� � ��� ����������� ���������. ������� ssh ���������� ��� �������� �������, ssh_login � ssh_bulk. Ssh_login ���� ����� ������� ��������� ��� ssh_bulk, � ��� �������� � ECN. Ftp ��������� ������ ����������� � 500�kbps � ��� ��������� 3. ��� ������� ����� ���������� ��������� ���������� ����������� ������ �������� � ������������ red.

C.2.2.4.3.1. ���������� ������� �������

��� ����������� ������� � ������� ������������ �������� ����� queue � �������� ��������� �������. ��� ������� ���������� ��������� ������:

pass out on fxp0 from any to any port 22
              

������ �� ����� ������� ����� ��������� � ������� ��������� ��������:

pass out on fxp0 from any to any port 22 queue ssh
              

���� �������� ����� queue ������������ ��������� � block, ��� ������ TCP RST ��� ICMP Unreachable �������� � ��������� �������.

�������� ��������, ��� queue ����� ������������ ��� ������� ����������, ��� ���� ���������� ���������� altq:

altq on fxp0 cbq bandwidth 2Mb queue { std, ftp }
queue std cbq(default)
queue ftp bandwidth 1.5Mb

pass in on dc0 from any to any port 21 queue ftp
              

������� ������������ �� fxp0, �� �������� �� �ţ ����������� �� dc0. ���� �����, ��������������� ������� ������� � ���������� fxp0, �� �� ����� ��������� � ������� ftp. ���� ��� �������� ����� ���� ����� ������� �� ���������������.

������ � �������� ������ queue ������������ ������ ���� ��� �������, �� ���� ���������� � ������ ���, �� ������� ����� �������������� ��� ������� � Type of Service (ToS) ������ �������� � ��� ������� TCP ACK ��� ��������� ����� ������. ������� ������ ����� ���� ������ ��� ������������� ssh: �� ����� �������� ������ ToS ��������������� � low-delay ���� �� ��������� ������ SCP ��� SFTP. PF ����� ������������ ���������� � ����������� � ������� ������� ��� ����. ����� �������� ������ �� ���� ������ �� ��������� �������. �������� ����� �������� �������� �� ����������� ������ ����������� �� ������� ������:

pass out on fxp0 from any to any port 22 queue(ssh_bulk, ssh_login)
              

��������� ���������� ������� TCP ACK ����� ����� �� ����������� �����������, ����� ��� ADSL, ��� �������� ��������� � ���������� ������ �� ����� ����� �����. �� ADSL ����� ��� ��������� ������� ��������� ������ ����� ��������� � �������� ������������� ��������� ������, ��� ��� ������ TCP ACK ����� �������� � �������������. ������������ ��������, ��� ��� ���������� ���������� �������������, ������ ����������� ������ ���� ������� ������, ������������ ������. ��������, ���� ADSL ����� ���� ������������ �������� � 640�kbps, ���������� �������� ���������� ����������� ��� �������� ����� � 600�kb. ����������� �������� ��������� ����� ���� � ������.

����� �������� ����� queue ������������ � ��������� keep state, �������� ������ ����� ������ ������ ������� � ������� ��������� ����� �������, ��� ������ � fxp0 ��������������� ��������������� ���������� ����� ����������� � ������� ssh:

pass in on fxp0 proto tcp from any to any port 22 flags S/SA \
   keep state queue ssh
              

�������� ��������, ��� �������� ����� queue ����������� � ��������, ������������� �������� ������.

C.2.2.4.4. ������ 1: ��������� �������� ����
    [ Alice ]    [ Charlie ]
        |             |                              ADSL
     ---+-----+-------+------ dc0 [ OpenBSD ] fxp0 -------- ( Internet )
              |
           [ Bob ]
            

� ���� ������� OpenBSD ������������ ��� ���� � �������� ��� ��������� �������� ���� � ����� �������� ���������. �� ����� �������� NAT � ���������� �������. ����� � �������� �������������� �� ADSL � �������� ��������� 2Mbps � ��������� 640Kbps.

��� �������� ��������� ��������� �������:

  • �������� 80Kbps ��� ��� ����, ����� �� ������, ����� ����� � ����� ������ ������ � ������. ����� ���� ��������� �������— ����� ��ң�.
  • SSH ������ � ������ ��������-��������� ����� ������ ���������.
  • DNS �������-������ ����� ��������� ���� ����.
  • ��������� TCP ACK ����� ������ ��������� �� ��������� �� ���� ��������� ��������� ��������.

���� ������������ �������, ����������� ��� ��������. �������� ��������, ��� � pf.conf �� ������������ ������� nat, rdr, options, � �.�. ��������������� �� ������� ��������� � ������ ������.

# �������� ������� �� ������� ���������� ��� �������� �� ��������
# ��������� � ��������. ���������� ����������� priq ��� �������� ������
# �� �����������. ������������� ������ ����������� 610 kbps ���
# ������������ ����������� ������� TCP ACK

altq on fxp0 priq bandwidth 610Kb queue { std_out, ssh_im_out, dns_out, \
    tcp_ack_out }

# ���������� ��������� �������� ��������
# std_out      - ����������� �������. ����� ������� ����, � �������
#                ������� �� ������� ����, ��������� ������ � ����
#                �������.
# ssh_im_out   - ������������� SSH � �������� ��������
# dns_out      - ������� DNS
# tcp_ack_out  - ������ TCP ACK �� ������� �������� ��������

queue std_out     priq(default)
queue ssh_im_out  priority 4 priq(red)
queue dns_out     priority 5
queue tcp_ack_out priority 6

# �������� ������� �� ���������� ���������� ��� �������� �������
# ���������� �� ��������. ���������� ����������� cbq ��� �������� ������
# �����������. ������������ ������ 2 Mbps.

altq on dc0 cbq bandwidth 2Mb queue { std_in, ssh_im_in, dns_in, bob_in }

# ���������� ��������� �������� ��������
# std_in       - ����������� �������. ����� ������� ����, � �������
#                ������� �� ������� ����, ��������� ������ � ����
#                �������.
# ssh_im_in    - ������������� SSH � �������� ��������
# dns_in       - ������ DNS
# bob_in       - ������ ����������������� ��� ����, ��������� ���
#                ����������� ������ �� ���� ����������� (borrow)

queue std_in    bandwidth 1.6Mb cbq(default)
queue ssh_im_in bandwidth 200Kb priority 4
queue dns_in    bandwidth 120Kb priority 5
queue bob_in    bandwidth 80Kb cbq(borrow)


# ... ������ ���������� ...

alice         = "192.168.0.2"
bob           = "192.168.0.3"
charlie       = "192.168.0.4"
local_net     = "192.168.0.0/24"
ssh_ports     = "{ 22 2022 }"
im_ports      = "{ 1863 5190 5222 }"

# ������� ���������� ��������� ������� �� fxp0
block in on fxp0 all

# ������� ���������� ���������� ������� �� fxp0
block out on fxp0 all
pass  out on fxp0 inet proto tcp from (fxp0) to any flags S/SA \
    keep state queue(std_out, tcp_ack_out)
pass  out on fxp0 inet proto { udp icmp } from (fxp0) to any keep state
pass  out on fxp0 inet proto { tcp udp } from (fxp0) to any port domain \
    keep state queue dns_out
pass  out on fxp0 inet proto tcp from (fxp0) to any port $ssh_ports \
    flags S/SA keep state queue(std_out, ssh_im_out)
pass  out on fxp0 inet proto tcp from (fxp0) to any port $im_ports \
    flags S/SA keep state queue(ssh_im_out, tcp_ack_out)

# ������� ���������� ��������� ������� �� dc0
block in on dc0 all
pass  in on dc0 from $local_net

# ������� ���������� ���������� ������� �� dc0
block out on dc0 all
pass  out on dc0 from any to $local_net
pass  out on dc0 proto { tcp udp } from any port domain to $local_net \
    queue dns_in
pass  out on dc0 proto tcp from any port $ssh_ports to $local_net \
    queue(std_in, ssh_im_in)
pass  out on dc0 proto tcp from any port $im_ports to $local_net \
    queue ssh_im_in
pass  out on dc0 from any to $bob queue bob_in
            
C.2.2.4.5. ������ 2: ������������� ����
  ( IT Dept )  [ Boss's PC ]
       |          |                                   T1
     --+----+-----+---------- dc0 [ OpenBSD ] fxp0 -------- ( Internet )
            |                         fxp1
         [ COMP1 ]    [ WWW ]         /
                         |           /
                       --+----------'
            

� ���� ������� OpenBSD ��������� � ���� ������� ������� ������ ��� ������������� ����. � �������� �������� WWW ������, ������������� � DMZ. ������� ��������� ���� ����� ����� FTP. � IT ����� ������� ����������� �������, ��������� � �������, ���� ���������� ���� ��������� ��� ����� � �������� �� ����. ���������� � ���������� �������������� �� �������� T1 (1.5�Mbps) � ��� �������. ��� ������ ������� �������� ���������� Fast Ethernet (100�Mbps).

������� ������������� ������ ��������� ��������:

  • ������ ����� WWW �������� � ���������� �������������� 500�kbps:

    • �������� 250�kbps �� HTTP ������
    • �������� 250�kbps �� ��-HTTP ������
    • ����� �������� ��������� ����� �� ������ ������ � 500�kbps
    • HTTP ������� ����� WWW �������� � �������� ���� ������� ���������, ��� ��-HTTP (� ������� ftp-�������).
  • ������ ����� ���������� ����� � WWW �������� ����� ������������ ��� ������ 100�Mbps, ������� ��������� ����.
  • 500�kbps ������������� ��� IT ��� ����, ����� ������ ��������� ������ ������������ �����������. IT ����� ������� ������� ������, ���� ���� ����� �����������.
  • ������ ����� ����������� � ���������� ����� ������ ��������� �� ��������� �� ����.

���� ������������ �������, ����������� ��� ��������. �������� ��������, ��� � pf.conf �� ������������ ������� nat, rdr, options, � �.�. ��������������� �� ������� ��������� � ������ ������.

# �������� ������� �� ������� ���������� ��� ������� ��������� �
# ��������. ���������� ����������� cbq ����� �������������� ������
# ����������� ������ �������. ������������ ��������� ������ 1.5 Mbps

altq on fxp0 cbq bandwidth 1.5Mb queue { std_ext, www_ext, boss_ext }

# ���������� ��������� �������� ��������
# std_ext        - ����������� �������. ��� �� �������� �������� ���
#                  ���������� ������� �� ���������� fxp0
# www_ext        - ��������� ��� �������� WWW �������. ������ 500 kbps
#   www_ext_http - http ������ WWW ������� - ������ ���������
#   www_ext_misc - ��-http ������ WWW �������
# boss_ext       - ������ ��������� � ���������� �����

queue std_ext        bandwidth 500Kb cbq(default borrow)
queue www_ext        bandwidth 500Kb { www_ext_http, www_ext_misc }
  queue www_ext_http bandwidth 50% priority 3 cbq(red borrow)
  queue www_ext_misc bandwidth 50% priority 1 cbq(borrow)
queue boss_ext       bandwidth 500Kb priority 3 cbq(borrow)

# �������� ������� �� ���������� ���������� ��� �������� �������
# ��������� �� ��������� ��� �� DMZ. ���������� ����������� cbq ���
# �������� �� ������ ��������. ������ ����������� ��������������� �
# ��������. ������� �� DMZ ����������� ������������ ��� ������, �
# ������� ���������� �� �������� ���������� ������������ 1.0 Mbps
# (��������� 0.5 Mbps (500 kbps) ��������������� �� fxp1).

altq on dc0 cbq bandwidth 100% queue { net_int, www_int }

# ���������� ��������� �������� ��������
# net_int    - ��������� ��� ������� �� ��������. ������ 1.0 Mbps
#   std_int  - ����������� �������. ��� �� �������� ������� �� ���������
#              ��� ���������� ������� �� dc0
#   it_int   - ������ IT-������. �� ��������������� 500 kbps
#   boss_int - ������ ����� ����� ������ ���������
# www_int    - ������ WWW ������� �� DMZ �� ����� �����������

queue net_int    bandwidth 1.0Mb { std_int, it_int, boss_int }
  queue std_int  bandwidth 250Kb cbq(default borrow)
  queue it_int   bandwidth 500Kb cbq(borrow)
  queue boss_int bandwidth 250Kb priority 3 cbq(borrow)
queue www_int    bandwidth 99Mb cbq(red borrow)

# �������� ������� �� ���������� DMZ ��� �������� ������� ������� � WWW
# �������. ���������� ����������� cbq ��� �������� �� �������
# �����������. ������ ������������ � ��������. ������ �� ���������� ����
# ����� ������������ ��� ������ �����������, � ������ �� ��������
# ��������� 500 kbps.

altq on fxp1 cbq bandwidth 100% queue { internal_dmz, net_dmz }

# ���������� ��������� �������� ��������
# internal_dmz   - ������ �� ���������� ����
# net_dmz        - ��������� ��� �������� ������� ������� �� ��������
#   net_dmz_http - http ������, ��������� ���������
#   net_dmz_misc - ��-http ������. ��� ������� �� ���������

queue internal_dmz   bandwidth 99Mb cbq(borrow)
queue net_dmz        bandwidth 500Kb { net_dmz_http, net_dmz_misc }
  queue net_dmz_http bandwidth 50% priority 3 cbq(red borrow)
  queue net_dmz_misc bandwidth 50% priority 1 cbq(default borrow)


# ... ������ ���������� ...

main_net  = "192.168.0.0/24"
it_net    = "192.168.1.0/24"
int_nets  = "{ 192.168.0.0/24, 192.168.1.0/24 }"
dmz_net   = "10.0.0.0/24"

boss      = "192.168.0.200"
wwwserv   = "10.0.0.100"

# default deny
block on { fxp0, fxp1, dc0 } all

# ������� ���������� ��������� ������� �� ���������� fxp0
pass in on fxp0 proto tcp from any to $wwwserv port { 21, \
    > 49151 } flags S/SA keep state queue www_ext_misc
pass in on fxp0 proto tcp from any to $wwwserv port 80 \
    flags S/SA keep state queue www_ext_http

# ������� ���������� ���������� ������� �� ���������� fxp0
pass out on fxp0 from $int_nets to any keep state
pass out on fxp0 from $boss to any keep state queue boss_ext

# ������� ���������� ��������� ������� �� ���������� dc0
pass in on dc0 from $int_nets to any keep state
pass in on dc0 from $it_net to any queue it_int
pass in on dc0 from $boss to any queue boss_int
pass in on dc0 proto tcp from $int_nets to $wwwserv port { 21, 80, \
    > 49151 } flags S/SA keep state queue www_int

# ������� ���������� ���������� ������� �� ���������� dc0
pass out on dc0 from dc0 to $int_nets

# ������� ���������� ��������� ������� �� ���������� fxp1
pass in on fxp1 proto { tcp, udp } from $wwwserv to any port 53 \
    keep state

# ������� ���������� ���������� ������� �� ���������� fxp1
pass out on fxp1 proto tcp from any to $wwwserv port { 21, \
    > 49151 } flags S/SA keep state queue net_dmz_misc
pass out on fxp1 proto tcp from any to $wwwserv port 80 \
    flags S/SA keep state queue net_dmz_http
pass out on fxp1 proto tcp from $int_nets to $wwwserv port { 80, \
    21, > 49151 } flags S/SA keep state queue internal_dmz
            

C.2.2.5. �������� ����, ������������ ��������

�������� ����� ���������� �������� ������������ ����� ��� �� ���� �������, ������������ ������� �������������. �������� ��� ����� ���� ������ � �������� ���������������, ���������� � ������ ��� ����� ���������� � ������ ���������� route-to, reply-todup-to.

���������� ������ ������� ������������� �������� �����:

bitmask
���������� ������ �� ���� �������� ��������� �������� ������ (����� ��������� ��� ������ nat, ����� ���������� ��� ������ rdr). ������: ���� ��� ������� �������� 192.0.2.1/24 � �������������� ����� 10.0.0.50, �� �������������� ������� ����� 192.0.2.50. ���� ��� ������� �������� 192.0.2.1/25 � �������������� ����� 10.0.0.130, ����������� ����� 192.0.2.2.
random
��������� ����� ������� �� ����
source-hash
������������� ���� ������ ��������� ��� ������������� ������� �� ����. ���� ����� ����������� ������������ ������ ��������� � ������, ������� �� ����. ���� ��� ��������� ����������� ����� ���� ������̣� ������������� ����� ��������� ����� source-hash � ����������������� ������� ��� ��� ������. �� ���������, pfctl(8) ���������� ��������� ���� ��� ������ �������� ������ ������.
round-robin
������������� ������� ���� �� �����. ��� ����� �� ��������� � ������������ �����, ����� ��� ������� ������̣� �� �������.

�� ����������� ������ round-robin, ��� ������� ������ ���� ������̣� ��� ���� ������� CIDR. � ������ round-robin ������������ ���������� ������� �� �������.

����� sticky-address (�������� «������ �����») ����� �������������� � ������ randomround-robin ��� �������� ����������� ������ ������ � ���� �� ������ ��������� � ����� ����.

C.2.2.5.1. �������� ���� NAT

��� ������� ����� ������������ ��� ���������� ������� � �������� nat. ����� ��������� ������������� �� � ��������� �����, � � ����� ������ ��� ������ ������ �� ������������� ���� ������� �� ����. ��� ����� ��������� ����� �������� � ������. ����� �������� ������ ����������� ������ ��� ����� ������� ����. ��� ��� ����� ������������� NAT ���������� �� ���� ������� ����� �����������, ��������� ��� ���� ����� ���� ������� �������� ����������� ��������� ����� �������������.

� ��������� ������� ��� �� ���� ������� ������������ ��� ���������� ��������� �������. ��� ������� ���������� ���������� �������� ������ ���������� ������� ������� ������� round-robin:

nat on $ext_if inet from any to any -> { 192.0.2.5, 192.0.2.10 }
            

������������ ����������� ����� ������ ����� ��, ��� �� ������ ����� ����������� ������������ ����� �������� ������� � ������� ����������. ��� ����� ������� �������� ��� ������ �� web-����: ��� �� ������ ��������� ������������ ���������� � �������. �������� ���� �������� ����� ����� ������������� ������ source-hash ��� �������� ����������� ������ � ������ ����������. � ���� ������ �������� ��� ������ ���� ������̣� ��� ������� ���� CIDR:

nat on $ext_if inet from any to any -> 192.0.2.4/31 source-hash
            

� ���� ������� nat ������������ ��� ������� 192.0.2.4/31 (192.0.2.4�— 192.0.2.5) ��� ������ ���������� ��� ��������� �������. ������ ���������� ����� ����� ������ ��������������� � ���� ������� �����, ��� ��� ������� �������� ����� source-hash.

C.2.2.5.2. ������������ �������� ��������� �������

���� ������� ����� ����� �������������� ��� ������������ �������� �������� �����������. ��� �������, �������� ����������� �� web-������ ����� ���� ������������ ����� ��������� ������:

web_servers = "{ 10.0.0.10, 10.0.0.11, 10.0.0.13 }"

rdr on $ext_if proto tcp from any to any port 80 -> $web_servers \
   round-robin sticky-address
            

��� ���������� ���������� ����� ���������������� �� ������� ����� ��������� ����� round-robin. ��� ���� ������ ������������� ������ ���������� ����� ������������ ������ ������� ("sticky connection"), �� ��������� ���������� �������� ���� �� ������, ����� ���������� ���������� �������.

C.2.2.5.3. ������������ �������� ���������� �������

���� ������� ����� �������������� ��� ������������ �������� ����� ����� � ����� �������� �������� � �������������� ����� route-to � ������ ������������� ������������ ������������ ������������� (��������, � �������������� ��������� BGP4). ���������� ������������� route-to � ���� ������� round-robin ��������� ������������ ��������� ���������� ����� ������� ������������.

� �������� �������������� ���������� ���������� ������� ������ ��������������� ��� ������� ��������-����������. ��� ����� ��� ����� route-to, ���� ��������� ���������� ��������.

��������� ������ ������������ ������������ �������� ����� ����� ��������:

lan_net = "192.168.0.0/24"
int_if  = "dc0"
ext_if1 = "fxp0"
ext_if2 = "fxp1"
ext_gw1 = "68.146.224.1"
ext_gw2 = "142.59.76.1"

pass in on $int_if route-to \
   { ($ext_if1 $ext_gw1), ($ext_if2 $ext_gw2) } round-robin \
   from $lan_net to any keep state 
            

����� route-to ������������ ��� ��ɣ�� ������� �� ���������� ���������� � ���������� ��� �������� �������� ���������� � �����, ����� ������� ����������� ������������. �������� ��������, ��� ����� route-to ������ ���� ������� � ������ �������, ��������������� ��� ������������ �������. �������� ������ �������� �� ��� ���������, � �������� �ۣ� ������ � ��� ����� �������������� �� ������ ��� ������.

��� �������� ����, ��� ������ � $ext_if1 ������ ������������ � $ext_gw1 (� �������������� ��� $ext_if2 � $ext_gw2), � �������� ����� ������� ���������:

pass out on $ext_if1 route-to ($ext_if2 $ext_gw2) from $ext_if2 to any
pass out on $ext_if2 route-to ($ext_if1 $ext_gw1) from $ext_if1 to any
            

NAT ����� ������������ �� ������ ������� ����������:

nat on $ext_if1 from $lan_net to any -> ($ext_if1)
nat on $ext_if2 from $lan_net to any -> ($ext_if2)
            

���� ��� ������ ������ ������ ��� ������������ �������� �������:

lan_net = "192.168.0.0/24"
int_if  = "dc0"
ext_if1 = "fxp0"
ext_if2 = "fxp1"
ext_gw1 = "68.146.224.1"
ext_gw2 = "142.59.76.1"

#  ������� nat ��� ��������� ���������� �� ������ ������� ����������
nat on $ext_if1 from $lan_net to any -> ($ext_if1)
nat on $ext_if2 from $lan_net to any -> ($ext_if2)

#  default deny
block in  from any to any
block out from any to any

#  ���������� ��� ��������� ������ �� ���������� ���������
pass out on $int_if from any to $lan_net
#  ���������� (quick) ������ ��������������� ������ �����
pass in quick on $int_if from $lan_net to $int_if
#  ������������ ���������� tcp ������� ������� �� ���������� ����
pass in on $int_if route-to \
    { ($ext_if1 $ext_gw1), ($ext_if2 $ext_gw2) } round-robin \
    proto tcp from $lan_net to any flags S/SA modulate state
#  ������������ ���������� icmp � udp ������� ������� �� ���������� ����
pass in on $int_if route-to \
    { ($ext_if1 $ext_gw1), ($ext_if2 $ext_gw2) } round-robin \
    proto { udp, icmp } from $lan_net to any keep state

#  �������� "�����������" ������� �� ������� ����������
pass out on $ext_if1 proto tcp from any to any flags S/SA modulate state
pass out on $ext_if1 proto { udp, icmp } from any to any keep state
pass out on $ext_if2 proto tcp from any to any flags S/SA modulate state
pass out on $ext_if2 proto { udp, icmp } from any to any keep state

#  ������������� ������� ������ � ������ IP �� $ext_if1 ����� $ext_gw1 �
#  ������� ������  �� $ext_if2 ����� $ext_gw2
pass out on $ext_if1 route-to ($ext_if2 $ext_gw2) from $ext_if2 to any 
pass out on $ext_if2 route-to ($ext_if1 $ext_gw1) from $ext_if1 to any 
            

C.2.2.6. ������������ �������, ���������� �� ������ �������

������������ ������ך— ������ �������� ����� ���������� ��������������� ��� ����������� ������������� � �������� �������� � �������� ���������� � ����������. ������������ ��������� ������� «�������» ����� ������������, � ��� �� �������� ��������� ��� �� ����� ��������� ��������� ����������. ����� ���������� ��������� ������� �� ����������, ���������� �� ��������, � ����������, ���������� �� ���������.

C.2.2.6.1. ������������ ������� �������

��� ���������� ������� ������������ �������� ����� tag:

pass in on $int_if all tag INTERNAL_NET keep state
            

������ INTERNAL_NET ����� �������� ������ ������ ���������������� �������.

������ ����� ���� �������� � �������������� ��������, ��������:

name = "INTERNAL_NET"
pass in on $int_if all tag $name keep state
            

���������� ����� ����������̣���� ��������, ������� ����� ������������ ��� ���� �����:

$if
���������
$srcaddr
IP ����� ���������
$dstaddr
IP ����� ����������
$srcport
���� ���������
$dstport
���� ����������
$proto
��������
$nr
����� �������

��� ������� ������������ �� ����� ��������, � �� �� ����� ������.

������������ ����������� ��������� ��������:

  • ������ «�������������». ������� ������������ � ������, ������ �� ����� ���� ���̣�, ������ ��� ����� �������� ������ ��������.
  • ��������� ������� «�������» ����� ����� ����� ������ ���� ���� ��������� ������� �� �������� �������� ����� tag.
  • ������ ������ ����� ��������� ������ ���� ������.
  • ������� ��� ���������� ��������������, ��� �� ���������� �� ����.
  • ����� ������� ������ ���������� 15 ��������, ������� � OpenBSD 4.0 �� 63 ��������.

���������� ��������� ������:

pass in on $int_if tag INT_NET keep state 1
pass in quick on $int_if proto tcp to port 80 tag INT_NET_HTTP keep state 2
pass in quick on $int_if from 192.168.1.5 keep state 3
            
1 ������ �������� ����� ��������� $int_if ����� �������� �������� INT_NET
2 ������ ��������� ����� ��������� $int_if, �������������� �� ���� 80, ���� �������� ��� INT_NET, �� ����� ������ ������ �� INT_NET_HTTP
3 ����� ������ �� ����� 192.168.1.5 ����� ������� ���� �������� INT_NET_HTTP (���� �� �ģ� �� ���� 80), ���� INT_NET. ���� � �������� ������� ��������� ����� tag ���. ��� � ���� «���������» �������.

� �������� nat, rdr � binat ���� ����� ������ ������ ��� ������ ��������� ����� tag.

C.2.2.6.2. �������� ��������

��� �������� ������������� �������� ������������ �������� ����� tagged:

pass out on $ext_if tagged INT_NET keep state
            

��� ������� ������������� ��������� ������� �� ���������� $ext_if ���������� �������� INT_NET. ��������������� ���� ������������ ��� �������������� �������:

pass out on $ext_if ! tagged WIFI_NET keep state
            

� �������� nat, rdr � binat ��� �� ����������� ������������� ��������� ����� tagged.

C.2.2.6.3. ���������� �� ������ �������

���������� ������� �� ������ ������� ��������� ���������� �� ���������� �� ������ ������. � ��������� ��������������� �������, �� ������� ��������� ��� ������� ������ ���� ��������, � ��������� �����ݣ�. ������ ���������������� ������ ������� �� ������ ������������ ��������ך— IP ������ ���������/����������, ��������� � �.�. ���������� ��������� ������:

  • ������ �� ���������� ���� LAN � �������� ������������ (LAN_INET) � ������ ���� ������������ (LAN_INET_NAT)
  • ����������� ������ �� ���������� ���� LAN � DMZ (LAN_DMZ)
  • ����������� ������ �� ��������� � DMZ (INET_DMZ)
  • ����������� ������, ������� ������ ���� ��ף���� ������ spamd(8) (SPAMD)
  • ���� ��������� ������ �����������.

��������, ��� �������� ���������� ���� ������ ������ ����� ����������. � ������� ������� ������� ������� ������������ ��� ������ ��������.

������� ���������� � ����������:

rdr on $ext_if proto tcp from <spamd> to port smtp \
   tag SPAMD -> 127.0.0.1 port 8025
nat on $ext_if tag LAN_INET_NAT tagged LAN_INET -> ($ext_if)

block all
pass in on $int_if from $int_net tag LAN_INET keep state
pass in on $int_if from $int_net to $dmz_net tag LAN_DMZ keep state
pass in on $ext_if proto tcp to $www_server port 80 tag INET_DMZ keep state
            

����� �������, �� ���������� ����� ������ ������������� ����� ��������. ������ �������� ������ ������� �������������� ��������� SPAMD, LAN_INET_NAT, LAN_DMZ � INET_DMZ:

pass in  quick on $ext_if tagged SPAMD keep state
pass out quick on $ext_if tagged LAN_INET_NAT keep state
pass out quick on $dmz_if tagged LAN_DMZ keep state
pass out quick on $dmz_if tagged INET_DMZ keep state
            

������ ��� �������� ����������. ���� �� ������� �������� POP3/SMTP ������ � DMZ, ��� ���� ����� �������� ��������� ������ � pf.conf(5):

mail_server = "192.168.0.10"
...
pass in on $ext_if proto tcp to $mail_server port { smtp, pop3 } \
   tag INET_DMZ keep state
            

����� �������, ������ ����������� ����� ����� ��������������� �������� INET_DMZ � ����� ��������.

������ ����� ������:

# macros
int_if  = "dc0"
dmz_if  = "dc1"
ext_if  = "ep0"
int_net = "10.0.0.0/24"
dmz_net = "192.168.0.0/24"
www_server = "192.168.0.5"
mail_server = "192.168.0.10"

table <spamd> persist file "/etc/spammers"

# ������������� ������� ���������� �� ������̣���� � �����������
# ���������
rdr on $ext_if proto tcp from <spamd> to port smtp \
    tag SPAMD -> 127.0.0.1 port 8025
nat on $ext_if tag LAN_INET_NAT tagged LAN_INET -> ($ext_if)

block all
pass in on $int_if from $int_net tag LAN_INET keep state
pass in on $int_if from $int_net to $dmz_net tag LAN_DMZ keep state
pass in on $ext_if proto tcp to $www_server port 80 tag INET_DMZ keep state 
pass in on $ext_if proto tcp to $mail_server port { smtp, pop3 } \
    tag INET_DMZ keep state 

# ���������� ������� -- ���������� �� ������ ������̣���� � �����������
# ���������
pass in  quick on $ext_if tagged SPAMD keep state
pass out quick on $ext_if tagged LAN_INET_NAT keep state
pass out quick on $dmz_if tagged LAN_DMZ keep state
pass out quick on $dmz_if tagged INET_DMZ keep state
            
C.2.2.6.4. ������������ ������ ethernet (��������� ������� OSI)

���� ������ �������� ��� ���� �� ��������� ������ (� OpenBSD ��. bridge(4)FreeBSD if_bridge(4)) �������� ������ ����� ����������� ����� ethernet. ��� �������� ������ ���������� ��� ������ ������� brconfig(8) (���������� ��� OpenBSD) ����� ���������� ������ � ������� ����� tag:

# brconfig bridge0 rule pass in on fxp0 src 0:de:ad:be:ef:0 tag USER1
            

����� ����� ��������� �� ���� ������ � pf.conf(5):

pass in on fxp0 tagged USER1
            

C.2.3. �������������� �������

C.2.3.1. �������������� � �������� �������

�������������� � �������� ������� �������������� ��� ������ ������ pflogd(8) ���������� ������� ��������� pflog0 � ������������� ������ � ���������� ���� /var/log/pflog � �������� ������� libpcap, ������� ����� ������������� ��� ������ ��������� tcpdump(1) ��� wireshark(1), ��� �� ethereal(1) (��. �����̚6.11, «������������ �������� ������� ������ � �������� tcpdump(1)»). � ��������� tcpdump(1) ���� ����������� ������� ��� ������ � �������� ��������. ����� ����, ��������� tcpdump(1) ��������� ������������� ������ «�� ����» ���� ��������� ţ �� ������������� ���������� pflog0. ��� ��������� � ������, ����� ��������� �������� ����� log (��� log (all)) � �������� ����������.

���������� �����������:

� 1999 ���� ���� ������ ������� ������� ����������. ����������� ��������� ���� � ��������������� ����� � ��� ������� �������. ����� �������� � ������� �� ���� «�������� ������»�— � Σ� ���� �������� ��������� ������, ��� �� ���������� ������ ������������ �����������, � �������� ����������� ң���. � ��� ������ �� ���� �� ������ (������ ��-�� �������...). ��� ������ ������ �����, ���� �� ��� ���ģ� � ��������.

������ ����������� ������ � ������ ��������� � ���, ��� ����� ��� ���ۣ� ��������� �����. ����� ������� ���: ���, ����� �������� ���-�� � ���-��.

�������� ������ ���ģ� � ������ ���� ������.

C.2.3.1.1. ��������� ������� � ������

��� �������������� ������ ���� ��������� �������� ����� log � ������� ����������, nat ��� rdr. ��������, ��� � ������� ������� ������ ������� ������� ������ ��� �������������� �������— ������ �������������� ���� ��������� block ���� pass.

��������� ����� log ����� �������� ��������� �����:

all
�������� � ������ �� ������ ��������� ������, �� ������ ��� ������ ����������. ����� ����������� � �������� keep state.
user
�������� � ������ UID � GID ������, �������� ��������� �����.
to <interface>
������� � OpenBSD�4.1 ����� ��������� ��������� ����������� ��� �������������� � ��������� �� ������ ������ �������� �� ������ ����������. �� � ����� ������ ������� ��� ����������� ���� �� �����������.

����� ����������� � ������� ������� ����� ��������� ����� log. ��������� ����� ����� ������� ����� ������� ��� ����� ������:

pass in log (all) on $ext_if inet proto tcp to $ext_if port 22 keep state
            

��� ������� �������� � ������ ��� �������� ������, ������ �� 22-� ����.

C.2.3.1.2. ������ �������

���������� ���� ���������� pflogd(8) ����� �������� ������, ��� ������ ������ ��� ������ ���������� ��������. �� ������������ ��� ������ �������� tcpdump(1) (��� ������ ���������� ���������������� � ���������� ���������� libpcap, �������� wireshark(1)).

��� ��������� ����������� ����� ��������� �������

# tcpdump -n -e -ttt -r /var/log/pflog
            

��� ��������� ������� � ������ ��������� �������:

# tcpdump -n -e -ttt -i pflog0
            
[��������]��������

��� ������ ������� � ����������� ������ verbose (������������ ������ -v) ������ ���������: �������� ������������ tcpdump(1) �� ����� ����������� ������� � ����� ������ ������������. ������������, ��� ������ ������� � ������ ��������� �������, �������� ��� ������� ����� ���������� � ��������� � ������ �������. ������������� �������� ������� � ���, ����� ������� ���������� ����� ���������� �� �� ������ ������.

����� ����, ������ � ����, ��� pflogd(8) �� ��������� �������� � ������ ������ 96����� ������. � ���� ������ ����� ���������� ����������� ������, ����� ��� ������ telnet(1) ��� ftp(1).

C.2.3.1.3. ���������� ���������� ������

��������� pflogd(8) ��������� ������ � ������� tcpdump(1), ��� ��������� ������ ������� ����� ������������ ������� ���������� tcpdump(1). ��������, ��� ��������� ������ ���������� ���������� ����������� ����� ����� ��������� �������:

# tcpdump -n -e -ttt -r /var/log/pflog port 80
            

���� ������ ����� ������ ��������, ����� ���������� ���������� ��������� ���������� ������:

# tcpdump -n -e -ttt -r /var/log/pflog port 80 and host 192.168.1.3
            

�� �� ���� ����� �������������� ��� ������ ������ �� ��������� pflog0:

# tcpdump -n -e -ttt -i pflog0 host 192.168.4.2
            

������� ���������� � tcpdump(1) ���������� ��������� ��� �������������� � pflogd(8). � ������ ������ ��������� ������ tcpdump(1) �������� ���������� � �����̚6.11, «������������ �������� ������� ������ � �������� tcpdump(1)», � ��� �� ������� ��������������� �������������� ������� tcpdump(1) ��� ������ � �������� pflogd(8).

�ݣ ���� ������:

# tcpdump -n -e -ttt -i pflog0 inbound and action block and on wi0
            

� ���� ������� �� � ������ ��������� ������� ������ �� ��������� �������� �������������� �� ���������� wi0.

C.2.3.1.4. �������������� ��� ������ syslogd(8)

�� ������ ������� ���������� ����� ������ ����������� � ��������� ������� � ���������� ������ ������� �� ������� ���������� ������.

���, �������� ������������� ������ ��� ����� ������������ �� ��������� ������� ��� �� ����������. �ӣ ��� ��� ����������, ��� ��� � 5 ����� ���������� �������� ���� ����� pipe:

# tcpdump -n -e -ttt -r /var/log/pflog | logger -t pf -p local0.info
            

��������� HOWTO ��� ����������� ������ ������� ����� logger(1) ������ syslogd(8) ����� ����� �� ����� ������������� �������� �������. � �� �������� ������������� ��� �������� � ������ �����, ��� ��� ������ ţ �������.

C.2.3.2. ������������������

��������� ������� ������ ����������� ����� ����������� �������� ������? ��������� ������ ��������� ��� ����� ��� ������������ ���������� � ��������?

�������� ������ �� ��� ������� ���. ��� ��������� ����� ����� ���������� ���������� 486/66 � ����� ������� ������� ���� ISA, ��� ���� ����� ����������� ���������� NAT � �������������� ������ �� 5�Mbps. ��� ������ ����� ����� �� ����� ������� ���� ����� ������� ������ � ����� ������� �������� ������������. ��������� ������� �� ���������� ���� � �������, � ���������� ������� � �������.

������������������ ��������� ������� ������������ ����������� ����������:

  • ���������� ������� � �������. �������� �� �������������� �������� ���������� �� ������� �� ������� �������� �������� � ������. ���������� ������� � ������� ���������� ���������� �������� � ������ ��������� � ���������� ������ ���������� ������������� ������ �������.
  • ������������������ ����� ��������� ����. ������������ ������ ����������� ���� ISA 8�Mpbs. ���� �� �������� ����� �������, ������� ����� ������ ������ ��������� �� ������ �������� ��������. ���� PCI �������� ����������� ������� ���������� ������������.
  • ������������������ ����� ������� �����. ������ ������� ������� ���� �������� ������ �������������������. �������� Realtek�8139 (rl0) �������� ����������� ������� ������������������� ��� Intel�21143 (dc(4)). ��� ������������ ������������������ �� ������ ������������ ���������� �����, ���� ���� �� ������������� �� � 100-���������� ���ɚ— � ���������� ���� ����� ����������� �����.
  • ��������� � ���������� ������ ����������. ��� ������� ����� ������, ��� ��������� ������ �������. ��� ������ ������� ����������� ����� ������� keep statequick ��� ����� ������������������. ��� ������ ������ ����� ������� ����ģ� �����, ��� ���� ������������������.
  • ������ � ������������������ CPU � RAM. ��������� �������� ������ �������� �� ������ ����, �� �� ���������� swap. ���� ��� ������� ������, �� ��������, ���� ���, �������� «������». �������� ���������� ������ �� ����: 32�Mb ���������� ��� �������� ���������� � 30000 ���������� � ������� ���������. ����� ���������� ��� ���������� �����. ������ ������������ �� «��������������� �� �����» ����������� ��������� ������ �� 300�Mb. ��� ��� ������ ����� ������� ����� � ������� ����� ������ (��. ����).

����� ���� ���������� ��� benchmark ��� ��������� �������. Benchmark ��� ����� ������� � ����� ���������� ������ ������� ������ ��.

�������� ������ ���������� �� ��������� ����� ������� �������� � ����� ������� ��������. �����������ɚ— ���� ������������. ��� �� ������ ��� ��� �������.

��������� ������� ������������������ ��������� ������� �������� � ������ ������� ���������� [url://Hartmeier-2006-en], [url://Hartmeier-2006-ru].

C.2.3.3. FTP

C.2.3.3.1. ������ FTP

FTP ��� ��������, ������� ����������, ����� �������� ��� ��������� � ��� � � ���� ����� �����. ����� � ���������� ������� � �� ���� �� ����, ������� FTP �������������� ��� ������� �� ����������� � ���������� NAT.

���������� ��� ������ ���������������� FTP: ��������� � ��������. ����� ����� ����, ��� ����� ����� ���, � ���� ����� �������� � ����������� �������. ���� �� ������, ����� ���� ������������ ���� ���������, ��� ����� �������������� � ����� �������.

�������� FTP.� ����� ������ �������� ������� ������� � �������� ������, ������ «��ģ� ���� �������»�— ��������� ���������� � �������. ������ �������� ��������� ������� ���� � �������� ��� �������, ��������� ��������� ���������� �� ��������� ���� ������� ��� �������� ������. ����� ��������� ���������� ������ NAT: FTP ������ �������� ������� ���������� � �������, �� ������� �������� NAT, � �� ������ �� �����, ��� ������ � ����� ������������.

��������� FTP.� ��� �������� ������ ������ �������� ��������� ������� ���� � �������� ��� �������. ������ ��������� ���������� �� ��������� ������� ���� �������, � �� ����� ���������� ���������� ������. ����� �������� �� ������ �������� � �� ������ ����������, ��� ��� ���������� ����� ����������� ������ ������ �� ��� ��������� �����. ���� � NAT � ���������� �������, �������� ��� ������� �������, ��� ��� ��� ���������� ���� �� ������� � �������.

��� ������������ ����� ��������� ��������� ftp(1). � ���� �������� BSD ��� ��������� �� ��������� �������� � ��������� ������. � �������� ����� ţ ����� ��������� � �������������� ��������� -A ��� ��� �� ����� ������ ��� ������ ������� passive off �������� � ����� �� ����������� ftp> (� ��������� � ��������� ����� �������� passive on).

C.2.3.3.2. FTP ������ �� ������������

��� ������� ���� �������� FTP ����� ��������������� � ������������� � NAT.

��� ������� ���� �������� �������� ������ ���������� ��������������� ������ �������� FTP. ���� ������� ���������� FTP ������ �������� � ������ ������� � �������� ������ ��� ������ ������� ������. ����� ftp-proxy(8) ������������ �������� �������� � OpenBSD�3.9. � ������ ������� ����������� ������ ����� � ��� �� ���������.

����� ������������ ���, ��������� ��������� ������ � ������ NAT ����� /etc/pf.conf(5):

nat-anchor "ftp-proxy/*"
rdr-anchor "ftp-proxy/*"
rdr on $int_if proto tcp from any to any port 21 -> 127.0.0.1 port 8021
            

������ ��� ������� ������� ���� ������, ������� ����� �������������� ������� ftp-proxy(8) ��� ���������� � �������� ������, �.�. ��� ���������� �������� FTP.

��������� ������ �������������� ������ FTP �� �������� ��������� ftp-poxy(8), ������� ����� ������� ���� 8021.

��� ��� �� ����������� ����� � ������� ����������:

anchor "ftp-proxy/*"
            

��� ��� �� ����������� ������� ���, ����� ����� ftp-proxy(8) ��������� ��� ������� �������. ��� ����� � OpenBSD ���� � ���� /etc/rc.conf.local �������� ������:

ftpproxy_flags=""
            

����� ��������� ��������� �������, ����� �� ������������� ������.

��� ������ ��������� FTP ��� ����������� ���� -r ��� ftp-proxy(8)

C.2.3.3.2.1. ������������� ftp-proxy(8)FreeBSD

FreeBSDNetBSD ���������������� ftp-proxy(8) ����, ��� � OpenBSD. ����������, � ���� �������� ���� ����������� ���������� ������ ftp-proxy(8). ������ ftp-proxy(8) � ���� �������� ����� ������������ ���� ftp/ftpsesame. ��. �����̚C.5.3, «ftpsesame». ����� �������, ��� ������������ ������ ������ ��������� ftp-proxy(8), ������� �������������� FreeBSD.

FreeBSD ftp-proxy(8) ����������� �� ������������ inetd(8). ��� ����� � /etc/pf.conf(5) �� ��������� �������� ����� �������:

int_if = "xl0"
rdr pass on $int_if proto tcp from any to any port 21 -> 127.0.0.1 port 8021
              

����� �� ������������� inetd(8) ���, ����� �� ����� ������� ���� 8021. ��� ����� � ���� /etc/inetd.conf ��������� ������:

ftp-proxy stream tcp nowait root /usr/libexec/ftp-proxy ftp-proxy
              

����� �������, ftp-proxy(8) ������������ ��������� ����� FTP, � ��� �������� ������ ���������� �������� ����������� ������� � ����������:

block in on $ext_if proto tcp all
pass  in on $ext_if inet proto tcp from any to $ext_if \
   port > 49151 keep state
              

��� ������� ��������� ����������� � ������ �� 49151 �� 65535. ��������� ftp-proxy(8) ����� �������� ��������� ������ ��� ������ ����� -m-M. ��������� ��. man(1) �� ������� ftp-proxy(8). �������� ������ ������������ ������� ftpd(8)FreeBSD ����� ������������ ��� ������ ���������� ���� net.inet.ip.portrange.first net.inet.ip.portrange.last, � � OpenBSD net.inet.ip.porthifirstnet.inet.ip.porthilast.

���� ��������, ��� ������� � ������������� ���������, ���������� � OpenBSD �������� ��������. �������� ���������, ��� � ������� �� ����� ���������� � FreeBSD, � ����, ���������, �� ����� ������������ ���� ftp/ftpsesame.

C.2.3.3.3. FTP ������ ����ݣ���� �������� �������� ���������� ��������������� �� Σ�

��� ���������������� ��������� ������� � FTP ������� �� ����� ������ ���������� ��������� � ��� ������� �������� � ��������� ������ �� 49151 �� 65535. ���� �������� ������ ������������ �� ��������� ��������� FTP ��������� ftpd(8). �������� ������ ����� ������������ � FreeBSD ��� ������ ���������� ���� net.inet.ip.portrange.first net.inet.ip.portrange.last, � � OpenBSD net.inet.ip.porthifirstnet.inet.ip.porthilast.

pass in on $ext_if proto tcp from any to any port 21 keep state
pass in on $ext_if proto tcp from any to any port > 49151 keep state
            
C.2.3.3.4. FTP ������ ����ݣ���� ������� �������� �������� � ���������� �� Σ� NAT

� ���� ������ ���������� ������ �������������� FTP ������ ������� � �� ����������� ������ �����. ��� ����� �� ����� �������� � ������������� ������������ ftp-proxy(8).

ftp-proxy(8) ����� ���� ������� � ������ ��������������� ����� FTP ������� �� ���� ������ FTP. ������ �� ����������� ���������� ���, ����� �� ������ ���� 21 � ������������ ������ �� ���������� ������ FTP:

ftpproxy_flags="-R 10.10.10.1 -p 21 -b 192.168.0.1"
            

����� 10.10.10.1�— ����� ������� FTP, � �������� �� �� ����� 21. 192.168.0.1�— ������� ����� �����������, � �������� �� ����������� ��������� ftp-proxy(8).

������� pf.conf:

ext_ip = "192.168.0.1"
ftp_ip = "10.10.10.1"

nat-anchor "ftp-proxy/*"
nat on $ext_if inet from $int_if -> ($ext_if)
rdr-anchor "ftp-proxy/*"

pass in on $ext_if inet proto tcp to $ext_ip port 21 \
    flags S/SA keep state
pass out on $int_if inet proto tcp to $ftp_ip port 21 \
    user proxy flags S/SA keep state
anchor "ftp-proxy/*"
            

����� user proxy ����� ��� ����, ����� ���������, ��� ������ ��������� ftp-proxy(8) ����� ������������ ������.

[���������]���������
FreeBSDNetBSD ������ ftp-proxy(8) ����� ������������ ���� ftp/ftpsesame. ��. �����̚C.5.3, «ftpsesame».
C.2.3.3.5. ������������� TFTP

��� ������ � ���������� TFTP � OpenBSD ����������� ������ ���������-�������˚— tftp-proxy(8). � ������� �� ftp-proxy(8) ��� ������ ����������� �� inetd(8).

C.2.3.4. Authpf: ����������� � �������� �������

authpf(8)�— ���������������� �������� ��� ����������� �� �����. ��� ������������� ���� ��������� ���� �������� ��� ������� �������������, �� ���������� ���������������� ������ ������ ���� ������������ ������������������ �� Σ�. ���� ���������������� �������� ���������� � /etc/sbin/authpf (�.�. ������ csh(1) � ��.) � ������������ ��ۣ� � �������, �������� ����� ssh(1), authpf(8) ����������� ����������� �������� ������ ���, ����� �� ����� ���������� ������ ������������, ����������� ������ ������������ ��������������� � ����������. ����� ������������ ���������� ������ ssh(1), authpf(8) ������� ������� �� ��������� ������� � ������� ������ �� ������� ���������. ����� �������, ������������ �������� ��������� ���������� ������ ���� ������� ������ ssh(1).

authpf(8) ��������� ������� ���������� � ���������� ��������� ���������� ��� ������� ������������ �����. �������� ����� �������� ����������� �� ����� ������������ � PID ���������� authpf(8) � ������� username(PID). ������ ���������������� ����� ��������� ������ ����� authpf, ������� ��� ��������� � �������� ������ ������. ����� �������, «��������� �����ۣ���� ��� �����» �������� ���

main_ruleset/authpf/username(PID)
          

�������, ������� ����� ��������� authpf(8) ����� ���� ��������������� ��� ������� ������������, � ����� ���� �����������.

��� ������� ������������� authpf(8):

  • ���������� �� ������������ ������������������� ����� ������� � ��������.
  • ������ ��������� ������������� (���������������) ���� ������� � �������� ������� ����.
  • �������������� ������ ��������� ������������� ����������� ������� � �������� �� ������������ ���� (���� �� ����� �������� � ��������� �������� � ������������ ����).
  • �������������� ����� ���������� ���� ��� �������������� �� ���� ������� � ���� ��������. ������������ ����������� ��� ����� ����� �� ������ ����� � ���� �����������, �� ��� �� ����� ���� �������������� �� ���� desktop �� ��������� ���ģ����� ��� ������ � ������.
  • � ������ � �������� ��������� ���������� (����������� � �.�.) ����� ���� �������� ������������ ������ � �������� ��� ������, � ������������������ ��� ������ authpf(8) ������������� ������������ ������ ������ � ��������.

���������� �� ��������������������� ������������� ������������� ����� syslogd(8). ��� ��������� �������������� ��������� ��� ����� ����������� ���������� � ��������� ����� ������������ ����������� ������� ���������� �������.

C.2.3.4.1. ���������������� authpf(8)

��������� ���������������� authpf(8) ������� � man(1) �������� �� authpf(8).

C.2.3.4.1.1. ��������� authpf(8)

� ������� ������ ������������ ���������������� ���� /etc/authpf/authpf.conf. � � ���������� ���������������� ����� authpf(8). ���� ����� �� ����������, authpf(8) ����� ��������� ������ ����� ����� ��������������. ���� �� ����������, �� ����, ����� ������������ ���������.

� ���� ����� ����� �������������� ��������� ��� �����:

anchor=name
������������� �����name ������ authpf
table=name
������������� �������table ������ authpf_users.
C.2.3.4.1.2. ��������� authpf(8) � �������� ����� ������

authpf(8) ���������� � �������� ����� ������ ��� ������ ������� anchor:

nat-anchor "authpf/*"
rdr-anchor "authpf/*"
binat-anchor "authpf/*"
anchor "authpf/*"
              

�������� ������ �����ģ� � �������� ������ �������� � ��� ����� ���, ��� ��� �����������. ��� ����� ������ ������������ ��� �����. ��������, ���� authpf(8) �� �������� �� ��, ����� ������������ ���������� NAT, �� ��������������� ����� �� �����.

C.2.3.4.1.3. ��������� ������������ ������

authpf(8) ���������� ������� �� ������

  • /etc/authpf/users/$USER/authpf.rules
  • /etc/authpf/authpf.rules

������ ������ ������, ����� ������, ���� ���������� ����— ������������ ������ ����. ����� �������, � ������ ����� ������ ��������� ������� ����������� ��� ����������� ������������ � ��� ����� ���������� ���������� ������� �������� �� ������ �����. ��� ������� ���� ���� ������ ������������, ����� authpf(8) �� ����������.

������� ���������� ����� �� ��� � � �������� �����, ������ ���������� ��� �������:

$user_ip
IP ����� � �������� ���ۣ� ������������.
$user_id
��� ��������������� ������������.

������������� ������������ $user_id ��� ����, ����� ��� �����ۣ� ������ ������ � ���������������� ������.

� ������� � ������� $user_ip authpf(8) ����� ������������ ��� �������� ���� ��������������������� ������������� ������� authpf_users ���� ��� ����������. ���������, ��� �� ���������� ţ, ������ ��� ������������:

table <authpf_users> persist
pass in on $ext_if proto tcp from <authpf_users> \
    to port smtp flags S/SA keep state
              

��� ������� ������ �������������� � ��������, ������� ��������� �� ���� ��������������������� �������������.

C.2.3.4.1.4. ������ �������

������������� ����� ��������� ������������ authpf(8) ��� ����� ���� ������� ���� � �������� /etc/authpf/banned/. ���� ������ ���������� �� ����� ������������. ��� ���������� ����� �������� ������������ ����� ������� �����. ����� �������, � � ����� ������� ������� ����������� ������� � ��� ��������� � ������������� �����.

����� ����, � ����� /etc/authpf/authpf.allow ����� ����������� �������������, ������� ��������� ������� � ������� � �������������� authpf(8). ���� ���� ����������, ��������� �������� «��� �� ���������, �� ���������». ���� ����� ���, ��� ���� � Σ� �ף������ *�— authpf(8) ��������� ����� ����, ��� ������� ����������� ����� ssh(1), ���� ������ ��� �� «��������» � �������� /etc/authpf/banned/.

���� authpf(8) �� ����� ���������� ��������� ����������� ������� ��� ���, �� �������� �������������� � �� ������� ������������. /etc/authpf/banned/ ������ ������� /etc/authpf/authpf.allow.

C.2.3.4.1.5. �����������

����� ������������ ������� ����������������� � �������, ��� ����� ���������� �������������� ���������

Hello charlie. You are authenticated from host "64.59.56.140"
              

��� ��������� ����� ��������� ���������� �� ����� /etc/authpf/authpf.message.

C.2.3.4.1.6. ��������� authpf(8) � �������� ���������������� ��������

����� authpf(8) ���������, ��� ���� ������� ��������� ������������. ����� ������������ ������� ���ģ� � ������� ����� ssh(1), authpf(8) ����� ������� � �������� ��������. �� �������� ����� �� ������������ ��� ������������, �������� ������ ������� � �.�.

���� ��� ������� ��������� ������������ authpf(8) � �������� ��������:

  • �������, ������� ������������, ��������� ������� chsh(1), vipw(8), adduser(8), pw(8), (��������� ��� � FreeBSD), useradd(8), usermod(8) (��������� ��� � OpenBSD), � ��.
  • �������� ������������ ����� � ����Σ���� ���������, ����������� ����� login.conf(5). (��. ���������ŚF, /etc/login.conf(5)).
C.2.3.4.2. �������� ������ authpf ��� /etc/login.conf(5)
[���������]���������
��� ����� ������, ����� ��� �����, ��� �� ���������, �������� ������� � ���������ŚF, /etc/login.conf(5).

� �������, ��� ���� ������������ ������� ������������ � ������������ ��� authpf(8) ������ ������� ��� ��������� ����������� �����. ��� �������� ������� ������ �������� ��� ������ �������������. ��������, � ������ ����� �������:

shell
����� ֣���� ������� ������������� �������� /usr/sbin/authpf ���, ��� ţ ���������� ����� ������� ����� ��������� chsh(1)�— ��� ����� login.conf(5) ����� ��������� ����� ���������� ����� passwd(5).
welcome
����� ������� ������ ����������� ��� ������ ����� ������������.

����� ��������� � ����� /etc/login.conf. ��� ������ ������ ��� ������������� authpf(8):

authpf:\
    :welcome=/etc/motd.authpf:\
    :shell=/usr/sbin/authpf:\
    :tc=default:
            

����� �������������� ����� /etc/login.conf �� �������� ��������� �������

# cap_mkdb /etc/login.conf
            

��������� ������������ ����� ����� ������� ���������. ��������: chsh(1), pw(8), vipw(8).

����� ����������� ������ ������������� �� ������ authpf, ����� ��������� ����� �������:

# awk -F: '$5=="authpf"{print $1}' /etc/master.passwd | sort
            
C.2.3.4.3. ��� ��ۣ� � ������� ����� authpf(8)?

����� ����, ��� ������������ ������� ��ۣ� � �������, authpf(8) ������ ��������� ��������, ������� � ���� ��� ������������ � IP ����� � �������� �� ���ۣ�:

$ ps -ax | grep authpf
23664 p0  Is+     0:00.11 -authpf: charlie@192.168.1.3 (authpf)
            

������ ����� �������� ������ SIGTERM ����� �������� �������� ������ ������������. ��� ���� authpf(8) ������ ��� ������� �� ��������� ������� � ��������� ������� ������������. � ���� ������� ������ SIGKILL, �� �� ������, � ������������ �� �������� ����� ������ ����� ����!

# kill -TERM 23664
          
C.2.3.4.4. ������

����� �������� ������ ������������ �� ������ OpenBSD, ������� �������� ������ ��� ������������ ����, ������� �������� ������ ������� ��������������� ����. ���� ������������ ������������������, � �� �� ��������� � ������ �����ݣ���� ������������� (/etc/authpf/banned/), ��� ��������� SSH ������, ������������ web, �, �������, ��������� ������ � DNS.

���� /etc/authpf/authpf.rules �������� ��������� ������:

wifi_if = "wi0"

pass in quick on $wifi_if proto tcp from $user_ip to port { ssh, http, \
   https } flags S/SA keep state
            

������������� charlie ������ ����� ������ � SMTP, POP3, � ��� �� web � SSH.

���� /etc/authpf/users.charlie/authpf.rules �������� ��������� ������:

wifi_if = "wi0"
smtp_server = "10.0.1.50"
pop3_server = "10.0.1.51"

pass in quick on $wifi_if proto tcp from $user_ip to $smtp_server \
   port smtp flags S/SA keep state
pass in quick on $wifi_if proto tcp from $user_ip to $pop3_server \
   port pop3 flags S/SA keep state
pass in quick on $wifi_if proto tcp from $user_ip to port { ssh, http, \
   https } flags S/SA keep state
            

�������� ���� � ���������, ������������� � /etc/pf.conf �������� ��������� ������:

# macros
wifi_if = "wi0"
ext_if  = "fxp0"
dns_servers = "{ 10.0.1.56, 10.0.2.56 }"

table <authpf_users> persist

scrub in all

# filter
block drop all 1

pass out quick on $ext_if inet proto tcp from \
   { $wifi_if:network, $ext_if } flags S/SA modulate state
pass out quick on $ext_if inet proto { udp, icmp } from \
   { $wifi_if:network, $ext_if } keep state 2

pass in quick on $wifi_if inet proto tcp from $wifi_if:network to $wifi_if \
   port ssh flags S/SA keep state 3

pass in quick on $wifi_if inet proto { tcp, udp } from <authpf_users> \
   to $dns_servers port domain keep state 4
anchor "authpf/*" in on $wifi_if 5
            

������� ����� ������. ���, ��� ��� ������:

1 ��������� ���� ������ (�������� default deny).
2 ���������� ���� ��������� ������ (TCP, UDP � ICMP) �� ������� ���������� �����, ��� �� ������������ ����, ��� � ������ � ������ �����.
3 ���������� �������� ������ SSH �� ������������ ���� (����� ��� ��������������).
4 ���������� ������� DNS �� ��������������������� �������������.
5 ������� ����� ��� authpf(8).

�������� ���� � ���, ����� ������������� �ӣ � ������� ��������� ����, ��������� ��� ��������. ������ ����� �������� �������� ������� ���������, ������ �� ������������ ��������� default deny �� ���������� (wi0) ����������. ����� ������������ �����������������, ��� ������ ����������� �����ۣ� ��� ������� �� ���������� ���������� �, ����� �������, �������� ������. �������� ����� quick ������������ ��� ����, ����� ����������� �� ���� ������� �� ����������� �� ����������� �����������.

C.2.3.5. CARP � pfsync

C.2.3.5.1. �������� � CARP

CARP�— Common Address Redundancy Protocol (����� �������� ���������� �������, � �� ���� ���� �� ������������ ������� �� ������� ����). �������� ������ ����������— ���� ����������� ��������� ������ � ��������� ���� ������������ ����� IP �����. CARP �������� ��������� � ���������� ������������� ���������� VRRP (Virtual Router Redundancy Protocol, ��. [RFC-3768]) � HSRP (Hot Standby Router Protocol, ��. [RFC-2281]). � ���������, �� ���� �������� �� ������������ RFC. ����� ����, ��� ���������� ������ �������� � ��� �� ���������: (Cache Array Routing Protocol, [RFC-3040]�— �������� ������������ Microsoft�ISA).

������� ������� ������ (�� ������ wikipedia): � ����� 90-� ����� IETF ������ ������ ��� ��������� ������������������ ��������. � 1997 ���� Cisco ����������������, ��� �������� ��� ������ ��� ������ ��������������� ��� ����������. � 1998 ���� Cisco ������������ ��������������� �������� HSRP. �������� �� ��� IETF ���������� ������ ��� ����� ���������� VRRP. ����� ��������� ������� ���� ������, ��� ��������������� ���������� ����� ������������ � �������� ��������� ��� ������� �������������� �� «�������� � �� �����������������» ��������. ������, ��������� VRRP ������ ��������� �������� HSRP ���� Cisco ������� �� ������������� VRRP ��� ���� ������� ��� �����.

Cisco ���������������� ������������� OpenBSD, ��� ��� �� ����� ������������ ������������� VRRP. �������� ��� ���� ������� � ��������� ������� Cisco � Al�atel (������ ��������Ϛ— �.�.). ����� �������, ��������� ���������� VRRP ������� ���� ������, ������� OpenBSD ��������� �� ���������� ��������������� ��������� CARP.

� ��������� ������ CARP ���������� �� ������ � OpenBSD, �� ��� �� ���������� � FreeBSDNetBSD (�, ������������� � DragonFly�BSD).

IANA �� ��� �� �� �������� ����������� ����� ��������� ��� CARP. ��� �������, �� ���� ���������, � ����������� ��� ��������. ������������ OpenBSD ���������� ��������� ��� ����� 112 (������������� � VRRP). �� �� �������� � ��������� pfsync.

CARP ��������� ������ ������ ������������ ����� IP �����. ��� ������ ������ ���������� «���������� ������» (redundancy group). ���������� ������ ������������� ����� �����, �����, ����� ţ ������ ����������� «������» � �������� ������ (backup). ������, ��� �� ������, ������� � ������ ������ ����������� ����� ����� IP. �� �������� �� ARP �������, ����ݣ���� � ����� ������. ������ ���� ����� ������������ ����� ��� � ����� «���������� ������».

���� �� �������� ������������� CARP�— ���������� ���������� ������������. ����������� IP �����, ������������� ������, ��������� �������� � �������� �������� �� ���������. ���� ���������� ����������� ����������, IP ����� ��������� � ������, �������� ������ � ������ � ������ ���� ������������.

C.2.3.5.2. ��� �������� CARP

������-���� ������ ��������� �������� ���������� � ��������� ����, ����� �������� ����� �����, ��� �� �ݣ ���. ���� �������� ���� � ������� ���������� ������� �� �������� ����������� �� �������, �� �� ����� ������� �� ���� ����������� �������. (����� �����Ϛ— ������� �� �������� advbaseadvskew).

� ����� ��������� ���� ����� ���������� ��������� ����� CARP, ��� ��� � ����������, ����������� �������� ������������ Virtual Host ID, �� �������� �������� ������ ����� ������ ����� ������ ���������� ����������.

����� ������������� �������� ���������� ���������� CARP, ������ ������ ����� ���� ���������������� � �������. ������ ����� CARP ���������� ���� ������� � ���� SHA1 HMAC.

CARP ����������� ��� ������ ������������ ��������� �������� ������ (����� 112, ���������� �� ������ģ� IANA) � ��� ����� ��������� ������� � �����������:

pass out on $carp_dev proto carp keep state
            

����� $carp_dev�— ���������� ��������� ����� ������� ���������� ���������� CARP.

C.2.3.5.3. ��������� CARP

������ ������ CARP ������������ ����������� ������� ����������� carp(4). ����� �������, CARP ����� ��������� ��������� ������� ifconfig(8):

# ifconfig <carpN> create

# ifconfig <carpN> vhid <vhid> [pass <password>] [carpdev <carpdev>] \
   [advbase <advbase>] [advskew <advskew>] [state <state>] <ipaddress> \
   netmask <mask>
            
carpN
��� ����������. N�— ����� �����, ����� ����������, �������� 10.
vhid
Virtual host ID�— ������������� ������ CARP. ����� ����� �� 1 �� 255.
password
������ ������ ��� �������������� ������ ������. ������ ���� ����� ��� ���� ������ ������.
carpdev
���������� ��������� ������������� ������. �������������� ��������. �� ��������� CARP �������� �������������� ���������� ��������� �� ������ IP-������ � ����� �������. �������� ����������� � FreeBSD.
advbase
�������������� �������� ����������� �� ��, ��� ����� ����������� ����������� � ������. �� ��������� 1. ���������� �������� �� 1 �� 255.
advskew
�������������� �������� ��������� �� ��, ��������� ����� ���������� �������� advbase. �� ������ ������� advbaseadvskew ���������� ����� ������� � ������: ��� ������ advbase, ������� ����� ������������ ����, ��� ���� � ���� ���������. �� ��������� 0. ���������� �������� �� 0 �� 254.
state
��������� ����������� ��������� ������� � ������ ���������. ���������� ��������� init, backup, master. �������� ����������� � FreeBSD.
ipaddress
����� ����������� ������. �� �� ������ ��������� � ��� �� ����, ��� � ���������� ���������. ����������, ����� �� �������� � ���� ������ ������.
mask
����� ������� ��� ���������̣����� ������.

���������� CARP ����� ��������� ����� sysctl(8). ��� ��������� ���������� ����:

�������� ���� ���������� ���� �������� ��� � OpenBSD, ��� � � FreeBSD:

net.inet.carp.allow
��������� ��� ��� ������ CARP. ��������� 1 (��).
net.inet.carp.preempt

��������� ������� �������� ��� ����������� ������ ������ ������ CARP ������� ������ ���������� advbaseadvskew. ����� ����, ��������� ���������� �������� �������— ���� ���������� ��������� �������, �� ������ ����������� � ����ޣ���� CARP advskew ������������ � 240.

������: ����� ������� ������������� A � ����� ������������ � CARPadvskew=0 � ������������� B � advskew=100. ���� ������ ���������� ���� ���������� � ������, � �� �������������� A ������ ���� ���������. � ���� ������ advskew �� A ������������� �� 240 � ����������� ������� ��ң� ������������� B.

�� ��������� ��������� � 0 (���)

net.inet.carp.log
�������� � ������ ���������� � ������ ������� CARP. � OpenBSD �� ��������� 0 (���������). � FreeBSD �� ��������� 1 (�������������� ������������ �������). � FreeBSD �������� 2 �������� � ������ ���������� � ����� ��������� CARP ����������. �������� ��� �������� �������� � � OpenBSD, �� ��� ��� �����������������.
net.inet.carp.arpbalance
������������ ARP ��������. ��� ����� �������� �� ������� � ���, � ���� ������� ������ IP �����. �� ��������� ���������.

�������������� ���������� ����� �������� �� ����������� man(1) �� carp(4) � �� [url://Sgibnev-CARP-2006].

C.2.3.5.4. ������ CARP

������ ������������ CARP:

# sysctl -w net.inet.carp.allow=1 1
# ifconfig carp1 create 2
# ifconfig carp1 vhid 1 pass mekmitasdigoat carpdev em0 \
    advskew 100 10.0.0.1 netmask 255.255.255.0 3
            
1 �������� ��ɣ� ������� CARP (��� ���������).
2 ��������� ��������� carp1.
3 ��������������� ��������� ���������: ��� ������������� vid=1 (���� id), ��������������� ������, ����������� ���������� ��������� em0, ������ ���� ����������� �������� (������ ����� � ������� advskew<100). ������� ���������̣���� ����� ���������� 10.0.0.1/24.

����� ����������� ��������� ���������� carp1 �� ����� ����� ������������ ������� ifconfig(8)

$ ifconfig carp1
carp1: flags=8802<UP,BROADCAST,SIMPLEX,MULTICAST> mtu 1500
     carp: BACKUP carpdev em0 vhid 1 advbase 1 advskew 100
     groups: carp
     inet 10.0.0.1 netmask 0xffffff00 broadcast 10.0.0.255
            
C.2.3.5.5. �������� � pfsync(4)

��������� pfsync(4) ������������ ��� ���������� �� �������� ��������� ��������� �������. ��� ������ ������� tcpdump(8) ����� ������� �� �������� ��������� � ������ ��������� �������. ����� ����, pfsync(4) ��������� �������� ���������� �� ���������� � ������� ��������� �� ����. ����� �������, ������ �������� ������� �� ������ ������� ����� �������� ��� ���������� � ���� �������. ����� �������, pfsync(4) ��������� �������������� ������� ��������� �� ����.

C.2.3.5.6. ������������� � pfsync(4)

�� ��������� pfsync(4) �� �������� � �� �������� ���������� � ��������� ����������. ��� �� ������ ������� �� ��� ������������� ��������, ��� ������ tcpdump(8).

����� pfsync(4) ��������������� ��� �������� ��� ��������� ����������, �� �������� ��������� ţ ��� ������ multicast ������� � ��������� ����. ��� ���������� pfsync(4) �������� ��� ��������������. ��������� �������� ������� � ���, �����:

  1. ��������� ������ «����� � �����» ��� ������ ���������� �������� (�����). � ������������ ����� syncdev (��. ����).
  2. ������������ ����� ifconfig(8)syncpeer (��. ����). ��� �����ģ� � ����, ��� ���������� ����� ���������� �� unicast ������. ����� ���� ����������� ������ ����� ����Σ���� ��� ������ ipsec(4).

��� ������ ����������� pfsync(4) ���� ���������������� �������� ������ ���, ����� �� ����� ���� ������ ���������� (pfsync ���������� ���� �������� �������� ������, ����� 240, ���� ����� ���������� �� ������ģ� IANA):

pass on $sync_if proto pfsync
            

����� $sync_if�— ���������, ����� ������� �ģ� ����� �����������.

C.2.3.5.7. ���������������� pfsync

��������� pfsync(4)�— ����������� ������� ���������, ��� ����� ��������������� ��������� ifconfig(8):

ifconfig <pfsyncN> syncdev <syncdev> [syncpeer <syncpeer>]
            
pfsyncN
��� ���������� pfsync(4). ��� ������������� ���� GENERIC ��������� pfsync0 ���������� �� ���������. ��� ��������� � � OpenBSD � � FreeBSD.
syncdev
��� ����������, ������� ������������ pfsync(4) ��� ������� ����������.
syncpeer
���� �������������� �������� ������������ ��� �������� �����, � ������� �ģ� ����� �������. �� ��������� pfsync(4) ���������� ����� multicast, � � ������ ������ ���������� unicast.
C.2.3.5.8. ������ ������������� pfsync

������:

# ifconfig pfsync0 syncdev em1
            

��� ������� �������� pfsync(4) �� ���������� em1. ��������� ������ ������������ ��� ������ multicast � �������� ���� ������ � ����, �� ������� ������� pfsync.

C.2.3.5.9. ���������� ������������� CARP � pfsync ��� ������������������

���������� ������������� CARP � pfsync ��������� ������� ��� � ����� ����������� � ���������� �� � ���������� ������������������� �������. ��� ���� CARP ��������� ���������������� �������, � pfsync ��������� ���������������� ������ ������ ���������, ���, ��� ��� ������ �������, �������� ������ ��ң� �� ���� ��� ������� � ��� ���� �� �������� ��������� ����������.

��������, ����� � ��� ������� ��� ������������— fw1 � fw2:

              +----| WAN/Internet |----+
              |                        |
              |      ����� �����       |
              | +----192.0.2.100-----+ |
              | |                    | |
 192.0.2.1:em2|/                      \|em2:192.0.2.2
           +-----+        10.10.10.2+-----+
           | fw1 |-em1----------em1-| fw2 |
           +-----+10.10.10.1        +-----+
172.16.0.1:em0|\                      /|em0:172.16.0.2
              | |                    | | 
              | +----172.16.0.100----+ |
              |      ����� �����       |
              |                        |
           ---+-------Shared LAN-------+---
            

����������� ��������� «����� � �����» ����� ����� ����� ���������� em1. ��� ��������� � ��������� ����� ��� ������ ����������� em0 � � ������� ����� ����� ���������� em2. ������ �������� �� �����. �����Қ— fw1.

������������� fw1:

��������� ����������� ��������� � ����:
# sysctl -w net.inet.carp.preempt=1

����������� pfsync
# ifconfig em1 10.10.10.1 netmask 255.255.255.0
# ifconfig pfsync0 syncdev em1
# ifconfig pfsync0 up

����������� CARP �� ���������� ����������
# ifconfig carp1 create
# ifconfig carp1 vhid 1 carpdev em0 pass lanpasswd \
     172.16.0.100 netmask 255.255.255.0

����������� CARP �� ������� ����������
# ifconfig carp2 create
# ifconfig carp2 vhid 2 carpdev em2 pass netpasswd \
    192.0.2.100 netmask 255.255.255.0
            

������������� fw2:

��������� ����������� ��������� � ����:
# sysctl -w net.inet.carp.preempt=1

����������� pfsync
# ifconfig em1 10.10.10.2 netmask 255.255.255.0
# ifconfig pfsync0 syncdev em1
# ifconfig pfsync0 up

����������� CARP �� ���������� ����������
# ifconfig carp1 create
# ifconfig carp1 vhid 1 carpdev em0 pass lanpasswd \
     advskew 128 172.16.0.100 netmask 255.255.255.0

����������� CARP �� ������� ����������
# ifconfig carp2 create
# ifconfig carp2 vhid 2 carpdev em2 pass netpasswd \
    advskew 128 192.0.2.100 netmask 255.255.255.0
            
C.2.3.5.10. ��������� �� ������������� CARP � pfsync

��������� �������������� �������� ��� ������������� CARPpfsync(4).

C.2.3.5.10.1. ���������������� CARP � pfsync ��� ��������

carpNpfsyncN �������� �������� ������������ � ������������� ��� ��� ����� ������������� ������� ������� ���������� (��: �����̚6.2.6, «��� ��������� ������������� ������� ���������»). � OpenBSD ��������� ���� hostname.if:

���� /etc/hostname.carp1:

inet 172.16.0.100 255.255.255.0 172.16.0.255 vhid 1 carpdev em0 \
    pass lanpasswd
              

���� /etc/hostname.pfsync0:

up syncdev em1
              

FreeBSD ��� ����������� ��������� ������ � /etc/rc.conf:

ifconfig_carp1="172.16.0.100/24 vhid 1 carpdev em0 pass lanpasswd"
ifconfig_pfsync0="up suncdev em1"
              
C.2.3.5.10.2. �������������� �������

������ ������ ����� ��������� ������� � ������ ����� �� ������. ��������, ���� ���������� ������� ��� ���������������� ����� ��� ��� �������. ����� ����������� ��� ��� ������� �� ����� ��������� ���������, ����� ������������ ������ �� ��������.

��� ���� ����� �� ������ ���������� ��������� carp. ������ ��� ���� �������� ���������� ������� �������� advbaseadvskew �������� ������ ���������� ��� ��������� � ���� �� ��� ������ �� ���� ����������� �������.

# ifconfig carp1 down
              

������ ������� ������� � ���, ��� �� ������������ �������� advbaseadvskew ��� ���� ����������� ������� �������� � �������� ������, �� ������ ������ �� ����� ������� �� ������ CARP.

������ ������� ������� � ���, ����� ��������� CARP'�� ��� ������ ���������� demotion. ��� ����������� ���� ����������� ������ � OpenBSD.

[��������]��������
��������� �������� ��������� � ���������� demotion �������� ������ � OpenBSD.

���������� demotion ������������� ������ �����������. ������� ��� �������� �� ������ �������� CARP �� �������� ������ �����������. ������� �������� demotion ����� ������� ��� ������ ������� ifconfig(8):

$ ifconfig -g carp
carp: carp demote count 0
              

����� �������� �������� ��������������� � ������� carp.

���������� ����� ������: ������� ��� ����������� � ���������� CARP �� ���������� CARP ������������:

carp1
������ �����
carp2
������ �����
carp3
��������
carp4
���

������ ������� � ���, ����� ��������� ������ carp1carp2 �� ������ ������.

��� ������ �������� ��� ���������� ������ «internal»:

# ifconfig carp1 group internal
# ifconfig carp2 group internal
$ ifconfig internal
carp1: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
     carp: MASTER carpdev em0 vhid 1 advbase 1 advskew 100
     groups: carp internal
     inet 10.0.0.1 netmask 0xffffff00 broadcast 10.0.0.255
carp2: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
     carp: MASTER carpdev em1 vhid 2 advbase 1 advskew 100
     groups: carp internal
     inet 10.0.1.1 netmask 0xffffff00 broadcast 10.0.1.255
              

������ �������� �ޣ���� demotion ��� ������ internal ��� ������ ifconfig(8):

$ ifconfig -g internal
internal: carp demote count 0
# ifconfig -g internal carpdemote 50
$ ifconfig -g internal
internal: carp demote count 50
              

������ CARP �������� ���������� �� ����������� carp1carp2 �� ������ ������, �� ��������� �������� ��� carp3carp4.

����� ������� ��������� ������� ���� ��������� �������:

# ifconfig -g internal -carpdemote 50
$ ifconfig -g internal
internal: carp demote count 0
              

��������� ������� ������, ����� ��� OpenBGPDsasyncd(8) ���������� �ޣ���� demotion ��� ����, ����� ����� ��� ��� ���������� BGP ������ ��� ����� ��� ��� ���������������� IPSec SA, �������ؚ— �������� �� ���������� ��������.

C.2.3.5.10.3. ������ �� ��������� ������ ����������

������ ������ �������� �� ���������� ����������, �� �� ����������� ���������� carp0. �������:

pass in on fxp0 inet proto tcp from any to carp0 port 22
              

���� �� �������� fxp0 �� carp0 ������� ����� �������� �� ���, ��� �� ����� ��������.

[���������]���������
�� ��������� ���������� �������� CARP ��� ������ ������� proto carp � ������ proto pfsync.

C.2.4. ������: ���������� ��� ���� ��� ���������� �����

C.2.4.1. ��������

� ������ ������� �������� ������ ������������ ��� ���������� � NAT � �������� ���� ��� ��������� �����. ������ ������� � ���, ����� ���������� ������ �� ���������� ���� � ��������, ���������� ������������ ������ � ����������� �� ��������� � ���������� ������ � ����������� web-������� �� ��������.

C.2.4.1.1. ����

��������� ����:

             WWW-server
[ COMP1 ]    [ COMP3 ]
   |            |                               
---+------+-----+------- xl0 [ BSD ] fxp0 -------- ( Internet )
          |
      [ COMP2 ]
            

�� ���������� ���� ���� ��������� ���������� �����������. ������� �����Ϛ— �������. � ��� �� ��������� �������� ���. �� ���������� COMP3 �������� ��������� web-������. ���������� ���� 192.168.0.0/24

���������� �������� �� OpenBSD (��� ����� ������ BSD) �� ���������� Celeron�300MHz � ����� �������� �������: 3com 3c905B (xl0) � Intel EtherExpress Pro/100 (fxp0). ���������� ������ ������� FastEthernet � �����������. ��� ������ ���������� ����� � ���� ������������ NAT. ������� ����� ����������� ����������� �����������.

C.2.4.1.2. ������
  • ������������ �������������� ������ � �������� ������ ������ �� ���������� ����.
  • ������������ �������� «default deny».
  • ��������� ��������� �������� ������:

    • SSH (tcp ���� 22): ����� �������������� ��� ���������� ������������ �������.
    • Auth/Ident (tcp ���� 113): ������������ ���������� ���������, ������ ��� SMTP � IRC.
    • ICMP echo request: ���������� �������� ping(8).
  • ������������ ���� 80 (�������� ������ web-�������) �� ������ COMP3. (� �� ������ ��������� ���� ������ � �������� ����������).
  • �������� ���������� ������� �� ������� ����������.
  • ��� ������������ ������� �������� ������ TCP/RST � ICMP Unreachable.
  • ������� ������� �������� ��������� ��� ��������, ��� �������� ��������� �����������.
C.2.4.1.3. ���������������� ��������

�� �������, ��� ������ ���������������� ��� ���� (�.�. ����ޣ� ������� ������� � ���������� �� ���������) � �������� ������ ����ޣ�. � ��� ��� ��� ������ �������� � �����̚C.1, «�������� � ������ � �������� �������� OpenBSD».

C.2.4.2. ��������� �������� ������ ����������

C.2.4.2.1. �������

���������� ������� ��� ���������� ���������� ������������ � ��������� ������ ������:

ext_if="fxp0"
int_if="xl0"

tcp_services="{ 22, 113 }"
icmp_types="echoreq"

comp3="192.168.0.3"
            

������ ��� ������ ���������� ������� ���������� �����������. ���� ��� ���ģ��� ��������� ���������� � ������ �� ������, ��� ���� ����� �������� ������ ��� ��� �������, ��������� ������� ����� �� �������� ��������������. ������ � ���ף���� ������ ���������� ������ �������� ������ � ���� ICMP ��������� ����������� ������. � ��������� ������ ����� ����� ������ COMP3.

[���������]���������
���� ���������� ����������� ����� PPPoE, NAT ���������� ������ �������������� �� ���������� tun0, �� �� fxp0.
C.2.4.2.2. �����

��������� ��� ����� ���������� ��������� ������� ��� ������������ ������� � �������� �������������� ��� �������� ����������:

set block-policy return
set loginterface $ext_if
            

������ UNIX-������� ����� ��������� ���������, ����������� ��� ����, ����� ��������� ����� �������� ���� � ������ ��� ������ ������� ���������� ������ ������. ���������� �� ��������� ���������� ����� ��������ؚ— ����� �� ������ ������ ��������.

set skip on lo
            
[���������]���������
OpenBSDlo ��� ������ ��������� �����������, ������� ��� ��������� ������ �������� ���������� ��� �� ���ģ��� �� � ޣ� ���������� ����������. � ��������� ��������, FreeBSD, NetBSD, DragonFly�BSD, ��� ���ģ��� ���������� ��� ����� �������� ��� ������� �������� ���������� lo0, lo1 � �.�. (������ ����� �� ������ ������ �� ����).
C.2.4.2.3. ������������ �������

��� ������ �� ������������ ��������������� ��������� ������������ �������. ������� ������������, ��� ����� ���� ������:

scrub in
            
C.2.4.2.4. ���������� NAT

��������� ������� ������������ ��� ���������� NAT ���� ���������� ����:

nat on $ext_if from !($ext_if) to any -> ($ext_if)
            

�� ����� �������� !($ext_if) �� $int_if, �� ����� ��� ���ģ��� ��������� ������� � ����������, ���� �� ������� � ���� �ݣ ���� ���������, ������� ����� �������� � ������ ���������� ����.

������� ������ ������ ���������� ����� ������, ��� ����� ��� ����������� �����������.

��� ������ FTP-������, ������� �����:

nat-anchor "ftp-proxy/*"
            
C.2.4.2.5. ���������������

��-������, ��� ����������� ������� ��������������� ��� ������ ftp-proxy(8), ����� ������� �� ��������� ���� ����� ������������ FTP:

rdr-anchor "ftp-proxy/*"
rdr on $int_if proto tcp from any to any port 21 -> 127.0.0.1 port 8021
            

�������, ��� ����� ����� ���������������� ������ FTP � ����������� ������� �� ����� 21. ���� ������������ ��������� ���������� ������ �����, ������� ������������ ������: from any to any port {21, 221}.

��-������, ��� ���� ������������� ��� �������� ���������� �� 80-� ���� ������ COMP3.

rdr on $ext_if proto tcp from any to any port 80 -> $comp3
            
C.2.4.2.6. ����������

��� ������ ���������� �������� default deny:

block in
            

����� �� ����������� ���� �������� ������, ���� �� ���������� ����. ������ �� ����� �� ������� ��������� ������� ������������ ������ ������.

������ �����, ��� �������� ������ ����� ����������� �������� �������� ������ � �������� ���������. �� � ���� ����������� ���� �������� ������, �� ���� ����� ��� ��ۣ� (�.�. �� �������������� ������������ �������, ������� ����� �������� ����), �� �� ����� ��� ���������:

pass out keep state
            

��� ����������� ����� ��� ftp-proxy(8):

anchor "ftp-proxy/*"
            

�������� ��� �� ���������� �� ��������:

antispoof quick for { lo $int_if }
            

������ ������� �����, ������������ ���������, ������ ������ ���� �������� �� ��������. ��� ������, ������ �������������� ������ �����������:

pass in on $ext_if inet proto tcp from any to ($ext_if) \
   port $tcp_services flags S/SA keep state
            

��������� �������� ������ � ������� $tcp_services ���������� ������ ������� ��������� ����������: ���������� ������ ��������������� ����������� ������� � ����������� ����� ������. ����� �������� ������� UDP ����� ������ �������� ������ $udp_services ����������� �������. ��� ���� ����������� �������� ����� �� ������� � ��������� proto udp.

����� ���� ���������� ������ ������ �� ������ COMP3, ������� ���ۣ� ���������� rdr:

pass in on $ext_if inet proto tcp from any to $comp3 port 80 \
    flags S/SA synproxy state
            

����� ������� ��������� ������������ web-������� �� ���������� TCP SYN Proxy.

���������� ������ ICMP:

pass in inet proto icmp all icmp-type $icmp_types keep state
            

���������� ������� $tcp_services, �� ����� ������������� ������ $icmp_types, ����� ����������� ���� ������� ����������� ������������. ��������, ��� ������� �������� ���� �����������.

������ �� ���������� ���� ������ �� ���������� ����. �� ������������, ��� ������������ �� ���������� ���� ����� ��� ��� ������ � ��� �� ������� �������. ������ �� ������ ������� ��� �� ��� � ����������� ����� ֣����� �����������.

pass in quick on $int_if
            

������ TCP, UDP � ICMP ����� �������� ������ ��������� ������� «pass out keep state». ���������� � ���������� �����������, ����� �������, �������� ������ ���� ����� ���������.

C.2.4.3. ������ ������� ������

# �������
ext_if="fxp0"
int_if="xl0"

tcp_services="{ 22, 113 }"
icmp_types="echoreq"

comp3="192.168.0.3"

# �����
set block-policy return
set loginterface $ext_if

set skip on lo

# ������������ �������
scrub in

# nat/rdr
nat on $ext_if from !($ext_if) -> ($ext_if:0)
nat-anchor "ftp-proxy/*"
rdr-anchor "ftp-proxy/*"

rdr pass on $int_if proto tcp to port ftp -> 127.0.0.1 port 8021
rdr on $ext_if proto tcp from any to any port 80 -> $comp3

# ����������
block in

pass out keep state

anchor "ftp-proxy/*"
antispoof quick for { lo $int_if }

pass in on $ext_if inet proto tcp from any to ($ext_if) \
   port $tcp_services flags S/SA keep state

pass in on $ext_if inet proto tcp from any to $comp3 port 80 \
    flags S/SA synproxy state

pass in inet proto icmp all icmp-type $icmp_types keep state

pass quick on $int_if