Showing posts with label VOIP. Show all posts
Showing posts with label VOIP. Show all posts

Tuesday, May 3, 2011

NAT and VOIP

— SkyHi @ Tuesday, May 03, 2011
What is NAT?
NAT (Network Address Translation) is a technology most commonly used by firewalls and routers to allow multiple devices on a LAN with 'private' IP addresses to share a single public IP address. A private IP address is an address, which can only be addressed from within the LAN, but not from the Internet outside the LAN. In order to let a device with a private IP address communicate with other devices on the Internet, there needs to be a translation between private and public IP addresses at the point where the LAN connects to the Internet, that is within the firewall/router connecting the LAN to the Internet. Such a translation is commonly referred to as NAT (for Network Address Translation) and a router doing such translation is often called a NAT router or NAT firewall/router. Sometimes NAT is also called IP Masquerading. The passing of traffic through NAT is called NAT Traversal.

The way NAT works is in principle rather simple. When a device on the LAN initiates a connection with a device on the Internet, the device will send all traffic to the NAT router first. The NAT router then replaces the source address, which is the device's private address, with its own public address before passing the traffic to its destination on the Internet. When a response is received, the NAT router searches its translation tables to find the original source address of the packet from which the device on the LAN originally started the connection and thus passes the response to that device.

Unfortunately, when a connection is originated by a device on the Internet outside the LAN it is not clear which device on the LAN the connection is meant to be established with. In this case there needs to be some rule that tells the NAT router what to do with the incoming traffic, otherwise it will simply discard the traffic and no connection will be established. If the NAT router supports what is commonly referred to as a 'software DMZ' it can handle simple rules, such as "pass all incoming connection requests to the device with address 192.168.0.2". Another technique, called port forwarding allows the NAT router to pass incoming connection requests to different devices on the LAN depending on the type of connection (ie web or mail connection). However, if there are multiple devices on the LAN to which a certain type of connection from outside may need to be established, then neither a software DMZ nor port forwarding will be sufficient.

Sometimes people (those without network experience) have difficult to understand if their host is or not behind NAT, there is a website that will test to see if you are behind NAT (you need to have Java): (amibehindnat.com).


The Trouble with NAT and VOIP
In addition, the way in which conventional VoIP protocols are designed is also posing a problem to VoIP traffic passing through NAT. Conventional VoIP protocols only deal with the signalling of a telephone connection. The audio traffic is handled by another protocol and to make matters worse, the port on which the audio traffic is sent is random. The NAT router may be able to handle the signalling traffic, but it has no way of knowing that the audio traffic is related to the signalling and should hence be passed to the same device the signalling traffic is passed to. As a result, the audio traffic is not translated properly between the address spaces.

At first, for both the calling and the called party everything will appear just fine. The called party will see the calling party's Caller ID and the telephone will ring while the calling party will hear a ringing feedback tone at the other end. When the called party picks up the telephone, both the ringing and the associated ringing feedback tone at the other end will stop as one would expect. However, the calling party will not hear the called party (one way audio) and the called party may not hear the calling party either (no audio).

The issue of NAT Traversal is a major problem for the widespread deployment of VOIP. Yet, the issue is non-trivial and there are no simple solutions. In general terms there are two ways to deal with this problem:

avoid the problem altogether
working around the problem


Avoidance
By far the best way to deal with the issue of VoIP NAT Traversal is to avoid the cause of the problem in the first place:

Do not use NAT and obtain public IP addresses for all VoIP devices
If you cannot avoid NAT, use IP Tunneling between VoIP devices on different LANs
Use a public service. Eg sign up both sides to FWD and call from one to the other. Look at user authentication page for ways to control who has access to your internal lines
Use servers that implement IETF's Best Current Practices for NAT Traversal for Client-Server SIP. One of those is Yate



Workarounds
If you cannot avoid the problem, there are still several techniques available to work around the problem, none of them without their downsides. A white paper (NAT Traversal in SIP) explains some of the issues (at least as they relate to SIP signaling) and discusses STUN- & ICE-based workarounds in more detail.
fridu has published a set of clarifications and a step by step solution to interconnect an Asterisk server and remote SIP phones over a dual NAT configuration. You will find it on fridu.org web site.

However, there are some simple workarounds available:

(Re) Configure your NAT device to provide (limited) VoIP support. The specific configuratios required depend on what is required by the signaling method used (e.g. SIP, H.323, etc.) and the number and type of devices inside your NAT, and are set using the specific user interface supplied by your NAT vendor.
For instance, to set up a single SIP phone inside a residential NAT:
Set the SIP phone up with a static IP address;
Set up two forwarding entries the "Port Forwarding" (or similar) configuration form on the NAT configuration interface, each of which cause the NAT device to forward all traffic destined for the designated range of port numbers to the fixed IP address of the SIP phone:
SIP signaling: Ports 5060 to 5070
RTP audio: Ports 8766 to 35000
For enterprise firewalls, many directly support SIP and H.323 forwarding to both Proxy/PBX devices as well as to/from VoIP phone endpoints
Use a VoIP Protocol that overloads HTTP in order to traverse NATs on normally-open IP ports, such as the open IAX protocol. (Caution: IP network protocol experts will point out that techniques such as this which use HTTP for purposes for which it was not intended frequently carry negative unintended side-effects.)
A utility is available that enables Asterisk (win32) to work on the same box as ISA Server. Visitwww.generationd.com and look for SIPPF in the downloads area. It's a free script.
IXC found an approach to enable NAT customers to be callable via h323. It's possible to test this 'know how' after registration. News release of new version is also available.
Linux kernel: Netfilter seems to have got a conntrack patch for sip/rtp nat/firewall traversal: Iptables sip conntrack

'different approaches for making sip devices work behind a dd-wrt router'

'dd-wrt v23sp1voip' - upgrade your dd-wrt compatible router to dd-wrt v23sp1 (didn't test sp2 yet) VOIP version


This software release includes a special version of the ser (sip express router) software, which is able to act as an outbound proxy for sip devices (almost like a http proxy does for webbrowsers). ser and the second component rtpproxy take care of registering clients on the private network and forward all trafic between the sip service provider and the internal client (sip messages and rtp media streams).

This solution works fine for any device that has "outbound proxy" support as many ata (e.g. linksys-sipura spa 2001, grandstream budgetone etc.) do.

Just enter the ip adress and sip port (see dd-wrt administration interface for ip/port) of your dd-wrt router as outbound proxy in your phone's configuration screen. Restart the phone, and voila, you can talk. This works for an unlimited number of phones, as long as each phone uses a different sip username. Using the same sip username e.g. on a two analoge port sipura ata for both analog ports causes the second port to get registered to not work for incoming calls (not 100 % verified - please let me know if you tested it).

'transparent proxy on dd-wrt/openwrt'

Me myself having trouble using sip devices without "outbound proxy" support behind my dd-wrt routers, I was searching for a more simple solution. My motivation was to have booth my asterisk box behind the router as well as my nokia e61 sip smartphone being able to register to out companies public sip server. This was not possible as both asterisk as well as the current nokia sip client don't support outbound proxy nor stun.

Having used transparent proxies for hhtp for a while, the question was, why not do the same for sip messages and the rtp media streams? Well, it's possible. I didn't actually figure it out using dd-wrt voip's built in ser/rtpproxy package (maybe it's possible too with them), but relied on the instructions i found for the software "sipproxd" which is luckily available for the mips based broadcom plattform (openwrt package).

What you basically need is:

- dd-wrt/openwrt (non voip firmeware version - tested with v23sp1) with jffs enabled (and enough spare memory - this solution does not work for 8mb and maybe also not for 16 mb broadcom based router models). I myself us a 32mb Linksys WRT54GS v1.1. You need JFFS as a filesystem to download, install and configure additional software packages useing ipkg.
- ssh/telnet access to your router
- the information available on http://siproxd.sourceforge.net/siproxd_guide/siproxd_guide_c6s4.html

First enable jffs and initialize ipkg (see other dd-wrt/openwrt faqs/howtos on how to do this in detail). Once you've done this log onto your router using telnet or better ssh (root/).

Then download the siproxd package using the command "ipkg install siproxd". Then follow the instructions on this manual page http://siproxd.sourceforge.net/siproxd_guide/siproxd_guide_c6s4.html

You've to create the config file using the editor "vi" on while being looged onto your router. Copying the Text from the webrowser to the console vi using putty can be quite a hassle as for some reason characters seem to move to other places whil in reality they are still on their old place in the textfile. To be sure, save the file often, then open it again to get a clean view and then copy the next part of the file.

Then start siproxd by calling it from the command line cd ... then ./siproxd -c .

Finally copy the iptables commands one after each other to the console. Then fire up your sip client with it being configures as if it had a public ip address (e.g. xxxxxx@sipgate.at etc.) and voila you can talk and you be reachable if someone is calling you.

Currently the solution is not 100 % stable, as my nokia e61 is registering with my public asterisk server sucessfully the first time, but not the second time once I lost wlan connectivity. I did not determine yet if it is a problem on the router/siproxd or if it was the due to nokia e61 software problems (I then had the www.one.at branded april/2006 software version in the phone. I have not tried it with the generic nokia 07/2006 version yet as I found an even better solution for my nokia which I'll describe below.

'Mobile IPv4/Birdstep SmartRoaming'


The sipproxd solution works fine for clients within a fixed wlan/lan network. But what about poor me using my nokia outside my home/office network. It's nearly impossible to have all routers's equipped with siproxd transparent proxy solution.

After searching for a long time and having spent hours with Nokias incomplete SIP/Network Group Roaming implementation, I found a software supporting the Mobile IPv4 RFC on symbian operating systems. Great, what it basically does is having a client installed on your mobile phone, which makes a new connection available to all applications. It works like a vpn/tunnel. Thus once any network connection is available, the software signs up and creates a tunnel to Birdstel/Smartroaming and your phone gets a public IP from them.

Now it also takes care of you allways using the best connection, thus it's scanning for the wlan networks you've defined, and once you enter the office, it automatically sends all traffic via the wlan, or grps/umts vice versa when you leave the office. The applications are ALLWAYS ONLLINE and don't notice the connection change which is taking place in the background.

The best thing, there's no NAT, all applications are using the phones public ip via the tunnel. Thus your SIP client works flawlessly being able to register with my asterisk, sipgate and probably many other sip providers without any problem. Works like a charm.

The only drawback: after 1 month free trial, you've to pay a yearly fee of ~30 eur if you're using their Mobile IPv4 service. The say you can use the software (once you buy a licence) with other providers too. Too bad all open source software in regard to Mobile IPv4 is completely outdated and so to my knowledge no alternative option of being your own Mobile IPv4 Provider exists (apart from commercial software from hp/cisco etc.).

Some vendors offer information on the problem, and on how you can use their products to address the problem:

SNOM white paper: Operating phones behind NAT
Cisco.com whitepaper: VOIP traversal of NAT and firewall
White Paper: The SIP Protocol and Firewall Traversal
Newport Networks White Paper NAT Traversal for Multimedia over IP
White Paper: NAT Traversal for VoIP and Internet Communications using STUN, TURN and ICE
Use a SIP- and RTP-Proxy combination on your NAT/Firewall/Router - as done by the SIPatH Project





Free SIP NAT Solutions

Xtunnels Free NAT solution from Counterpath. Works with all Xlite and Eybeam softphones.



Other NAT Solutions
Some vendors offering NAT traversal 'solutions' for VOIP:

Acme Packet
AG Projects
BorderWare Technologies Inc.
Brekeke
CommuniGate Systems
Creacode
Cylogistics Trueline Session Border Controller
Eyeball Networks AnyFirewall Server and SDK
Data Connection
FreeSwitch opensource server that avoids most NAT issues by design
Ingate
Intertex
iSoftel
IXC
Jasomi Networks
Kagoor Networks
Loongtek: p2p nat tunnel library
MailVision's NAT Traversal Solutions
MediaRing
Mera Systems
miniSipServer for windows.
NeoTIP
Netrake
Newport Networks
NexTone
OpenSBC Open source Session Border Controller
Ridgeway
Sansay
Voice SIstem


See also:

A basic explanation of STUN protocol
Avoid SIP NAT Traversal using the NAT friendly IAX protocol
Asterisk: How to connect to FWD: Examples on Asterisk and NAT (to/from FWD )
Asterisk SIP NAT solutions
Freshmeat Article on SIP and NAT
How to solve the NAT traversal issue in SIP?
ICE: Interactive Connectivity Establishment (a proposal for NAT and SIP)
Important thing to look at if you get one way audio problem with Asterisk 1.4.10 and FreePBX 2.3.0
NAT survey: Types of NAT in various equipment
NAT Traversal for VoIP and Internet Communications using STUN, TURN and ICE - white paper
quintum http://www.binnacleita.com/ VoIP gateways NAT Traversal ready
SER NAT support: How SIP Express Router supports NAT (Interesting solution - check nathelper!)
Sho voip phone on SIP ,NAT and dect phones.
STUN: Simple Traversal of UDP through NAT
STUN protocol and VOIP A technical explanation of the purpose of STUN protocol in VOIP scenarios.
VOIP Routers


REFERENCES
http://www.voip-info.org/wiki/view/NAT+and+VOIP

Monday, March 8, 2010

VOIP problem

— SkyHi @ Monday, March 08, 2010
I currently got 2 problems with my WNR854T router, perhaps someone can help me here. I'm using firmware version 1.4.22.

* My VOIP router in bridge mode is somehow blocked by the WNR854T, I have tried UPNP and configuring port forwarding myself. I have forwarded the following ports manually: 5060-5061, 10000-10007, 3478-3479. VOIP works great on my old DLink router (configured those ports manually there too), but the netgear router seems to block the connection when making the actual phone call. I have tried disabling the SPI, but it doesn't help.

Anyone got any good suggestions how to make the VOIP work through the netgear router? Perhaps I should try an older firmware version?

* If I do an erase and start to reconfigure the router, I usually start by disabling the wireless, after doing most of my settings the "Enable Wireless Router Radio" setting gets enabled by itself automatically, and the funny thing is that I can't disable it again after that!

=============

Since Jope says that the ‘VOIP router is in bridge mode’ this implies to me that the VOIP router is also the modem? If so it will be on the WAN side of the Netgear router in which case DMZ would not be applicable? I don't do VOIP so could be wide of the mark here, but wouldn't the audio connection to the VOIP router also be on the WAN side of the Netgear, i.e. direct to the VOIP router? It might help if we knew the brand and model number of the VOIP router.

=============
Thanks for the answers, but I solved this by downgrading to firmware version 1.4.09.

Actually the VOIP router is connected as "just another device" on the LAN side. I tried setting it as DMZ before I downgraded, but it didn't work, somehow it could not get a proper connection to the server. The router is a Vood 322i.

Don't know if the problem with automatic wireless activation was solved by downgrading the firmware, don't really want to change anything now that I got it "working".

Lesson learned, next time I get the idea I need a new router I will build it myself and run pfsense or m0n0wall on it.


===========
Are you using UPnP? Yes.
Disable SPI? Yes.
DMZ? No.
Port forwarding? No.

==========

REFERERNCE
http://forum1.netgear.com/showthread.php?p=52928



Routers SIP ALG

— SkyHi @ Monday, March 08, 2010

Introduction

Many of today's commercial routers implement SIP ALG (Application-level gateway), coming with this feature enabled by default. While ALG could help in solving NAT related problems, the fact is that many routers' ALG implementations are wrong and break SIP.

There are various solutions for SIP clients behind NAT, some of them in client side (STUN, TURN, ICE), others in server side (Proxy RTP as RtpProxy, MediaProxy). ALG works typically in the client LAN router or gateway. In some scenarios some client side solutions are not valid, for example STUN with symmetrical NAT router. If the SIP proxy doesn't provide a server side NAT solution, then an ALG solution could have a place.

An ALG understands the protocol used by the specific applications that it supports (in this case SIP) and does a protocol packet-inspection of traffic through it. A NAT router with a built-in SIP ALG can re-write information within the SIP messages (SIP headers and SDP body) making signaling and audio traffic between the client behind NAT and the SIP endpoint possible.



SIP ALG example

  • caller behind NAT with private IP 192.168.1.33.
  • caller router public IP 192.0.2.200
  • SIP proxy in Internet with domain "example.com".


INVITE from the LAN client (with private IP)

INVITE sip:destino@example.com SIP/2.0
Via: SIP/2.0/UDP 192.168.1.33:5060;branch=z9hG4bKjyofoqmp
Max-Forwards: 70
To: <sip:destino@example.com>
From: "Iñaki" <sip:ibc@example.com>;tag=nrrrx
Call-ID: xetazdjyktlpsfo@192.168.1.33
CSeq: 800 INVITE
Contact: <sip:ibc@192.168.1.33:5060>
Content-Type: application/sdp
Allow: INVITE,ACK,BYE,CANCEL,OPTIONS,PRACK,REFER,NOTIFY,SUBSCRIBE,INFO,MESSAGE
Supported: replaces,norefersub,100rel
User-Agent: Twinkle/1.1
Content-Length: 312

v=0
o=ibc 1090098764 894503441 IN IP4 192.168.1.33
s=-
c=IN IP4 192.168.1.33
t=0 0
m=audio 8000 RTP/AVP 98 97 8 0 3 101
a=rtpmap:98 speex/16000
a=rtpmap:97 speex/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:3 GSM/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-15
a=ptime:20
a=zrtp


Note that text in red needs to be fixed before it arrives to the proxy (in case our proxy doesn't provide us a NAT server solution). If not, the proxy reply will not arrive at the client (caller):
  • The caller couldn't receive in-dialog/sequential messages (ACK for the INVITE, BYE, REFER, re-INVITE...) since the address in "Contact" is not routable outside their network.
  • Unidirectional audio since the caller told the callee to send audio to a non-routable address and port (so the caller won't hear the callee).

The text in blue doesn't need to be fixed since SIP already handles it (the server adds the parameter "received=REAL_SOURCE_IP" to the "Via" header and sends the replies to that address). Anyway some ALG implementations also change this value.


The same INVITE modified by the ALG router:

INVITE sip:destino@example.com SIP/2.0
Via: SIP/2.0/UDP 192.0.2.200:12345;branch=z9hG4bKjyofoqmp
Max-Forwards: 70
To: <sip:destino@example.com>
From: "Iñaki" <sip:ibc@example.com>;tag=nrrrx
Call-ID: xetazdjyktlpsfo@192.168.1.33
CSeq: 800 INVITE
Contact: <sip:ibc@192.0.2.200:12345>
Content-Type: application/sdp
Allow: INVITE,ACK,BYE,CANCEL,OPTIONS,PRACK,REFER,NOTIFY,SUBSCRIBE,INFO,MESSAGE
Supported: replaces,norefersub,100rel
User-Agent: Twinkle/1.1
Content-Length: 312

v=0
o=ibc 1090098764 894503441 IN IP4 192.168.1.33
s=-
c=IN IP4 192.0.2.200
t=0 0
m=audio 33445 RTP/AVP 98 97 8 0 3 101
a=rtpmap:98 speex/16000
a=rtpmap:97 speex/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:3 GSM/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-15
a=ptime:20
a=zrtp


The ALG has fixed the NAT related problem by:
  • Replacing IP in "Via" header with the public IP and port.
  • Replacing "Contact" with mapped public IP and port.
  • Replacing SDP media address with public IP and port.




SIP ALG problems

The main problem is the poor implementation at SIP protocol level of most commercial routers and the fact that this technology is just useful for outgoing calls, but not for incoming calls:
  • Lack of incoming calls: When a UA is switched on it sends a REGISTER to the proxy in order to be localizable and receive incoming calls. This REGISTER is modified by the ALG feature (if not the user wouldn't be reachable by the proxy since it indicated a private IP in REGISTER "Contact" header). Common routers just mantain the UDP "conntection" open for a while (30-60 seconds) so after that time the port forwarding is ended and incoming packets are discarded by the router. Many SIP proxies mantain the UDP keepalive by sending OPTIONS or NOTIFY messages to the UA, but they just do it when the UA has been detected as natted during the registration. A SIP ALG router rewrites the REGISTER request so the proxy doesn't detect the NAT and doesn't mantain the keepalive (so incoming calls will be not possible).
  • Breaking SIP signalling: Many of the actual common routers with inbuilt SIP ALG modify SIP headers and the SDP body incorrectly, breaking SIP and making communication just impossible. Some of them do a whole replacing by searching a private address in all SIP headers and body and replacing them with the router public mapped address (for example, replacing the private address if it appears in "Call-ID" header, which makes no sense at all). Many SIP ALG routers corrupt the SIP message when writting into it (i.e. missed semi-colon ";" in header parameters). Writting incorrect port values greater than 65536 is also common in many of these routers.
  • Dissallows server side solutions: Even if you don't need a client side NAT solution (your SIP proxy gives you a server NAT solution), if your router has SIP ALG enabled that breaks SIP signalling, it will make communication with your proxy impossible.



List of routers with SIP ALG enabled

The following is a list containing SIP ALG router models, their issues and how to disable SIP ALG (enabled by default in most of the cases). Please add more data to this list if you have experimented problems due to a SIP ALG router.


SpeedTouch

Models: ST530 v6 (firmware >= 5.4.0.13) comes with SIP ALG enabled by default.
NAT type: symmetrical
Issues:
  • No incoming calls.
  • It replaces the private IP appearing in SIP headers with the public IP using a dumb text replacement. If for example the private IP appears in the "Call-ID" it replaces it too (that it's completely unnecessary).
To disable SIP ALG:
~# telnet router
-> connection unbind application=SIP port=5060
-> saveall


Zyxel

Models: 660 family comes with SIP ALG enabed by default.
NAT type: symmetrical
Issues:
  • No incoming calls.
  • SIP protocol broken making 50% of outgoing calls impossible because the wrong values are inserted into SIP headers.
To disable SIP ALG:
~# telnet router
Menu option "24. System Maintenance".
Menu option "8. Command Interpreter Mode".
ip nat service sip active 0


Netgear

Models: WGR614v9 Wireless-G Router, DGN2000 Wireless-N ADSL2+ Modem Router
Firmware V1.0.18_8.0.9NA
To disable SIP ALG: From Wan Setup Menu, NAT Filtering, uncheck the box next to "Disable SIP ALG"


SMC

Models: ToDo
NAT type: No symmetrical
Issues:
  • The ALG doesn't replace the private address in "Call-ID" header (that is correct) but it does replace the "call-id" value in "Refer-To" header so SIP transfer is broken.
To disable SIP ALG: ToDo no ALG related options found via web and telnet. No idea of how to dissable it.


Linksys

Models: WRV200, WRT610N
NAT type: Symmetrical
Issues:
  • The ALG replaces the private address in "Call-ID" header (not needed at all). Some phones (as Linksys with latest firmware) encode the "Call-ID" value in the "Refer-To" header (by escaping the dots) so the private IP appearing there is not replaced with the public IP. This causes that the call transfer fails since the proxy/PBX/endpoint will not recognize the dialog info.
To disable SIP ALG: ToDo no ALG related options found via web and telnet. No idea of how to disable it.
To disable SIP ALG on WRT610N: Web Interface: Administration, Management, under side heading 'Advanced Features' SIP ALG, can be disabled.

Peplink Multi-WAN routers

Models: All multi-WAN models
To disable SIP ALG, go to http://<router.LAN.IP>/cgi-bin/MANGA/support.cgi
Click the "Disable" button under "SIP ALG Support"
Issues:
  • I'm not aware of any SIP ALG issues, but if you just want to turn it off, here you go.


Fortinet

Models: 800 comes with SIP ALG enabed by default.
To disable SIP ALG:
~# telnet firewall
config system settings
set sip-helper disable
set sip-nat-trace disable
end

config system session-helper
delete 12
end









See Also

REFERENCE
http://www.voip-info.org/wiki/view/Routers+SIP+ALG