Asterisk can both act as a SIP client and a SIP server. Asterisk as a SIP client is configured with type=peer (or type=friend) in one or more client sections of sip.conf and, optionally, one or more register=> lines in the [general] section of sip.conf. Asterisk as a SIP server connects clients (SIP Phones) configured by specifying their own username, secret, etc. (and either type=peer or type=friend) in client sections of sip.conf.
Asterisk SIP channels in a NATed network can be generalized like this:
Asterisk as a SIP client behind nat, connecting to outside SIP Proxies
Asterisk as a SIP client behind nat, connecting to inside SIP proxies
Asterisk as a SIP server behind nat, clients on the outside connecting to Asterisk
Asterisk as a SIP server behind nat, clients on the outside behind a second NAT connecting to Asterisk
Asterisk as a SIP server behind nat, clients on the inside connecting to Asterisk
Asterisk as a SIP client outside nat, connecting to outside SIP proxies
Asterisk as a SIP client outside nat, connecting to inside SIP proxies
Asterisk as a SIP server outside nat, clients on the outside connecting to Asterisk
Asterisk as a SIP server outside nat, clients on the inside connecting to Asterisk
Every setup works somewhere, but it depends on the client, the NAT, the server and many other factors. In most cases, 1 and 3 is broken. SIP is a peer-to-peer protocol and a NAT can be generalized and simplified as a solution that allows clients on the inside to connect to servers on the outside and _not_ allow clients on the outside to connect to any server on the inside.
#1 works with a NAT-supporting proxy as SIP Express router as the outside proxy. (Get an account at IPtel.org and try!). Fails with Free World Dialup.
#2 Works- no NAT in between
#3 Works with port forwarding and some header mangling magic tips
#4 Works with port forwarding, STUN on the remote and some fine tuning of RTP port allocation
#5 Works - no NAT in between
#6 is no problem. No NAT in the middle
#7 is a problem if no port forwarding is done, similar to 3 above.
#8 is no problem. No NAT in the middle
#9 is solved with nat=yes and qualify=xxx in sip.conf for the client in most cases. Some clients (X-lite) assist themselves by using STUN and sending UDP keep-alive packets. Qualify sends keep-alive packets from Asterisk to the client on the inside.
http://www.voip-info.org/wiki/view/Asterisk+SIP+NAT+solutions