7
IPsec VPN
139
NAT detection mechanism
To
achieve
NAT
detection,
both
IPsec
peers
send
hashes
of
their
own
IP
addresses
along
with
the
source
UDP
port
used
in
the
IKE
negotiations.
This
information
is
used
to
see
whether
the
IP
address
and
source
port
each
peer
uses
is
the
same
as
that
which
the
other
peer
sees.
If
the
source
address
and
port
have
not
changed,
the
traffic
has
not
undergone
NAT
along
the
way,
and
NAT
traversal
is
not
necessary.
If
the
source
address
and/or
port
has
changed,
then
the
traffic
has
undergone
NAT,
and
NAT
traversal
is
used.
Changing ports
Once
the
IPsec
peers
have
decided
that
NAT
traversal
is
necessary,
the
IKE
negotiation
is
moved
away
from
UDP
port
500
to
port
4500.
This
is
necessary
since
certain
NAT
devices
treat
UDP
packet
on
port
500
differently
from
other
UDP
packets
in
an
effort
to
work
around
the
NAT
problems
with
IKE.
The
problem
is
that
this
special
handling
of
IKE
packets
may
in
fact
break
the
IKE
negotiations,
which
is
why
the
UDP
port
used
by
IKE
has
changed.
UDP encapsulation
Another
problem
that
NAT
traversal
resolves
is
that
the
ESP
protocol
is
an
IP
protocol.
There
is
no
port
information
as
in
TCP
and
UDP,
which
makes
it
impossible
to
have
more
than
one
NAT
client
connected
to
the
same
remote
gateway
at
the
same
time.
Because
of
this,
ESP
packets
are
encapsulated
in
UDP.
ESP
‐
UDP
traffic
is
sent
on
port
4500,
the
same
port
as
IKE
when
NAT
traversal
is
used.
Once
the
port
has
been
changed,
all
following
IKE
communication
is
done
over
port
4500.
Keep
‐
alive
packets
are
also
sent
periodically
to
keep
the
NAT
mapping
alive.
NAT traversal configuration
Most
NAT
traversal
functionality
is
completely
automatic
and
in
the
initiating
gateway
no
special
configuration
is
needed.
However,
for
responding
gateways
two
points
should
be
noted:
•
On
responding
gateways,
the
Remote
Endpoint
field
is
used
as
a
filter
on
the
source
IP
of
received
IKE
packets.
This
should
be
set
to
allow
the
translated
IP
address
of
the
initiator.
•
When
individual
pre
‐
shared
keys
are
used
with
multiple
tunnels
connecting
to
one
remote
gateway
that
are
translated
out
through
the
same
address,
it
is
important
to
make
sure
the
Local
ID
is
unique
for
every
tunnel.
The
Local
ID
can
be
one
of:
•
Auto.
The
local
ID
is
taken
as
the
IP
address
of
the
outgoing
interface.
This
is
the
recommended
setting
unless
the
two
gateways
have
the
same
external
IP
address.
•
IP.
An
IP
address
can
be
manually
entered.
•
DNS.
A
DNS
address
can
be
manually
entered.
•
E
‐
mail.
An
e
‐
address
can
be
manually
entered.