quick
pf.conf(5)
������ ������ �� 80% ������� �� �������� ����������� ������������ �� ��������� ������� OpenBSD. ��������� 20%�— ��� ���������� �� ������ ����������.
�������� ������ OpenBSD ��� ������� ���������
������� �� ����������������� �����. �� ��������� ��� ����
/etc/pf.conf(5)
. ���� �� ������ ���
���������.
������ ��������� ������� ������� ������ ��������� ������� ��������� � ����� �������. ��������: ������ ����, ����� ������ �� ������ ������� �� ������ 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, «�������»).
�������, ��� ������̣���� ������������� ����������, �������
����� ��������� 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 }"
������� ������������ ��� �������� ������� IPv4 �/��� IPv6. ����� � ��� �������������� ����� ������, ��� ��������� ����������� ������ ������ � ������������� �������, ��� ������. �������, ����� �������, �������� ��� �������� ������� �������� �������, ��������� ����� � ������� � 50�000 ������� ���������� �� �� ����� ���������, ��� � ������� � 50 ��������. ������� ����� ������������ ��������� �������:
route-to
,
reply-to
,
dup-to
,
������� ����� ��������� ��� � ���������������� �����
pf.conf(5)
, ��� � ��� ������
����������� ������� pfctl(8).
� ��������������� ����� pf.conf(5)
������� ��������� ��� ������ ��������� table
. � ������� ����� ���� ���������
��������:
const
, persist
������ (��� ������� ����������� � ������� ������� <...>
):
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 �� ������ ��
������. ������ ������������ � #
��������� ������������ � ������������.
�������� ����� �������������� ��� ������ �������
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)».
����� � �������� ����� ��������� �� ������ � ����
IP-������, �� ��� �� � �� �����. � ���� ������ ����� �����
��������� � ��� ������, ��������������� ������� �����,
������� � �������. ����� ����, ����� ��������� ���
���������� ��� �������� ����� self
. � ���� ������ � ������� ����
��������� ��� ������, ��������������� ������� ����������, ���
��� ������ ������ ������ (������� ��������� ���������)
��������������.
�����������: ������ 0.0.0.0/0 � 0/0 � �������� �� ��������. ����������� ������.
��� ������ � ������� ��������� «�������� ����������» �����, �.�. ���� � ����� ������� ������. (���������� ����� � ����� «�����» ����.) ��������:
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>
:
���������� ������� ����������� � ���, ��� ������ ������������ ��� ������������� ��� ����������� ����� ������� ��������� � ������������ � ���������. ������� �������� �� ���������� ������� �������� � ������������� ������� ������ OSI (��. OSI). �������� ����� ������������ �������ɚ— ������ ��������� � ����������, ������ ������ ��������� � ����������, ���������.
������� ������� ������� �� �������� � ��������, ������� ����
�����������, ���� ����� ������������� ��������. ��������
����� ���� ��� block
��� pass
. ������� ����������� �� �������
�� ������� � ����������, ��� ���� ���������
������� ���������� ���� ������ �� ����������
������� ����� quick
. �����
�������, ���� � ����� ������ ����������������� ����� ������
������� «���������� ��� ������», ���
«����������� ��� ������», �� ��� �� ��� ����, ���
�������� �� ����������— ������ ��� ������� �����
��������� � ������, ������� �� ������������� �� ������
������� ���� �� ���� �����.
���� ��������� ����ݣ���� �������������� �����:
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
keep�state
, modulate�state
��� synproxy�state
�—
� ������ �������� ������ ������ ��������� ����������.
���� ����, ����� � ������ ������ ������ ��� ������,
���������� ������� log�(all)
.
quick
quick
, �� ������ �������
��������� ��������� � � ������ ���������� �����������
�������� action
. (�.�. ���� �
���� ������ ����� ��������� ����� quick
, �� �� ����� ����� ���� �
������������ � ������� ������ ������� ����������.)
interface
��� �������� ����������, ����� ������� �������� �����, ��� ��� ������ ������� �����������. ������ ����� ��������� ��� ������ ������� ifconfig(8) (������ � OpenBSD). ����� ����, ��������� ������ ��������� ����� �������������:
egress
, �������
�������� ��� ����������, ����� ������� ��������
�������� �� ���������.
ppp
��� carp
).
af
inet
��� ������� IPv4 � inet6
��� ������� IPv6. ������
�������� ������ ����� ���������� ��������� �������� ��
��������� � ������� �������.
protocol
�������� ������������� ������. ��������� ��������:
tcp
udp
icmp
/etc/protocols
.
src_addr
, dst_addr
����� ��������� ��� ���������� ������. ��������� ��������:
/netmask
(�������� /24
). �� ���� �������
������̣���� �� ������ �����������, ����� ���������
������ ������� �����, � ���������� ���� CIDR �����
��������� � ������ �������.
(...)
.
������ ������� ����� ������������� �������� ���
����� ������ ������̣����� �� �����������. ���
������� ��� DHCP ��������.
��� �������� ����������, �� ������� �ģ� ���� �� ��������� �������������:
:network
:broadcast
:peer
����� ����, �� ������ ���������� ��� �� ����� ��
������������� ���� �������������, �����
��������� ����������� :0
, ����������� �� ��,
��� ��� �� ���������� ������, �.�.
�������������� ������, ������ ����� �������� �
�������� ���������� (��. �����̚6.15, «������ ��� � ����� ������������� ��� ������� ������ �������� ����������»). ��������: fxp0:network:0
.
!
.
any
,
���������� ��� ������.
all
,
������� �������� ������������ ����������� from any to any
.
src_port
, dst_port
���� ��������� ��� ���������� � ��������� ������������� ������. �������� ��������� ��������:
/etc/services
.
��������� ������ � ����������� ��������� ����������:
!=
<
>
<=
>=
><
<>
:
��������� ��� ��������� �������� (���������
��� ���������). ��� ���� <>
� ><
�� ��������
��������� � ��������, � :
��������.
tcp_flags
proto�tcp
. ����� ��������
��� flags�check/mask
.
mask
�— ������
����������� ������, check
�— ������
������, ������� ������ ���� ��������. ��������
��������� flags�S/SA
��������, ��� �� ���� ����� � �������� �������� ����
ACK, � ����ޣ� ���� SYN, � ��������� ����� ��� ��
����������.
state
��������� ����������� �� ������ �������� ���������� � ��������� ����������. ��������� ��������:
keep state
modulate state
synproxy state
keep�state
� modulate�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>
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
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>)
tag <string>
tagged <string>
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%
������������� �������� ��� ��������� �����������ך— ������ �������� «default deny», �.�. �� ��������� ����������� ��� ������, � ����� ���������� ��������� �����ۣ���� ������. ��� �������� �������� «default deny» ���� ������� ��������� ������ ��� �������:
block in all block out all
��� ������� ��������� ���� ������ �� ���� ����������� ��� ����������� �� �����������.
������ ��� ���� ���� ��������� ����������� �������, ����� �� �� ��� ������������ ���������. ����� ����������� ����� �������� ��� ������ ������ ��������� � ����������, ������ ��������� � ����������, ���������. ������� ������ ���� ��������� ��������, ��������� ��� ��������, ��� ����, ����� ����� ���������� �������� ������ ������ ������.
��������:
# ���������� ������ �� ��������� ���� (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
��� ���� �������� ����, ������ �������� ����� ��� �������
�� ������ �� �����. �����, ������� ��������� �������� ���
���������� (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
����� ��� ������� �������� �������� � ������������ �������, � ����� ���� � ���. � ����������� �� ����, ����� ������� �������� ���� �� ������.
���� �� ������ ������������ ��������� ��������— ������������ ��������� ���������� («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-bound
� floating
, ���������� ���������������
� ��������. ��� ����� �� �� ��������, ��� � ��������
��������� �������� state-policy
.
������:
pass out on fxp0 proto { tcp, udp, icmp } from any \ to any modulate state (if-bound)
��� ������� ������, ��� ����� ����� ��������������� ������ �
������� ��������� ������ ���� �� �ģ� ����� ��������� fxp0
.
������� nat
, binat
� rdr
���� ������� ������ �
������� ���������.
���-�� ����� ��������, ��� ��� ��������� UDP ������ ������
������ � ������� ���������, ��� ��� ���
«stateless» ��������. ������ �������� ������
����� ����������� ��� ���������. �������� �� ����������
«����������» ������, �������� ������ ������ ��
�������� �� ��������� ��������� � ������� ������ ��������� �
����������. �� ���������� �������� ������� ���������
��������� �� ��������������� ������. �������� �������� �����
������ � ������� «�����»
pf.conf
, ��. �����̚C.2.2.1, «����� � �������� �������»
����� ������������ ��������� ����� ��� ���������� ����������
������� � ������� ���������, ��������� ��� ������ ������
keep�state
, modulate�state
��� synproxy�state
. ��� ������ ����
�����:
max
numbersource-track
��� ����� ���� ����������� ����������� ���������� ������� � ������� ��������� � �����ޣ�� �� ������ ����� ���������. ��������� ������� �����:
source-track�rule
�—
������������ ���������� ������� � �������
��������� ��������� ������ �������� ��������������
������� max-src-nodes
�
max-src-states
,
��������� � ���� �������. �ޣ����� ��������� ��
����������, � ���������.
source-track�global
�—
�� �� ��� � � ���������� ������, �� �ޣ�����
������� ���������. ��� ���� ������ ������� �����
����� ���� ������� max-src-nodes
� max-src-states
, ������
�ޣ����� ����� ������ ��� ���� ������.
����� ���������� ������� ����������, ��� �������
�������������� ���������� �������� ���������� �����
� ������� ���������, �������������� ��� ������ �����
src-nodes
. (��. �����̚C.2.2.1, «����� � �������� �������»)
max-src-nodes
numbersource-track
����� max-src-nodes
������������
���������� IP-������� � ������� ����� ������������
������� ����������.
max-src-states
numbersource-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)
��� ������� �������� ���������:
��������� ����������� ����� ������ ��� TCP ���������� ��������� ������� ����������� (��. �����̚B.1.4.3.2, «�������� ���������� TCP, ������� �����������»):
max-src-conn
numbermax-src-conn-rate
number / interval
��� ����� ������������� �������� ����� state-track rule
� �� ���������� �
state-track global
.
� ���������� � ������� ������� ����� ����������� ����� ����������� �����, ��� «���������» «�������������».
overload
<table>flash
[global]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)
��� ������� ������ ���������:
block
).
��� �������� ���������� 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
� ������� �������� ������ ��������� ������� ����������� � �������� (��. �����̚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�state
� modulate�state
.
![]() | ��������� |
---|---|
SYN proxy ����������, ���� �������� ������ �������� �� �����. (��. bridge.) |
IP-������ǚ— �������� ��������� ������� � ��������� IP ������ (��. spoofing).
�������� ������ ����� ������������ ������ �� �������� ���
������ ������ ������������ � ��������� ����� antispoof
:
antispoof [log] [quick] for interface [af]
log
quick
interface
af
inet
� inet6
.
������:
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
��� ������� �������� ���������:
![]() | ��������� |
---|---|
������� set skip on lo0 antispoof for fxp0 inet |
![]() | ��������� |
---|---|
������������� ������� block drop in on ! fxp0 inet all block drop in inet all � ����� ������������� ���� �������� ������ �� ���� �����������. |
������� � 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. |
�������� ������ �������� ������������ ���������� �� �����
������������ ������� ��� ��������� 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 (���������� ����� Sharp � Linux'��) 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
��������
����� �� ������� ��� �������������� ��������� �������
�����������.
![]() | ��������� |
---|---|
|
�� ��������� �������� ������ ����������� IP ������ �
������������� �������, ��� ����������� ������ ��������
���������� ������ ��� ����� ������������ �������, ��������
nmap(1). ���� � ��� ���� ����������
����������� � ����������� ������ �������, ��������
multicast ��� IGMP, ����������� ����� allow-opts
:
pass in quick on fxp0 all allow-opts
���� �����ģ� ������� ������ ����������������� ����� ��� ����������� ����� ��������� ���������� ����� � ����������. ����� ��������� ������ ������� ����������, 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
���� ���������� ������� NAT ������� � ���������: NAT.
����� ������ �� ���������� ���� �������� ������� IP ����� � �������� � ���� ������ ����������� ��������� IP ����� �� ����� �����, � ��� ��, ��� �������������, ����������� ����� ����� ��������� � ������� TCP � UDP. �������� ������ � ������� ���������.
�������� ������ ��������� � ������� ��������� � � ���� ������������� ����������� �������� ��������������.
�� ���������� ������, �� ������� �� ����� � ������������� NAT. �ӣ ���������� ���������. ��� ���������� ������ NAT ��� ������ ����, � ������� ������ ������ �� ����� � ���������� � �������, ��� ���������� ������� ������. ���������� NAT ����� ������ �� ��������� ���������.
������ ������������ ���������� �������� ����� ������ �
����� ��������� ��� ��������� � ����������� �� ������
������� ��� ����������. ������������
���������ڗ ���� � ������� NAT ����������
�������� ����� pass
, �� � ����
������ ����� �� ����� ���������� ����������.
���������� �������������� �� ����������. ������� ������� ������ ��� ����������������� ������.
��������� 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
�������������� ��������� ������� 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
pass
log
pass
, ������ ��������� � ������
��� ������ pflogd(8). � ����� �
������ �������� ������ ������ �����, ��� �������������
������������� ��� ������ ����������� log (all)
.
interface
af
inet
��� ������� IPv4 � inet6
��� ������� IPv6. ������
�������� ������ ����� ���������� ��������� �������� ��
��������� � ������� �������.
src_addr
, dst_addr
����� ��������� ��� ���������� ������. ��������� ��������:
/netmask
(�������� /24
). �� ���� �������
������̣���� �� ������ �����������, �����
��������� ������ ������� �����, � ���������� ����
CIDR ����� ��������� � ������ �������.
(...)
.
������ ������� ����� ������������� �������� ���
����� ������ ������̣����� �� �����������. ���
����� ���� �������, ��������, ��� DHCP ��������.
��� �������� ����������, �� ������� �ģ� ���� �� ��������� �������������:
:network
:broadcast
:peer
����� ����, �� ������ ���������� ��� �� ����� ��
������������� ���� �������������, �����
��������� ����������� :0
, ����������� �� ��,
��� ��� �� ���������� ������, �.�.
�������������� ������, ������ ����� �������� �
�������� ���������� (��. �����̚6.15, «������ ��� � ����� ������������� ��� ������� ������ �������� ����������»). ��������: fxp0:network:0
.
!
.
any
,
���������� ��� ������.
all
,
������� �������� ������������ ����������� from any to any
.
src_port
, dst_port
���� ��������� ��� ���������� � ��������� ������������� ������. �������� ��������� ��������:
/etc/services
.
��������� ������ � ����������� ��������� ����������:
!=
<
>
<=
>=
><
<>
:
��������� ��� ��������� �������� (���������
��� ���������). ��� ���� <>
� ><
�� ��������
��������� � ��������, � :
��������.
ext_addr
src_addr
� dst_addr
, ����� ������,
��������� � ������� !
�
��������� ����� any
. ������
������������ ����������� :broadcast
.
pool_type
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.
������������ ����� ����� ������� 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
����� ������� ���������� �� ���������� ��� ������
��������� ����� 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
����� ����������� � ���������
binat
� rdr
.
����� ������� ��������� ���������� ������������ 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
���� ��ޣ� (������ �����) �������� ���������:
���� � ��� �������� 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.20rdr on tl0 proto tcp from any to any port 5000:5500 -> \ 192.168.1.20 port 6000
rdr on tl0 proto tcp from any to any port 5000:5500 -> \ 192.168.1.20 port 7000:*
![]()
��������������� ������, ��� � � ������ � NAT, ������������ �� ������� ������� � ����� ���� ��� �������, ��� � ���������.
������������ ����������: ���� � ������� rdr
������������ �������� ����� pass
. � ���� ������ ����� ��
������������ � ������. �� ������ �������, ��� ��� �����
�������� ������ �������� ��� �������, � ����� �� �������
�������������� ����������, � � ������ ������������� ��������
����� pass
� keep state
. ������, ���� �� ������
������������ �����-�� ������ ����������� ��������� �������,
�������� modulate state
��� synproxy state
, ��� �����
����������� ��� ��������, �.�. rdr
pass
� ���� ������ �� ��������.
����� ����, ������ � ����, ��� �� ������ ������ ���������� ����� ����������.
���������� ��������� ��������:
������� ���������������:
rdr on tl0 proto tcp from 192.0.2.1 to 24.65.1.13 port 80 \ -> 192.168.1.5 port 8000
��� ������ ����� �����������:
��� ������ ����� ����������:
������� ������� ������ ��� ����� �ģ� �� ������ 192.168.1.5 �� ���� 8000
�������� �������� ��������� � ����������� ������� � ����������� ������������ �������. ��������, ���� � ��� �� ���������� ���� ��������� web-������ � �� ���������� �� ���� ������ �� ��������, �� ������������� ����� ��������� ���������� � ������ web-������� ��� CGI ��������, �������� ������ � web-������� �, ����� �������, ��������� � ����ݣ���� ���� ��������� ����.
������� ���� ������������� �������� �������� ����� ��ԣ� ���������� ������������������ ���� DMZ (��. DMZ).
��������������� ����� ������������ ��� �������������� ������� ������� ������� � ����������� �������:
server = 192.168.1.40 rdr on $ext_if proto tcp from any to $ext_if port 80 -> $server \ port 80
������ ��� ������������ ������ ��������������� �� ����������
���� ��� �� ��������. ���� � ���, ��� ������ �� ����������
���� �� �������� ����� ������� ��������� ����� ($ext_if
� �������) � ������ ��
������������ ����������.
���������� ������� rdr
������� ��
������� ��������: ����� �������� ����� ���������� ���������,
��� �������� ����� ���������� � �� ������������ �� ������,
������ ��������� ����� ��� ���� �� ������������ � �������
������ ����� ������� ��������������� ������� ����� ����.
������ ��� ���� �ģ� ������ �� �����, � �� �� �������. �����
�������, ���������� ��� � �� ����� �����������.
� �ӣ ���� ���������� �� ���������� ���� ������ ������ ��� �� ��� �� ����� �� ������� � ���, ����� ��� ������� �ӣ ���� ���������. ���������� ��������� �������� ������� ���� ��������.
������ DNS ����� ��������� ���, ��� �� ����� ������ ������ ������ � ������ ����. ����� ������� ���, ����� ��������� ������� ������ �� ������ ���������������, ��� ������ �����. ����� �������, � ���� ��, ������� �������� �� ����.
����� ����������� ������ � ��������� ���� (��. ��� �� DMZ) � �������� ����� ������� ��������� � ����.
����� ���������� ������������� 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
� �������, � ���������� � �������� 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 ���� �����
������ ������, ���������� ���������� �����������, ���
�������������� ������ ����.
������ ������������ � ��������� ������� ����������� � ����� ������ ������������ �����-������ �� ���������� ������� ������ ����������.
�������� ������ ������������� ��������� ������� ���������
����������������� �����. ������� �������� ��������
������������� ������� �
��������. �������� ���� � ����������
pf.conf(5)
������ ����� � ��������� �
���� ������� �������� �������� ����� � ����������� �� � ������
�������, ����� ������� ������������� �� ������ �������
��������� ����� pf.conf(5)
. � ����� �����
�������, ��� ��� ����� �������, ��� ����� ������������
��������� �����������.
������� ������� ��� ��� ��������� ������������ ��������
����� ������ �ͣ� ����������� � �������. ���� �������� 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 }"
������ ����� ������������ ������ �ӣ ����� �������� ��-��������.
��������� 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
�������� ������ �������� ������ � ���� ����� ���������� �����������. ��� ������������� ������ ������� ������� �������� ���� � ������ �������������� ������-�� ������̣����� �����.
��� ����������� �������� ������������� �� ��������� ������, ������� ������ ��� �������:
block in all block out all
��� ����� ��������� ��
block all
����� ����������� �� �������, �������� ������ �������, ��� ������ ������� � ��� �������.
���������� ����� �� ������ from any to
any
� all
, ��������:
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
, �� ��� ������������ ��
����� �������� ����� ������� ������� ��������, � �� �����
��������� ������ �� ������� �������� �������� ������ ���
������������ ����������.
������� ���������� �������� ���� � ����������� ������� �����. ��������, ��������� �������:
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
������ ������� �������� ���� ����� ��������.
����� � 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/etc/pf.os
.
set limit
option value���������� ������ ��� ��������� �����:
frags
�—
������������ ���������� ������� � ���� ���������� ��
������������
������� (scrub). �� ����������—
100
.
src-nodes
�—
������������ ���������� ������� � ���� ���������� ��
������������ ��������� IP �������. (��� ������������
��������� � ��������� �������
sticky-address
�
source-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
interfaceset 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
0
.
proto.modifier
����� � ������� �������� � ������� ���������
�������� ������ � ��������. �����
proto
����� ����
tcp
, udp
,
icmp
��� ���-�� (�����
other
), �
modifier
��������� �� ���������
��������. ����������:
TCP:
tcp.first
tcp.opening
tcp.established
tcp.closing
tcp.finwait
tcp.closed
UDP:
udp.first
udp.single
udp.multiple
ICMP:
icmp.first
icmp.error
������ ��������� �������������� ��� �
UDP:
other.first
,
other.single
,
other.multiple
set adaptive.start
valueadaptive.end
-
����������_�������_�_�������_���������) /
(adaptive.end
-
adaptive.start
)
set adaptive.end
value
������: ����� � 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 ������.
������������ ������� ����� ��� ����, ����� ��������� ��������̣������ � ��� ���� ������������ �����. ����� ����, ��� ������������ ���������� ������ ����������������� ������, ���������� ������ ������������ ������ �� ���������� ���� ���� � ������������� TCP ������ � ����������� ���������� ������. ���������� ��������� �������� ���:
scrub in all
��� �������� � ������������ ����� ��������� ������� �� ���� �����������.
���� �� ��������� ������ ��� ���������������
�����������ɚ— ������������� NFS. ��������� ��
OpenBSD ��������� ���������� ��������
�����ٚ— �����������������, �� � ������������
����� «�����������������», ������� ������
������������� �������� �������� ��� ������������. ��� ��������
����� ��������� ��� ������������� �����
no-df
. ������ ������� ����� �������� � ���,
��� ��������� ��������������������� ������� ���� �����������
�������� �������� � ���������� ��������������. �� ����
��������� �������, ����� �������� ������ ���������
��������, ������������ ������� ������ ����������.
��������� ��������� scrub
������ ����������
��������� ������ ���������� (��. �����̚C.2.1.4, «���������� �������»). ��� � � ������ � NAT
�����������, ������ ������� ����������.
����� ���������� scrub
����� �����������
�������� ����� no
, ����� ��������� ������ ��
���������������.
Scrub ����� ��������� �����:
no-df
random-id
.
random-id
min-ttl
nummax-mss
numfragment reassemble
fragment crop
fragment crop
, �����ڗ
fragment drop-ovl
. � ����� ������� ������
�� �������������� ��� � ������ fragment
reassemble
.
fragment drop-ovl
reassemble tcp
������������ ���������� TCP �� ������ ������� ���������.
��� ������������� ������ ����� ������ ���������
����������� in/out
.
�������������� ��������� ������������:
������:
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
![]() | ��������� |
---|---|
��� ��� ������� ��������� ��� ����� �� ������ ���� ���������� ��������. ����� ��� �������� ��������� ������������, ������� � ���� ����������� ����� anchor. ���� ���, �� ��������� ������Ě— �����. ����� �������� �����: ����ؚ— ��� ����� ���� ������������ �������� ������ � ������������ ����� ��� ��� ���������. ������ ����� ����� �������� ������� �� �������� ����������� �������� ���������. ������ ������ «�����» ������� ����� �������� ������, � �������� ������ ������ ������� «����������� �������� ������». � �������� ���� ����� � ������ ����������. |
�������� � ������� ������� ������ �������� ������ ����� ������������ ���������. ���� ������� ����� ������������ ��� ������������ ����� �� ���� ������� IP-�������, �� ��������� ������ ����� ������������ ��� ������������� �������������������� �����������. � �� ������� ����� ������ ������ ������ �������, nat, binat � rdr.
��������� ������ ����� ��������� ��� ������ «������»,�— anchor ���������� ������ ���� anchor'��:
anchor
name�— ����������� ���
������� ������� ��
������ name;
binat-anchor
name�— ����������� ���
������� binat ���������� ��
������ name;
nat-anchor
name�— ����������� ���
������� nat ���������� ��
������ name;
rdr-anchor
name�— ����������� ���
������� ��������������� ��
������ name;
��������� ����� ���� ���������� � �������� ���� ����� ��
�������. ������� anchor �������������� � ��� �����, ��� ���
����������. ��������, ������� anchor
�
�������� ���������������� ����� ������� ��������, ���������
�������� ��������� ������� ����� ������, ������ ���������
����������� � ������ ��������� ��� ������ ���������
load�anchor
�������� ��� ���������.
����������� ����Қ— ��� ������ ������ ����������, �/��� ������ ����������, ������� ���� ��������� ���. ����� �������� ������ ������������ ����� � ������� ������ ������, �� ���������� �������� ���� ���������� ������ ����������� � ����.
������:
ext_if = "fxp0" block on $ext_if all pass out on $ext_if all keep state anchor goodguys
���� ����� ������ ������������� �� ��������� ��������������
�������� �� ���������� fxp0
���
����� ��������� � ���������� �������. ����������� ����
��������� ������ � ������������ ����������� ����� ������
goodguys. ����� ����� ���� ������� � ��������� �����
��������:
load
�������� ������ ��������� 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). ����� ������������ ��� ������ �� �������� �� ������ ������������ � ���� ������ ������.
������� 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, � ���� ����������� ��������� ��� ���������� �����.
���������� ������������ �������� ������ �������������� ��� ������ ������� pfctl(8). ��� ��������� ������� � ��������� ������� � ����� ��� ������������ �������� ������ ������.
������� ������ ������ �� ������ ssh
:
#
pfctl -a ssh -s rules
�������� ����� ������ ssh
:
#
pfctl -a ssh -F rules
��������� ���-�� � �������, ������ ��������� ��� �� ���������. ��� ������ � ����, ������ ���������� ������ ��������� � ������� � ����, ����� ��� ����� ���������� ������������ ��������, ��� ���� ��� ������, ����� ������ ������ � � ����� ������� ������������. ��������� ������� ��������� ������� ����� ������� ������� �� ������������������ ����. � ��������� ������, ������ ssh ������ �������������� � ������ �������, ��� ��� ���� �������� ����� ������������ � ���������. ��� ������� ������� � ssh-������� ��������� ����������� �����, �� ������ �������� �� ftp �������� �������� � ��������� ������. ��� ����� ��������� � ������, ����� ������ ������������ ������� ���������� ftp �������? ������ ssh ����������� � �������, � �� � ������ ������������� � ������ ������ ������ � � ���������� ssh ������ ����� ������ ����������. ��������� ��������� ����������� �������� ����� ��������� ������������ ���������� ����������� ����� ���������� ������������, �������������� � �������.
�������� ��������, ��� ����������� ������� ����� ����� ������ ��� ��������� ����������, ������ ��� ��� ������ ����� ����� �� �������� ��������� � ��� ��� ������ ���-���� ������, ��� ��� ������ ����������� ������ ���� ��� ������������. ������������ �������� ���� �������� ����� ����� ����������� ������� �� ������� �������������� ��� ��������� ����������� ������� �� ���������� ����������, ���� ���� ��� �������� ������� ���������������.
������������� ���������� ��, ��� �������������� ������� � ���������� ������� ��������� �������. �� ��������� � OpenBSD � �������� ������������ ������������ FIFO, �������. ������� ţ ������ ����� ����Ԛ— ������ ��ۣ̚— ������ �����. ������������� ����� ����������� � ����� �������. ��� ���������� ������������� ������� ������� ����� �������������. ��� ������� �������� ��� tail-drop (������ ������, ��� � �������).
���� � ������ ������������. OpenBSD (� FreeBSD) ������������ �ݣ ��� ������������:
� �������� ������������ �� ������� (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.
������������ ������� (PRIQ) ��������� �� ������� ����������, ������ ��������� �������� �������� ������ʚ— ������ ��������� �������� �������. ������ ������������ �������� ������� � ��������� ����� ���������� �����������, � �� ��� ��� �������� �������. ��������:
Root Queue (2Mbps) Queue A (priority 1) Queue B (priority 2) Queue C (priority 3)
���������� ����������� �������� ������� ���������� ��� 2�Mbps, ������ ���� ��������.
��� ������������� PRIQ �� ������ ����� ��������� ����������� �������, ��� ��� ��� �������������� ������ �� ����������� � ���� ������ � ������� ����������� ���ͣ� ���� �����, ������ ������������� ������� � ������ ����������� ����� �������������.
������� ������̣���� �� ����������� ������������� � ������������� �����, ������ ������� ����� ����� �������. ������ ������� ����� ����� ���� ��������� � ���� ������ �����������. ���� ��� ������� ����� �� CBQ. �������� ������� HFSC �� CBQ � ���, ��� ��� ��������� �������� ������������ �������� � ���������� ����������� �������.
� CBQ ������������ �������� ������� ��� ������ �����������. ���� �� �������� «������ �������» (����������� ������� �� �������), �� ��� ����� ��������� ������. ������������ ������ ������� �������� ��� ������ ����� ������� ������� � ���, ����� ��������� ������ �����������.
� HFSC ������ ������� ������� �� ���� �������� ��������:
�������������� ���������� � HFSC ����� ���� ������� �� ������ http://www.cs.cmu.edu/~hzhang/HFSC/main.html.
��������� ������ ����������� (Random Early Detection, RED)�— ��� �������� ����������� ���������� ������. ��� ����� �������� �������������� ������������ �������. �������� ��� ��ԣ� ������������ ��������� ������� ����� ������� � ����������� � ������������ ��������. ���� ����������� ����� �� ��������Ԛ— ��� ������ ������������. ���� ��������� ������������ ����ǚ— ��� ������ �������������. � ���������� ������ ������������� � ������̣���� ������������, ��������� �� ������� �������. ��� ����� � ������������� �����՚— ��� ���� �����������. ������ ��� ������������ ���������� ��������� ������� �� ������ ������. ��� ������� ������ ����������� ���������� �������, ��� ���� ����������� ������ �� �ţ ������.
RED ������ �������, ��� ��� ��������� �������� ��������, ���������� «���������� ��������������», ��� ����������� � ���, ��� ����� ��������� ������������ ��-�� ������������ ������������� ������� � ������ ������. ��������, ���� ���������� ���������� �� ��������������, ������������� 10 ������������� ������ ftp � ����� ��������� ������ �� ����������� ��� ���� ������, ����� ���������� ����������� ����� ���������. RED ��������� �������� �����, ������� ������ �� ������� ������ ������ ��������� �������. ��������� ������ ���������� ������ ������ ����������� ����� ������� ���� �� ������ ������, �� ����������� ������������� ���������� �������� � ������� ������ ������� �� ����������. ����� ����, RED ��������� ���������� �������� ������� �������, ��� ��� �������� ����������� ������ �� ������������ �������.
RED ������ �������������� ������ �����, ����� ������������ �������� �������� ����������� �� ���������� ���������� ����. � ����������� ������� ��� ��������, ��� RED ������ ����������� ������ � �������� TCP, � �� � �������� UDP ��� ICMP.
��������� ���������� � RED ��������� � References on RED.
����� ����������� � ���������� (ECN) �������� ��������� � RED � ����������� ��� ����������� ���� ��������� ������ � ���������� ����. �������� ��� ����������� RED ���������� ���� � ��������� ������, ������ ����, ����� ��������� �����. ���� ���̣���� ���� ������������ ECN � ������ ����� ECE � CWR, �� �� �������� ������� ��������� ������ (��. ��������B.3, «����� TCP», [RFC-3168]).
������� � OpenBSD�3.0 Alternate Queueing (ALTQ) ���� ������ �������� �������, � � ������ OpenBSD�3.3 ALTQ ��� ������������ � �������� ������ �, �������������, ���������� ������ � ��� � � FreeBSD. ���������� ALTQ � OpenBSD ������������ ������������ CBQ PRIQ � RED ������ � ECN.
������� ��������������� � �����
/etc/pf.conf(5)
. ���� ��� ����
��������, ������� ������������ ��� ����������������
��������:
altq on
queue
��������� ��������� altq
:
altq on interface scheduler bandwidth bw qlimit qlim \ tbrsize size queue { queue_list }
interface
scheduler
cbq
� priq
. �� ���������� � ���� ������
������� ����� ���������� ������ ���� �����������.
bw
qlim
size
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
pri
qlim
scheduler
sched_options
�������������� ����� ��� ���������� ��������������:
default
red
rio
ecn
borrow
queue_list
��������� ��� ����� ����������� ������ ��� ������� ���� 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.
��� ����������� ������� � ������� ������������ �������� ����� 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
����������� � ��������,
������������� �������� ������.
[ Alice ] [ Charlie ] | | ADSL ---+-----+-------+------ dc0 [ OpenBSD ] fxp0 -------- ( Internet ) | [ Bob ]
� ���� ������� OpenBSD ������������ ��� ���� � �������� ��� ��������� �������� ���� � ����� �������� ���������. �� ����� �������� NAT � ���������� �������. ����� � �������� �������������� �� ADSL � �������� ��������� 2Mbps � ��������� 640Kbps.
��� �������� ��������� ��������� �������:
���� ������������ �������, ����������� ��� ��������.
�������� ��������, ��� � 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
( 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:
���� ������������ �������, ����������� ��� ��������.
�������� ��������, ��� � 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
�������� ����� ���������� �������� ������������ ����� ��� ��
���� �������, ������������ ������� �������������. �������� ���
����� ���� ������ � �������� ���������������, ���������� �
������ ��� ����� ���������� � ������ ���������� route-to
, reply-to
� dup-to
.
���������� ������ ������� ������������� �������� �����:
bitmask
random
source-hash
source-hash
� �����������������
������� ��� ��� ������. �� ���������,
pfctl(8) ���������� ��������� ���� ���
������ �������� ������ ������.
round-robin
�� ����������� ������ round-robin
,
��� ������� ������ ���� ������̣� ��� ���� �������
CIDR. � ������ round-robin
������������ ����������
������� �� �������.
����� sticky-address
(��������
«������ �����») ����� �������������� � ������ random
� round-robin
��� �������� �����������
������ ������ � ���� �� ������ ��������� � ����� ����.
��� ������� ����� ������������ ��� ���������� ������� � �������� 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
.
���� ������� ����� ����� �������������� ��� ������������ �������� �������� �����������. ��� �������, �������� ����������� �� 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"), �� ��������� ���������� �������� ���� �� ������, ����� ���������� ���������� �������.
���� ������� ����� �������������� ��� ������������ ��������
����� ����� � ����� �������� �������� � �������������� �����
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
������������ ������ך— ������ �������� ����� ���������� ��������������� ��� ����������� ������������� � �������� �������� � �������� ���������� � ����������. ������������ ��������� ������� «�������» ����� ������������, � ��� �� �������� ��������� ��� �� ����� ��������� ��������� ����������. ����� ���������� ��������� ������� �� ����������, ���������� �� ��������, � ����������, ���������� �� ���������.
��� ���������� ������� ������������ �������� ����� 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
$dstaddr
$srcport
$dstport
$proto
$nr
��� ������� ������������ �� ����� ��������, � �� �� ����� ������.
������������ ����������� ��������� ��������:
tag
.
���������� ��������� ������:
pass in on $int_if tag INT_NET keep statepass in quick on $int_if proto tcp to port 80 tag INT_NET_HTTP keep state
pass in quick on $int_if from 192.168.1.5 keep state
![]()
� �������� nat, rdr � binat ���� ����� ������ ������ ���
������ ��������� ����� tag
.
��� �������� ������������� �������� ������������ ��������
����� 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
.
���������� ������� �� ������ ������� ��������� ���������� �� ���������� �� ������ ������. � ��������� ��������������� �������, �� ������� ��������� ��� ������� ������ ���� ��������, � ��������� �����ݣ�. ������ ���������������� ������ ������� �� ������ ������������ ��������ך— IP ������ ���������/����������, ��������� � �.�. ���������� ��������� ������:
��������, ��� �������� ���������� ���� ������ ������ ����� ����������. � ������� ������� ������� ������� ������������ ��� ������ ��������.
������� ���������� � ����������:
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
���� ������ �������� ��� ���� �� ��������� ������ (�
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
�������������� � �������� ������� �������������� ��� ������
������ 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 ���� ���� ������ ������� ������� ����������. ����������� ��������� ���� � ��������������� ����� � ��� ������� �������. ����� �������� � ������� �� ���� «�������� ������»�— � Σ� ���� �������� ��������� ������, ��� �� ���������� ������ ������������ �����������, � �������� ����������� ң���. � ��� ������ �� ���� �� ������ (������ ��-�� �������...). ��� ������ ������ �����, ���� �� ��� ���ģ� � ��������.
������ ����������� ������ � ������ ��������� � ���, ��� ����� ��� ���ۣ� ��������� �����. ����� ������� ���: ���, ����� �������� ���-�� � ���-��.
�������� ������ ���ģ� � ������ ���� ������.
��� �������������� ������ ���� ��������� �������� ����� log
� ������� ����������, nat ��� rdr.
��������, ��� � ������� ������� ������ ������� �������
������ ��� �������������� �������— ������
�������������� ���� ��������� block
���� pass
.
��������� ����� log
����� ��������
��������� �����:
all
keep state
.
user
to <interface>
����� ����������� � ������� ������� ����� ��������� �����
log
. ��������� ����� ����� �������
����� ������� ��� ����� ������:
pass in log (all) on $ext_if inet proto tcp to $ext_if port 22 keep state
��� ������� �������� � ������ ��� �������� ������, ������ �� 22-� ����.
���������� ���� ���������� pflogd(8) ����� �������� ������, ��� ������ ������ ��� ������ ���������� ��������. �� ������������ ��� ������ �������� tcpdump(1) (��� ������ ���������� ���������������� � ���������� ���������� libpcap, �������� wireshark(1)).
��� ��������� ����������� ����� ��������� �������
#
tcpdump -n -e -ttt -r /var/log/pflog
��� ��������� ������� � ������ ��������� �������:
#
tcpdump -n -e -ttt -i pflog0
![]() | �������� |
---|---|
��� ������ ������� � ����������� ������ verbose
(������������ ������ ����� ����, ������ � ����, ��� pflogd(8) �� ��������� �������� � ������ ������ 96����� ������. � ���� ������ ����� ���������� ����������� ������, ����� ��� ������ telnet(1) ��� ftp(1). |
��������� 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
.
�� ������ ������� ���������� ����� ������ ����������� � ��������� ������� � ���������� ������ ������� �� ������� ���������� ������.
���, �������� ������������� ������ ��� ����� ������������ �� ��������� ������� ��� �� ����������. �ӣ ��� ��� ����������, ��� ��� � 5 ����� ���������� �������� ���� ����� pipe:
#
tcpdump -n -e -ttt -r /var/log/pflog | logger -t pf -p local0.info
��������� HOWTO ��� ����������� ������ ������� ����� logger(1) ������ syslogd(8) ����� ����� �� ����� ������������� �������� �������. � �� �������� ������������� ��� �������� � ������ �����, ��� ��� ������ ţ �������.
��������� ������� ������ ����������� ����� ����������� �������� ������? ��������� ������ ��������� ��� ����� ��� ������������ ���������� � ��������?
�������� ������ �� ��� ������� ���. ��� ��������� ����� ����� ���������� ���������� 486/66 � ����� ������� ������� ���� ISA, ��� ���� ����� ����������� ���������� NAT � �������������� ������ �� 5�Mbps. ��� ������ ����� ����� �� ����� ������� ���� ����� ������� ������ � ����� ������� �������� ������������. ��������� ������� �� ���������� ���� � �������, � ���������� ������� � �������.
������������������ ��������� ������� ������������ ����������� ����������:
keep
state
� quick
��� �����
������������������. ��� ������ ������ ����� ������� ����ģ�
�����, ��� ���� ������������������.
����� ���� ���������� ��� benchmark ��� ��������� �������. Benchmark ��� ����� ������� � ����� ���������� ������ ������� ������ ��.
�������� ������ ���������� �� ��������� ����� ������� �������� � ����� ������� ��������. �����������ɚ— ���� ������������. ��� �� ������ ��� ��� �������.
��������� ������� ������������������ ��������� ������� �������� � ������ ������� ���������� [url://Hartmeier-2006-en], [url://Hartmeier-2006-ru].
FTP ��� ��������, ������� ����������, ����� �������� ��� ��������� � ��� � � ���� ����� �����. ����� � ���������� ������� � �� ���� �� ����, ������� FTP �������������� ��� ������� �� ����������� � ���������� NAT.
���������� ��� ������ ���������������� FTP: ��������� � ��������. ����� ����� ����, ��� ����� ����� ���, � ���� ����� �������� � ����������� �������. ���� �� ������, ����� ���� ������������ ���� ���������, ��� ����� �������������� � ����� �������.
�������� FTP.� ����� ������ �������� ������� ������� � �������� ������, ������ «��ģ� ���� �������»�— ��������� ���������� � �������. ������ �������� ��������� ������� ���� � �������� ��� �������, ��������� ��������� ���������� �� ��������� ���� ������� ��� �������� ������. ����� ��������� ���������� ������ NAT: FTP ������ �������� ������� ���������� � �������, �� ������� �������� NAT, � �� ������ �� �����, ��� ������ � ����� ������������.
��������� FTP.� ��� �������� ������ ������ �������� ��������� ������� ���� � �������� ��� �������. ������ ��������� ���������� �� ��������� ������� ���� �������, � �� ����� ���������� ���������� ������. ����� �������� �� ������ �������� � �� ������ ����������, ��� ��� ���������� ����� ����������� ������ ������ �� ��� ��������� �����. ���� � NAT � ���������� �������, �������� ��� ������� �������, ��� ��� ��� ���������� ���� �� ������� � �������.
��� ������������ ����� ��������� ���������
ftp(1). � ���� ��������
BSD ��� ��������� �� ��������� �������� �
��������� ������. � �������� ����� ţ ����� ��������� �
�������������� ��������� -A
��� ��� ��
����� ������ ��� ������ ������� passive
off
�������� � ����� �� �����������
(� ���������
� ��������� ����� �������� ftp>
passive
on
).
��� ������� ���� �������� 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)
� FreeBSD � NetBSD
���������������� 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.porthifirst
� net.inet.ip.porthilast
.
���� ��������, ��� ������� � ������������� ���������,
���������� � OpenBSD �������� ��������.
�������� ���������, ��� � ������� �� ����� ���������� �
FreeBSD, � ����, ���������, �� �����
������������ ���� ftp/ftpsesame
.
��� ���������������� ��������� ������� � FTP ������� ��
����� ������ ���������� ��������� � ��� ������� �������� �
��������� ������ �� 49151 �� 65535. ���� �������� ������
������������ �� ��������� ��������� FTP ���������
ftpd(8). �������� ������ �����
������������ � FreeBSD ��� ������
���������� ���� net.inet.ip.portrange.first
net.inet.ip.portrange.last
, � �
OpenBSD net.inet.ip.porthifirst
� net.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
� ���� ������ ���������� ������ �������������� 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) ����� ������������ ������.
![]() | ��������� |
---|---|
� FreeBSD � NetBSD
������ ftp-proxy(8) ����� ������������
���� ftp/ftpsesame . ��. �����̚C.5.3, «ftpsesame».
|
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):
���������� �� ��������������������� ������������� ������������� ����� syslogd(8). ��� ��������� �������������� ��������� ��� ����� ����������� ���������� � ��������� ����� ������������ ����������� ������� ���������� �������.
��������� ���������������� authpf(8) ������� � man(1) �������� �� authpf(8).
� ������� ������ ������������ ���������������� ����
/etc/authpf/authpf.conf
. � Σ�
���������� ���������������� �����
authpf(8). ���� ����� �� ����������,
authpf(8) ����� ��������� ������ �����
����� ��������������. ���� �� ����������, �� ����, �����
������������ ���������.
� ���� ����� ����� �������������� ��������� ��� �����:
authpf(8) ���������� � �������� �����
������ ��� ������ ������� anchor
:
nat-anchor "authpf/*" rdr-anchor "authpf/*" binat-anchor "authpf/*" anchor "authpf/*"
�������� ������ �����ģ� � �������� ������ �������� � ��� ����� ���, ��� ��� �����������. ��� ����� ������ ������������ ��� �����. ��������, ���� authpf(8) �� �������� �� ��, ����� ������������ ���������� NAT, �� ��������������� ����� �� �����.
authpf(8) ���������� ������� �� ������
/etc/authpf/users/$USER/authpf.rules
/etc/authpf/authpf.rules
������ ������ ������, ����� ������, ���� ���������� ����— ������������ ������ ����. ����� �������, � ������ ����� ������ ��������� ������� ����������� ��� ����������� ������������ � ��� ����� ���������� ���������� ������� �������� �� ������ �����. ��� ������� ���� ���� ������ ������������, ����� authpf(8) �� ����������.
������� ���������� ����� �� ��� � � �������� �����, ������ ���������� ��� �������:
$user_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
��� ������� ������ �������������� � ��������, ������� ��������� �� ���� ��������������������� �������������.
������������� ����� ��������� ������������
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
.
����� ������������ ������� ����������������� � �������, ��� ����� ���������� �������������� ���������
Hello charlie. You are authenticated from host "64.59.56.140"
��� ��������� ����� ��������� ���������� �� �����
/etc/authpf/authpf.message
.
����� authpf(8) ���������, ��� ���� ������� ��������� ������������. ����� ������������ ������� ���ģ� � ������� ����� ssh(1), authpf(8) ����� ������� � �������� ��������. �� �������� ����� �� ������������ ��� ������������, �������� ������ ������� � �.�.
���� ��� ������� ��������� ������������ authpf(8) � �������� ��������:
login.conf(5)
.
(��. ���������ŚF, /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
����� ����, ��� ������������ ������� ��ۣ� � �������, 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
����� �������� ������ ������������ �� ������
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 allpass 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
pass in quick on $wifi_if inet proto tcp from $wifi_if:network to $wifi_if \ port ssh flags S/SA keep state
pass in quick on $wifi_if inet proto { tcp, udp } from <authpf_users> \ to $dns_servers port domain keep state
anchor "authpf/*" in on $wifi_if
![]()
������� ����� ������. ���, ��� ��� ������:
�������� ���� � ���, ����� ������������� �ӣ � �������
��������� ����, ��������� ��� ��������. ������ �����
�������� �������� ������� ���������, ������ �� ������������
��������� default deny �� ���������� (wi0) ����������. �����
������������ �����������������, ��� ������ �����������
�����ۣ� ��� ������� �� ���������� ���������� �, �����
�������, �������� ������. �������� ����� quick
������������ ��� ����, �����
����������� �� ���� ������� �� ����������� �� �����������
�����������.
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, �� ��� �� ���������� � FreeBSD � NetBSD (�, ������������� � DragonFly�BSD).
IANA �� ��� �� �� �������� ����������� ����� ��������� ��� CARP. ��� �������, �� ���� ���������, � ����������� ��� ��������. ������������ OpenBSD ���������� ��������� ��� ����� 112 (������������� � VRRP). �� �� �������� � ���������
pfsync
.
CARP ��������� ������ ������ ������������ ����� IP �����. ��� ������ ������ ���������� «���������� ������» (redundancy group). ���������� ������ ������������� ����� �����, �����, ����� ţ ������ ����������� «������» � �������� ������ (backup). ������, ��� �� ������, ������� � ������ ������ ����������� ����� ����� IP. �� �������� �� ARP �������, ����ݣ���� � ����� ������. ������ ���� ����� ������������ ����� ��� � ����� «���������� ������».
���� �� �������� ������������� CARP�— ���������� ���������� ������������. ����������� IP �����, ������������� ������, ��������� �������� � �������� �������� �� ���������. ���� ���������� ����������� ����������, IP ����� ��������� � ������, �������� ������ � ������ � ������ ���� ������������.
������-���� ������ ��������� �������� ���������� � ���������
����, ����� �������� ����� �����, ��� �� �ݣ ���. ����
�������� ���� � ������� ���������� ������� �� ��������
����������� �� �������, �� �� ����� ������� �� ����
����������� �������. (����� �����Ϛ— ������� ��
�������� advbase
� advskew
).
� ����� ��������� ���� ����� ���������� ��������� ����� CARP, ��� ��� � ����������, ����������� �������� ������������ Virtual Host ID, �� �������� �������� ������ ����� ������ ����� ������ ���������� ����������.
����� ������������� �������� ���������� ���������� CARP, ������ ������ ����� ���� ���������������� � �������. ������ ����� CARP ���������� ���� ������� � ���� SHA1 HMAC.
CARP ����������� ��� ������ ������������ ��������� �������� ������ (����� 112, ���������� �� ������ģ� IANA) � ��� ����� ��������� ������� � �����������:
pass out on $carp_dev proto carp keep state
����� $carp_dev
�—
���������� ��������� ����� ������� ���������� ����������
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
password
carpdev
advbase
advskew
advbase
.
�� ������ ������� advbase
�
advskew
���������� �����
������� � ������: ��� ������ advbase
, ������� �����
������������ ����, ��� ���� � ���� ���������. ��
��������� 0. ���������� �������� �� 0 �� 254.
state
init
, backup
, master
. �������� ����������� �
FreeBSD.
ipaddress
mask
���������� CARP ����� ��������� ����� sysctl(8). ��� ��������� ���������� ����:
�������� ���� ���������� ���� �������� ��� � OpenBSD, ��� � � FreeBSD:
net.inet.carp.allow
net.inet.carp.preempt
��������� ������� �������� ��� ����������� ������
������ ������ CARP ������� ������
���������� advbase
� advskew
. ����� ����, ���������
���������� �������� �������— ����
���������� ��������� �������, �� ������ ����������� �
����ޣ���� CARP advskew
������������ � 240.
������: ����� ������� ������������� A � �����
������������ � CARP � advskew=0
� ������������� B �
advskew=100
. ���� ������
���������� ���� ���������� � ������, � ��
�������������� A ������ ���� ���������. � ���� ������
advskew
�� A �������������
�� 240 � ����������� ������� ��ң� ������������� B.
�� ��������� ��������� � 0 (���)
net.inet.carp.log
net.inet.carp.arpbalance
�������������� ���������� ����� �������� �� �����������
man(1) �� carp(4)
� �� [url://Sgibnev-CARP-2006].
������ ������������ CARP:
#
sysctl -w net.inet.carp.allow=1![]()
#
ifconfig carp1 create![]()
#
ifconfig carp1 vhid 1 pass mekmitasdigoat carpdev em0 \ advskew 100 10.0.0.1 netmask 255.255.255.0![]()
����� ����������� ��������� ���������� 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
��������� pfsync(4)
������������
��� ���������� �� �������� ��������� ��������� �������. ���
������ ������� tcpdump(8) ����� �������
�� �������� ��������� � ������ ��������� �������. �����
����, pfsync(4)
���������
�������� ���������� �� ���������� � ������� ��������� ��
����. ����� �������, ������ �������� ������� �� ������
������� ����� �������� ��� ���������� � ���� �������. �����
�������, pfsync(4)
���������
�������������� ������� ��������� �� ����.
�� ��������� pfsync(4)
��
�������� � �� �������� ���������� � ��������� ����������.
��� �� ������ ������� �� ��� ������������� ��������, ���
������ tcpdump(8).
����� pfsync(4)
���������������
��� �������� ��� ��������� ����������, �� �������� ���������
ţ ��� ������ multicast ������� � ��������� ����. ���
���������� pfsync(4)
�������� ���
��������������. ��������� �������� ������� � ���, �����:
syncdev
(��. ����).
syncpeer
(��. ����). ��� �����ģ� �
����, ��� ���������� ����� ���������� �� unicast ������.
����� ���� ����������� ������ ����� �������� ��� ������
ipsec(4)
.
��� ������ ����������� pfsync(4)
���� ���������������� �������� ������ ���, ����� �� �����
���� ������ ���������� (pfsync ���������� ���� ��������
�������� ������, ����� 240, ���� ����� ���������� ��
������ģ� IANA):
pass on $sync_if proto pfsync
����� $sync_if
�—
���������, ����� ������� �ģ� ����� �����������.
��������� 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.
������:
#
ifconfig pfsync0 syncdev em1
��� ������� �������� pfsync(4)
��
���������� em1
. ��������� ������
������������ ��� ������ multicast � �������� ���� ������ �
����, �� ������� ������� 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
��������� �������������� �������� ��� �������������
CARP � pfsync(4)
.
� carpN
� pfsyncN
�������� ��������
������������ � ������������� ��� ��� ����� �������������
������� ������� ���������� (��: �����̚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"
������ ������ ����� ��������� ������� � ������ ����� �� ������. ��������, ���� ���������� ������� ��� ���������������� ����� ��� ��� �������. ����� ����������� ��� ��� ������� �� ����� ��������� ���������, ����� ������������ ������ �� ��������.
��� ���� ����� �� ������ ���������� ��������� carp
. ������ ��� ���� ��������
���������� ������� �������� advbase
� advskew
�������� ������ ����������
��� ��������� � ���� �� ��� ������ �� ���� �����������
�������.
#
ifconfig carp1 down
������ ������� ������� � ���, ��� �� ������������ ��������
advbase
� advskew
��� ���� �����������
������� �������� � �������� ������, �� ������ ������ ��
����� ������� �� ������ 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
������ ������� � ���, ����� ��������� ������ carp1
� carp2
�� ������ ������.
��� ������ �������� ��� ���������� ������ «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 �������� ���������� ��
����������� carp1
� carp2
�� ������ ������, ��
��������� �������� ��� carp3
�
carp4
.
����� ������� ��������� ������� ���� ��������� �������:
#
ifconfig -g internal -carpdemote 50$
ifconfig -g internal internal: carp demote count 0
��������� ������� ������, ����� ���
OpenBGPD �
sasyncd(8) ���������� �ޣ����
demotion
��� ����, ����� ����� ��� ���
���������� BGP ������ ��� ����� ��� ��� ����������������
IPSec SA, �������ؚ— �������� �� ����������
��������.
������ ������ �������� �� ����������
����������, �� �� ����������� ���������� carp0
. �������:
pass in on fxp0 inet proto tcp from any to carp0 port 22
���� �� �������� fxp0
�� carp0
������� ����� �������� ��
���, ��� �� ����� ��������.
![]() | ��������� |
---|---|
�� ��������� ���������� �������� CARP
��� ������ ������� proto carp �
������ proto pfsync .
|
� ������ ������� �������� ������ ������������ ��� ���������� � NAT � �������� ���� ��� ��������� �����. ������ ������� � ���, ����� ���������� ������ �� ���������� ���� � ��������, ���������� ������������ ������ � ����������� �� ��������� � ���������� ������ � ����������� web-������� �� ��������.
��������� ����:
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.1, «�������� � ������ � �������� �������� OpenBSD».
���������� ������� ��� ���������� ���������� ������������ � ��������� ������ ������:
ext_if="fxp0" int_if="xl0" tcp_services="{ 22, 113 }" icmp_types="echoreq" comp3="192.168.0.3"
������ ��� ������ ���������� ������� ���������� �����������. ���� ��� ���ģ��� ��������� ���������� � ������ �� ������, ��� ���� ����� �������� ������ ��� ��� �������, ��������� ������� ����� �� �������� ��������������. ������ � ���ף���� ������ ���������� ������ �������� ������ � ���� ICMP ��������� ����������� ������. � ��������� ������ ����� ����� ������ COMP3.
![]() | ��������� |
---|---|
���� ���������� ����������� ����� PPPoE, NAT ����������
������ �������������� �� ���������� tun0 , �� �� fxp0 .
|
��������� ��� ����� ���������� ��������� ������� ��� ������������ ������� � �������� �������������� ��� �������� ����������:
set block-policy return set loginterface $ext_if
������ UNIX-������� ����� ��������� ���������, ����������� ��� ����, ����� ��������� ����� �������� ���� � ������ ��� ������ ������� ���������� ������ ������. ���������� �� ��������� ���������� ����� ��������ؚ— ����� �� ������ ������ ��������.
set skip on lo
![]() | ��������� |
---|---|
� OpenBSDlo
��� ������ ��������� �����������, ������� ��� ���������
������ �������� ���������� ��� �� ���ģ��� �� � ޣ�
���������� ����������. � ��������� ��������,
FreeBSD, NetBSD,
DragonFly�BSD, ��� �����
���������� ��� ����� �������� ��� ������� ��������
���������� lo0 , lo1 � �.�. (������ ����� �� ������
������ �� ����).
|
��� ������ �� ������������ ��������������� ��������� ������������ �������. ������� ������������, ��� ����� ���� ������:
scrub in
��������� ������� ������������ ��� ���������� NAT ���� ���������� ����:
nat on $ext_if from !($ext_if) to any -> ($ext_if)
�� ����� �������� !($ext_if)
��
$int_if
, �� ����� ��� �����
��������� ������� � ����������, ���� �� ������� � ���� �ݣ
���� ���������, ������� ����� �������� � ������ ����������
����.
������� ������ ������ ���������� ����� ������, ��� ����� ��� ����������� �����������.
��� ������ FTP-������, ������� �����:
nat-anchor "ftp-proxy/*"
��-������, ��� ����������� ������� ��������������� ��� ������ 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
��� ������ ���������� �������� 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
». ���������� � ���������� �����������,
����� �������, �������� ������ ���� ����� ���������.
# ������� 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