VoIP Firewall
This page explains which firewall rules you need so that calls reach VoIP phones and PBXs on public IP addresses (including IPv6). If your phones are behind NAT, see If you use NAT below.
In short: allow incoming UDP from our VoIP server addresses to your phone's SIP port and RTP port range. Don't open your SIP port to anyone else.
Allowing the right SIP and RTP packets through your firewall is the key to reliable VoIP. It may be possible to get by with SIP keep-alive packets and phones using UDP hole punching for the audio, but firewall rules are much more certain to work.
Our VoIP server addresses
Add all of these to your firewall rules, even if you don't see traffic from some of them. It's a fairly large number of addresses, but it lets us expand our platform and host equipment in different data centres without you having to change anything.
| IPv6 | IPv4 (legacy) | IPv4 as CIDR blocks |
|---|---|---|
2001:8b0:0:30::5060:0/1122001:8b0:5060::/48
|
81.187.30.110 - 81.187.30.11990.155.3.0/2490.155.103.0/24
|
81.187.30.110/3181.187.30.112/2990.155.3.0/2490.155.103.0/24
|
The same addresses are used for both SIP and RTP: audio comes from the same call server as the SIP messages.
Some routers can't take an address range like 81.187.30.110 - 81.187.30.119. Use the CIDR blocks in the third column instead.
Ports to allow
| Traffic | Protocol | Destination port on your phone | What it's for |
|---|---|---|---|
| SIP | UDP | 5060 (or whatever your phone's SIP port is) | Call set-up and control. If this is blocked, incoming calls fail. |
| RTP | UDP | Your phone's RTP port range. If you don't know it, 1024-65535. | The audio itself. |
SIP
SIP carries the messages that set up and manage calls. If incoming SIP packets are blocked, incoming calls will fail.
Only allow SIP from our addresses. If you open port 5060 to the whole internet, you'll see attacks and may get spam calls straight to your phone (see Odd incoming calls).
RTP
RTP carries the audio. On most phones you can set which ports it listens on for RTP, so you can narrow the range from 1024-65535.
RTP uses two consecutive ports: the even port you set, and that port + 1. Allow both. For example:
| Phone | Default RTP setting | Ports to allow |
|---|---|---|
| Snom | 49152-65534 | 49152-65535 |
| Grandstream phones and ATAs | 5004 | 5004-5005 |
Fewer rules: put SIP inside the RTP range
If your router needs one rule per address range, you can halve the number of rules by using one rule for both SIP and RTP. Set your phone's RTP range so that, together with the SIP port, it forms one continuous range, e.g. SIP on 5060 and RTP on 5000-5098, then allow 5000-5099. The ZyXEL example below does this.
Example configurations
FireBrick
If your phone registers with the FireBrick itself, allow traffic from the FireBrick to the LAN:
<rule name="Allow FireBrick" source-interface="self" comment="Allow all from the FireBrick to LAN"/>
If your phone registers with our VoIP service (Voiceless), allow our addresses to the phone. Replace 192.0.2.10 and 2001:db8::10 with your phone's IPv4 and IPv6 addresses:
<rule name="SIP" source-ip="81.187.30.110-119 90.155.3.0/24 90.155.103.0/24 2001:8b0:0:30::5060:0/112 2001:8b0:5060::/48" target-ip="192.0.2.10 2001:db8::10" target-port="5060" protocol="17" action="accept"/>
<rule name="RTP" source-ip="81.187.30.110-119 90.155.3.0/24 90.155.103.0/24 2001:8b0:0:30::5060:0/112 2001:8b0:5060::/48" target-ip="192.0.2.10 2001:db8::10" target-port="1024-65535" protocol="17" action="accept"/>
ZyXEL router
This example is for a ZyXEL router we supply. It assumes you've set your phones' RTP range to 5000-5098. Because that range plus SIP port 5060 fits inside 5000-5099, it needs 6 rules rather than 12.
| Filter name | Source IP address | IP type | Protocol | Custom destination port | Policy | Direction |
|---|---|---|---|---|---|---|
| VoIP6A | 2001:8b0:0:30::5060:0/112 |
IPv6 | UDP | 5000-5099 | ACCEPT | WAN to LAN |
| VoIP6B | 2001:8b0:5060::/48 |
IPv6 | UDP | 5000-5099 | ACCEPT | WAN to LAN |
| VoIP4A | 81.187.30.110/31 |
IPv4 | UDP | 5000-5099 | ACCEPT | WAN to LAN |
| VoIP4B | 81.187.30.112/29 |
IPv4 | UDP | 5000-5099 | ACCEPT | WAN to LAN |
| VoIP4C | 90.155.3.0/24 |
IPv4 | UDP | 5000-5099 | ACCEPT | WAN to LAN |
| VoIP4D | 90.155.103.0/24 |
IPv4 | UDP | 5000-5099 | ACCEPT | WAN to LAN |
Other things to firewall
- Phone and server web pages: don't allow access to your phones' or servers' web configuration pages from the internet.
- Your own PBX: if phones connect to your own PBX over the internet, lock it down as much as possible, e.g. only allow access via a VPN.
If you use NAT
If your phones are on private IP addresses (e.g. 192.168.x.x, 10.x.x.x), firewall rules on their own won't get calls through: the router also needs to know which phone to send incoming traffic to. Usually that's handled by keep-alives, STUN or a SIP ALG; see VoIP NAT for the options and a troubleshooting checklist. Avoid NAT for VoIP where you can.
Port forwarding for more than one phone
If you use port forwarding instead, each phone behind the router needs a different SIP port and RTP range. If both used SIP port 5060, the router wouldn't know which phone to send an incoming call on external port 5060 to.
For example, with two phones:
| Phone | LAN address | SIP port | RTP ports | Forward |
|---|---|---|---|---|
| Phone 1 | 192.168.1.12 | 5060 | 5062-5068 | 5060-5069 |
| Phone 2 | 192.168.1.13 | 5040 | 5042-5048 | 5040-5049 |
On a Linux router using iptables, the port forwards look like this:
SRC=81.187.30.110/31,81.187.30.112/29,90.155.3.0/24,90.155.103.0/24 iptables -t nat -A PREROUTING -i eth0 -p udp -s $SRC --dport 5060:5069 -j DNAT --to-destination 192.168.1.12 iptables -t nat -A PREROUTING -i eth0 -p udp -s $SRC --dport 5040:5049 -j DNAT --to-destination 192.168.1.13
If your FORWARD chain drops traffic by default, you'll also need matching FORWARD rules to accept it.
Further VoIP security
See VoIP Security for securing your phones, accounts and VoIP systems.