<s>
In	O
computer	B-Architecture
networking	I-Architecture
,	O
port	B-Protocol
forwarding	I-Protocol
or	O
port	B-Protocol
mapping	I-Protocol
is	O
an	O
application	O
of	O
network	B-Protocol
address	I-Protocol
translation	I-Protocol
(	O
NAT	O
)	O
that	O
redirects	O
a	O
communication	O
request	O
from	O
one	O
address	B-Protocol
and	O
port	B-Protocol
number	I-Protocol
combination	O
to	O
another	O
while	O
the	O
packets	B-Protocol
are	O
traversing	O
a	O
network	O
gateway	O
,	O
such	O
as	O
a	O
router	B-Protocol
or	O
firewall	B-Application
.	O
</s>
<s>
This	O
technique	O
is	O
most	O
commonly	O
used	O
to	O
make	O
services	O
on	O
a	O
host	B-Device
residing	O
on	O
a	O
protected	O
or	O
masqueraded	B-Protocol
(	O
internal	O
)	O
network	O
available	O
to	O
hosts	O
on	O
the	O
opposite	O
side	O
of	O
the	O
gateway	O
(	O
external	O
network	O
)	O
,	O
by	O
remapping	O
the	O
destination	O
IP	B-Protocol
address	I-Protocol
and	O
port	B-Protocol
number	I-Protocol
of	O
the	O
communication	O
to	O
an	O
internal	O
host	B-Device
.	O
</s>
<s>
Port	B-Protocol
forwarding	I-Protocol
allows	O
remote	O
computers	O
(	O
for	O
example	O
,	O
computers	O
on	O
the	O
Internet	O
)	O
to	O
connect	O
to	O
a	O
specific	O
computer	O
or	O
service	O
within	O
a	O
private	O
local-area	O
network	O
(	O
LAN	O
)	O
.	O
</s>
<s>
In	O
a	O
typical	O
residential	O
network	O
,	O
nodes	O
obtain	O
Internet	O
access	O
through	O
a	O
DSL	B-Device
or	O
cable	B-Device
modem	I-Device
connected	O
to	O
a	O
router	B-Protocol
or	O
network	B-Protocol
address	I-Protocol
translator	I-Protocol
(	O
NAT/NAPT	O
)	O
.	O
</s>
<s>
Hosts	O
on	O
the	O
private	O
network	O
are	O
connected	O
to	O
an	O
Ethernet	O
switch	O
or	O
communicate	O
via	O
a	O
wireless	B-Architecture
LAN	I-Architecture
.	O
</s>
<s>
The	O
NAT	B-Protocol
device	I-Protocol
's	O
external	O
interface	O
is	O
configured	O
with	O
a	O
public	O
IP	B-Protocol
address	I-Protocol
.	O
</s>
<s>
The	O
computers	O
behind	O
the	O
router	B-Protocol
,	O
on	O
the	O
other	O
hand	O
,	O
are	O
invisible	O
to	O
hosts	O
on	O
the	O
Internet	O
as	O
they	O
each	O
communicate	O
only	O
with	O
a	O
private	O
IP	B-Protocol
address	I-Protocol
.	O
</s>
<s>
When	O
configuring	O
port	B-Protocol
forwarding	I-Protocol
,	O
the	O
network	O
administrator	O
sets	O
aside	O
one	O
port	B-Protocol
number	I-Protocol
on	O
the	O
gateway	O
for	O
the	O
exclusive	O
use	O
of	O
communicating	O
with	O
a	O
service	O
in	O
the	O
private	O
network	O
,	O
located	O
on	O
a	O
specific	O
host	B-Device
.	O
</s>
<s>
External	O
hosts	O
must	O
know	O
this	O
port	B-Protocol
number	I-Protocol
and	O
the	O
address	B-Protocol
of	O
the	O
gateway	O
to	O
communicate	O
with	O
the	O
network-internal	O
service	O
.	O
</s>
<s>
Often	O
,	O
the	O
port	B-Protocol
numbers	I-Protocol
of	O
well-known	O
Internet	O
services	O
,	O
such	O
as	O
port	B-Protocol
number	I-Protocol
80	O
for	O
web	O
services	O
(	O
HTTP	B-Protocol
)	O
,	O
are	O
used	O
in	O
port	B-Protocol
forwarding	I-Protocol
,	O
so	O
that	O
common	O
Internet	O
services	O
may	O
be	O
implemented	O
on	O
hosts	O
within	O
private	O
networks	O
.	O
</s>
<s>
Administrators	O
configure	O
port	B-Protocol
forwarding	I-Protocol
in	O
the	O
gateway	O
's	O
operating	O
system	O
.	O
</s>
<s>
In	O
Linux	B-Application
kernels	O
,	O
this	O
is	O
achieved	O
by	O
packet	B-Protocol
filter	I-Protocol
rules	O
in	O
the	O
iptables	B-Application
or	O
netfilter	B-Application
kernel	O
components	O
.	O
</s>
<s>
BSD	B-Operating_System
and	O
macOS	B-Application
operating	O
systems	O
prior	O
to	O
Yosemite	B-Device
(	O
OS	O
10.10.X	O
)	O
implement	O
it	O
in	O
the	O
Ipfirewall	B-Protocol
(	O
ipfw	B-Protocol
)	O
module	O
while	O
macOS	B-Application
operating	O
systems	O
beginning	O
with	O
Yosemite	B-Device
implement	O
it	O
in	O
the	O
Packet	B-Protocol
Filter	I-Protocol
(	O
pf	B-Protocol
)	O
module	O
.	O
</s>
<s>
When	O
used	O
on	O
gateway	O
devices	O
,	O
a	O
port	B-Protocol
forward	I-Protocol
may	O
be	O
implemented	O
with	O
a	O
single	O
rule	O
to	O
translate	O
the	O
destination	O
address	B-Protocol
and	O
port	O
.	O
</s>
<s>
(	O
On	O
Linux	B-Application
kernels	O
,	O
this	O
is	O
DNAT	O
rule	O
)	O
.	O
</s>
<s>
The	O
source	O
address	B-Protocol
and	O
port	O
are	O
,	O
in	O
this	O
case	O
,	O
left	O
unchanged	O
.	O
</s>
<s>
When	O
used	O
on	O
machines	O
that	O
are	O
not	O
the	O
default	O
gateway	O
of	O
the	O
network	O
,	O
the	O
source	O
address	B-Protocol
must	O
be	O
changed	O
to	O
be	O
the	O
address	B-Protocol
of	O
the	O
translating	O
machine	O
,	O
or	O
packets	B-Protocol
will	O
bypass	O
the	O
translator	O
and	O
the	O
connection	O
will	O
fail	O
.	O
</s>
<s>
When	O
a	O
port	B-Protocol
forward	I-Protocol
is	O
implemented	O
by	O
a	O
proxy	O
process	O
(	O
such	O
as	O
on	O
application	O
layer	O
firewalls	B-Application
,	O
SOCKS	B-Application
based	O
firewalls	B-Application
,	O
or	O
via	O
TCP	O
circuit	O
proxies	O
)	O
,	O
then	O
no	O
packets	B-Protocol
are	O
actually	O
translated	O
,	O
only	O
data	O
is	O
proxied	O
.	O
</s>
<s>
This	O
usually	O
results	O
in	O
the	O
source	O
address	B-Protocol
(	O
and	O
port	B-Protocol
number	I-Protocol
)	O
being	O
changed	O
to	O
that	O
of	O
the	O
proxy	O
machine	O
.	O
</s>
<s>
Usually	O
only	O
one	O
of	O
the	O
private	O
hosts	O
can	O
use	O
a	O
specific	O
forwarded	O
port	O
at	O
one	O
time	O
,	O
but	O
configuration	O
is	O
sometimes	O
possible	O
to	O
differentiate	O
access	O
by	O
the	O
originating	O
host	B-Device
's	O
source	O
address	B-Protocol
.	O
</s>
<s>
Unix-like	O
operating	O
systems	O
sometimes	O
use	O
port	B-Protocol
forwarding	I-Protocol
where	O
port	B-Protocol
numbers	I-Protocol
smaller	O
than	O
1024	O
can	O
only	O
be	O
created	O
by	O
software	O
running	O
as	O
the	O
root	O
user	O
.	O
</s>
<s>
Running	O
with	O
superuser	O
privileges	O
(	O
in	O
order	O
to	O
bind	O
the	O
port	O
)	O
may	O
be	O
a	O
security	O
risk	O
to	O
the	O
host	B-Device
,	O
therefore	O
port	B-Protocol
forwarding	I-Protocol
is	O
used	O
to	O
redirect	O
a	O
low-numbered	O
port	O
to	O
another	O
high-numbered	O
port	O
,	O
so	O
that	O
application	O
software	O
may	O
execute	O
as	O
a	O
common	O
operating	O
system	O
user	O
with	O
reduced	O
privileges	O
.	O
</s>
<s>
The	O
Universal	B-Application
Plug	I-Application
and	I-Application
Play	I-Application
protocol	O
(	O
UPnP	B-Application
)	O
provides	O
a	O
feature	O
to	O
automatically	O
install	O
instances	O
of	O
port	B-Protocol
forwarding	I-Protocol
in	O
residential	O
Internet	O
gateways	O
.	O
</s>
<s>
UPnP	B-Application
defines	O
the	O
Internet	B-Protocol
Gateway	I-Protocol
Device	I-Protocol
Protocol	I-Protocol
(	O
IGD	O
)	O
which	O
is	O
a	O
network	O
service	O
by	O
which	O
an	O
Internet	O
gateway	O
advertises	O
its	O
presence	O
on	O
a	O
private	O
network	O
via	O
the	O
Simple	B-Protocol
Service	I-Protocol
Discovery	I-Protocol
Protocol	I-Protocol
(	O
SSDP	O
)	O
.	O
</s>
<s>
An	O
application	O
that	O
provides	O
an	O
Internet-based	O
service	O
may	O
discover	O
such	O
gateways	O
and	O
use	O
the	O
UPnP	B-Application
IGD	O
protocol	O
to	O
reserve	O
a	O
port	B-Protocol
number	I-Protocol
on	O
the	O
gateway	O
and	O
cause	O
the	O
gateway	O
to	O
forward	O
packets	B-Protocol
to	O
its	O
listening	O
socket	B-Protocol
.	O
</s>
<s>
Port	B-Protocol
forwarding	I-Protocol
can	O
be	O
divided	O
into	O
the	O
following	O
specific	O
types	O
:	O
local	O
,	O
remote	O
,	O
and	O
dynamic	O
port	B-Protocol
forwarding	I-Protocol
.	O
</s>
<s>
Local	O
port	B-Protocol
forwarding	I-Protocol
is	O
the	O
most	O
common	O
type	O
of	O
port	B-Protocol
forwarding	I-Protocol
.	O
</s>
<s>
forward	O
data	O
securely	O
from	O
another	O
client	O
application	O
running	O
on	O
the	O
same	O
computer	O
as	O
a	O
Secure	B-Protocol
Shell	I-Protocol
(	O
SSH	B-Protocol
)	O
client	O
.	O
</s>
<s>
By	O
using	O
local	O
port	B-Protocol
forwarding	I-Protocol
,	O
firewalls	B-Application
that	O
block	O
certain	O
web	O
pages	O
are	O
able	O
to	O
be	O
bypassed	O
.	O
</s>
<s>
Connections	O
from	O
an	O
SSH	B-Protocol
client	O
are	O
forwarded	O
,	O
via	O
an	O
SSH	B-Protocol
server	O
,	O
to	O
the	O
intended	O
destination	O
server	O
.	O
</s>
<s>
The	O
SSH	B-Protocol
server	O
is	O
configured	O
to	O
redirect	O
data	O
from	O
a	O
specified	O
port	O
(	O
which	O
is	O
local	O
to	O
the	O
host	B-Device
that	O
runs	O
the	O
SSH	B-Protocol
client	O
)	O
through	O
a	O
secure	O
tunnel	O
to	O
some	O
specified	O
destination	O
host	B-Device
and	O
port	O
.	O
</s>
<s>
The	O
local	O
port	O
is	O
on	O
the	O
same	O
computer	O
as	O
the	O
SSH	B-Protocol
client	O
,	O
and	O
this	O
port	O
is	O
the	O
"	O
forwarded	O
port	O
"	O
.	O
</s>
<s>
On	O
the	O
same	O
computer	O
,	O
any	O
client	O
that	O
wants	O
to	O
connect	O
to	O
the	O
same	O
destination	O
host	B-Device
and	O
port	O
can	O
be	O
configured	O
to	O
connect	O
to	O
the	O
forwarded	O
port	O
(	O
rather	O
than	O
directly	O
to	O
the	O
destination	O
host	B-Device
and	O
port	O
)	O
.	O
</s>
<s>
After	O
this	O
connection	O
is	O
established	O
,	O
the	O
SSH	B-Protocol
client	O
listens	O
on	O
the	O
forwarded	O
port	O
and	O
directs	O
all	O
data	O
sent	O
by	O
applications	O
to	O
that	O
port	O
,	O
through	O
a	O
secure	O
tunnel	O
to	O
the	O
SSH	B-Protocol
server	O
.	O
</s>
<s>
The	O
server	O
decrypts	O
the	O
data	O
,	O
and	O
then	O
redirects	O
it	O
to	O
the	O
destination	O
host	B-Device
and	O
port	O
.	O
</s>
<s>
On	O
the	O
command	O
line	O
,	O
"	O
-L	O
"	O
specifies	O
local	O
port	B-Protocol
forwarding	I-Protocol
.	O
</s>
<s>
The	O
destination	O
server	O
,	O
and	O
two	O
port	B-Protocol
numbers	I-Protocol
need	O
to	O
be	O
included	O
.	O
</s>
<s>
Port	B-Protocol
numbers	I-Protocol
less	O
than	O
1024	O
or	O
greater	O
than	O
49150	O
are	O
reserved	O
for	O
the	O
system	O
.	O
</s>
<s>
Some	O
programs	O
will	O
only	O
work	O
with	O
specific	O
source	O
ports	O
,	O
but	O
for	O
the	O
most	O
part	O
any	O
source	O
port	B-Protocol
number	I-Protocol
can	O
be	O
used	O
.	O
</s>
<s>
Some	O
uses	O
of	O
local	O
port	B-Protocol
forwarding	I-Protocol
:	O
</s>
<s>
Connect	O
from	O
a	O
laptop	O
to	O
a	O
website	O
using	O
an	O
SSH	B-Protocol
tunnel	O
.	O
</s>
<s>
This	O
form	O
of	O
port	B-Protocol
forwarding	I-Protocol
enables	O
applications	O
on	O
the	O
server	O
side	O
of	O
a	O
Secure	B-Protocol
Shell	I-Protocol
(	O
SSH	B-Protocol
)	O
connection	O
to	O
access	O
services	O
residing	O
on	O
the	O
SSH	B-Protocol
's	O
client	O
side	O
.	O
</s>
<s>
In	O
addition	O
to	O
SSH	B-Protocol
,	O
there	O
are	O
proprietary	O
tunnelling	O
schemes	O
that	O
utilize	O
remote	O
port	B-Protocol
forwarding	I-Protocol
for	O
the	O
same	O
general	O
purpose	O
.	O
</s>
<s>
In	O
other	O
words	O
,	O
remote	O
port	B-Protocol
forwarding	I-Protocol
lets	O
users	O
connect	O
from	O
the	O
server	O
side	O
of	O
a	O
tunnel	O
,	O
SSH	B-Protocol
or	O
another	O
,	O
to	O
a	O
remote	O
network	O
service	O
located	O
at	O
the	O
tunnel	O
's	O
client	O
side	O
.	O
</s>
<s>
To	O
use	O
remote	O
port	B-Protocol
forwarding	I-Protocol
,	O
the	O
address	B-Protocol
of	O
the	O
destination	O
server	O
(	O
on	O
the	O
tunnel	O
's	O
client	O
side	O
)	O
and	O
two	O
port	B-Protocol
numbers	I-Protocol
must	O
be	O
known	O
.	O
</s>
<s>
The	O
port	B-Protocol
numbers	I-Protocol
chosen	O
depend	O
on	O
which	O
application	O
is	O
to	O
be	O
used	O
.	O
</s>
<s>
Remote	O
port	B-Protocol
forwarding	I-Protocol
allows	O
other	O
computers	O
to	O
access	O
applications	O
hosted	O
on	O
remote	O
servers	O
.	O
</s>
<s>
An	O
employee	O
of	O
a	O
company	O
hosts	O
an	O
FTP	B-Protocol
server	I-Protocol
at	O
their	O
own	O
home	O
and	O
wants	O
to	O
give	O
access	O
to	O
the	O
FTP	B-Protocol
service	O
to	O
employees	O
using	O
computers	O
in	O
the	O
workplace	O
.	O
</s>
<s>
Opening	O
remote	O
desktop	O
sessions	O
is	O
a	O
common	O
use	O
of	O
remote	O
port	B-Protocol
forwarding	I-Protocol
.	O
</s>
<s>
Through	O
SSH	B-Protocol
,	O
this	O
can	O
be	O
accomplished	O
by	O
opening	O
the	O
virtual	O
network	O
computing	O
port	O
(	O
5900	O
)	O
and	O
including	O
the	O
destination	O
computer	O
’s	O
address	B-Protocol
.	O
</s>
<s>
Dynamic	O
port	B-Protocol
forwarding	I-Protocol
(	O
DPF	O
)	O
is	O
an	O
on-demand	O
method	O
of	O
traversing	O
a	O
firewall	B-Application
or	O
NAT	O
through	O
the	O
use	O
of	O
firewall	B-Application
pinholes	O
.	O
</s>
<s>
DPF	O
can	O
be	O
implemented	O
by	O
setting	O
up	O
a	O
local	O
application	O
,	O
such	O
as	O
SSH	B-Protocol
,	O
as	O
a	O
SOCKS	B-Application
proxy	I-Application
server	O
,	O
which	O
can	O
be	O
used	O
to	O
process	O
data	O
transmissions	O
through	O
the	O
network	O
or	O
over	O
the	O
Internet	O
.	O
</s>
<s>
Since	O
data	O
must	O
pass	O
through	O
the	O
secure	O
tunnel	O
to	O
another	O
server	O
before	O
being	O
forwarded	O
to	O
its	O
original	O
destination	O
,	O
the	O
user	O
is	O
protected	O
from	O
packet	B-Protocol
sniffing	O
that	O
may	O
occur	O
on	O
the	O
LAN	O
.	O
</s>
<s>
DPF	O
can	O
also	O
be	O
used	O
to	O
bypass	O
firewalls	B-Application
that	O
restrict	O
access	O
to	O
outside	O
websites	O
,	O
such	O
as	O
in	O
corporate	O
networks	O
.	O
</s>
