Customers often come to us with a fairly common problem. In general terms, it can be expressed as follows: the company uses an analog telephone station to which it is necessary to connect some of the users from a remote location. It can be a neighboring office, a neighboring city, or even another country - the main thing is that the telephone network does not reach there, but the LAN does not reach, or there is Internet access. Today we will solve this problem with the help of Grandstream VoIP-gateways of the GXW4xxx series.

In fact, this problem has many variations. For example, forwarding PSTN lines to another location or combining the number capacities of two remote analog PBXs is very similar in meaning and solution to the problem. Therefore, in order not to introduce unnecessary confusion, we will immediately determine the initial data and take the following illustration for them:

There is a head office of the company in which there is an analog PBX, with the numbering of internal phones 2XX. There is also a remote office with four employees who need to assign internal numbers 301-304. It is required to provide an opportunity for employees from different offices to directly call each other using an internal short number.
')
At the headquarters of the company, we will place a Grandstream VoIP gateway with FXO ports. This can be the GXW4104 model (4 ports) or the GXW4108 (8 ports). And in a remote office, the gateway with FXS ports is GXW4004 (4 ports) or GXW4008 (8 ports). For simplicity, we
accept that we work with the four-
port GXW4104 and
GXW4004 gateways, respectively.
Let's allocate four internal ports in our analog PBX and assign internal numbers to them - 301-304. We connect the Grandstream GXW4104 to the local network, assign a static IP address and connect the internal PBX ports to the gateway ports (No. 301 to the first port of the gateway, No. 302 to the second, etc.). At the remote branch, we will also assign a static address to the GXW4004 gateway and connect four analog telephone sets to it.
Now we need to solve two subtasks:
- Allow subscribers of the head office (â„–201, â„–202) to call the subscribers of the remote office (â„–â„– 301 - 304)
- Allow remote office subscribers to call subscribers of the company's head office.
We will begin the solution to the first problem by configuring GXW4104:
- Section Accounts - Account 1 - General Settings . In the SIP Server field, specify the IP address of the Grandstream GXW4004 FXS gateway located in the remote office. If the gateways are located in the same local network or VPNs are combined, we specify the local IP address. Otherwise, we specify the external IP address of the remote division, and ports on the remote router will have to forward. We'll talk about port forwarding separately later.

- Section Accounts - Account 1 - SIP Settings . In the SIP Registration field, select the No value — the gateways will interact with each other in the “no registration” mode.

- Section Settings - Channels Settings - Calling to VoIP . In the SIP Server field, we specify ch1-4: p1; This means that calls received from the PBX to any of the FXO ports of the gateway will be redirected to the IP address specified in the section Accounts - Account 1 - General Settings . If for some reason instead of Account1 we would use Account2, then this entry would look like this: ch1-4: p2; If we used the eight-port GXW4108 gateway, then we would specify ch1-8 to work with all its ports : p1;

- Section Settings - Channels Settings - Calling to VoIP . It is not enough to know the IP address to which calls should be redirected, you also need a SIP port. Therefore, in the SIP Destination Port field, we change the default value of ch1-4: 5060 to ch1-4: 5060 ++; The record means that calls from the PBX to the first FXO port will be sent to the SIP port 5060 of the remote gateway, to the second FXO port to be sent to the SIP port 5062, and to the third and fourth ports to the ports 5064 and 5066, respectively. Based on the SIP port to which the call came, the FXS gateway in the remote branch will be understood for which of its four phones that call is intended.
- Section Settings - Channels Settings - Calling to VoIP . The User ID field defaults to ch1-4:. This is not quite suitable for us, as in this case, the call that came from the PBX will not be automatically redirected to the IP network. Instead, the gateway will wait for the PBX subscriber who initiated the call to dial some number to which the call should be sent. It does not suit us, so it would be logical to write the following in this field: ch1: 301; ch2: 302; ch3: 303; ch4: 304 . Then the FXO gateway will add numbers 301-304 (depending on the port) to the SIP message for transmission to the FXS gateway. But, as we noted earlier, the remote FXS gateway will distribute calls between its phones only on the basis of the SIP port, so such an entry would be unnecessary. It is enough for us to specify absolutely any value, except for an empty one, so that the FXO gateway starts forwarding calls to the specified IP address on the specified ports. Records ch1-4: 123; or ch1-4: x; will work well.
All other settings for the GXW4104 can be left as default. And these settings are enough to organize communication from the subscribers of the head office with the subscribers of the branch. Yes, the GXW4004 remote gateway does not even need to be configured, since by default it listens to ports 5060, 5062, 5064 and 5066 and transforms the messages that go to these ports and sends them to ports 1-4, respectively. Odd SIP ports 5061, 5063, 5065, and 5067 on the FXS gateway are set as default for SIP over TLS.
However, we are also required to solve the second task - to organize communication by the subscribers of the remote branch with the subscribers of the head office. This problem can be solved in two ways: by analogy with the first task, using different SIP-ports for different channels or using dialplan. Choose the second option: open the web interface of the Grandstream GXW4004 remote gateway and go to the
Profile 1 section:

- In the Primary SIP Server field, enter the IP address of the Grandstream GXW4104 FXO gateway located in the head office. If it is not a local IP address, port forwarding will also be required.
- In the SIP Registration field, select the No value — the gateways will interact with each other in the “no registration” mode.
- In the Outgoing Call without Registration field, select Yes , thereby allowing outgoing calls to be made in the “without registration” mode.
- In the Dialplan field , specify {<= 99 $ P> x +} . This entry tells the gateway about the following: allow all numbers consisting of one or more digits (x +) to be dialed and add 99 $ P prefix to each dialed number, where $ P is the number of the FXS port to which the calling phone is connected. When the subscriber 301 dials the number 202 on his phone, the GXW4004 will transmit the number of the type 99-1-202 to the GXW4104. If subscriber 303 dials 204, it will be transmitted as 99-3-204. It is on the basis of this prefix that the FXO gateway at the head office will determine through which FXO port it should transfer the call to the PBX.

We return to the configuration of the GXW4104 gateway at the head office: open the web interface and go to the
FXO Lines> Dialing section.
- In the field Stage Method (1/2) make the record ch1-4: 1; This means that for all four channels the call will be used without dialing. If we left the default entry ch1-4: 2 , then the subscriber of the remote branch would have to redial the number he needed, after the call was sent to the FXO gateway. And this is an extra job, because the subscriber once dialed the number he needs.

- In the Prefix to Specify Port field, leave the default value 99 . Having found this prefix in the number that came from the branch, the FXO gateway will understand that the next digit is the port number through which it should send the call to the PBX. Thus, we will ensure that calls from remote subscribers come strictly to their designated ports on the PBX.
This completes the configuration of the gateways - now the subscribers of the remote branch can call the head office employees and even to landline numbers via PBXs, if this is not explicitly prohibited on the PBX itself.
About port forwardingWhat ports should be forwarded?
- In our configuration, these are UDP ports 5060, 5062, 5064, and 5066 for the SIP protocol. For eight-port gateways, you will also need to forward even-numbered ports 5068 - 5074.
- RTP voice traffic: 2 ports are used for each communication channel (RTP voice itself + RTCP control). On the gateways, the starting port is specified in the Local RTP port option, the default for both gateways is 5004, respectively, the first port will be listening on UDP ports 5004 + 5005, for the second one 5006 + 5007, and so on. Accordingly, when using Local RTP port = 5004, it is necessary to forward ports for the 4-port gateway - ports 5004-5011, and for the 8-port gateway - ports 5004-5019.
Naturally, port forwarding is strongly recommended to do with reference to the source address. Better yet, completely abandon port forwarding and, if possible, organize a VPN network between two remote locations.
Multiple remote offices
Change the task a bit. Suppose we need to connect not one but several remote branches to the central PBX of the company. Let it be three retail outlets with one subscriber in each:

Instead of four-port gateways, it would be more logical to put inexpensive single-port SIP adapters at these points, for example, Grandstream HT701. How, then, will the settings on the GXW4104 change? To pass a call from the subscribers of the head office to the remote subscribers no longer need to use different SIP ports, since now calls for different remote subscribers will be directed to different IP addresses. And here we encounter the first problem - the number of SIP servers that can be set up on GXW4104 (and even on GXW4108) is limited to three, so more than three locations can be connected via one such FXO gateway.
- Go to the section Accounts - Account 1 - General Settings . In the SIP-Server field, specify the IP address of the HT701 retail point 1. Do the same for Account 2 and Account 3, specifying the addresses of the gateways from retail point 2 and 3, respectively.

- Section Accounts - Account 1 - SIP Settings . In the SIP Registration field, select the value No. Repeat for Account 2 and Account 3.

- Section Settings - Channels Settings - Calling to VoIP . In the SIP Server field, we specify ch1: p1; ch2: p2; ch3: p3; ch4: p1; Although the fourth channel is not used, we must assign a profile for it. In the SIP Destination Port field, we leave the default value of ch1-4: 5060 . The User ID field is filled in similarly to the previous example, for example, ch1-4: 123;

Outgoing calls from the central PBX to remote points were earned, since each HT701 listens to its own port 5060 by default and when a call arrives, it initiates a call to the phone connected to the only FXS port. In order for calls to go the other way, you need to configure each Grandstream HT701. Go to the HT-701 gateway's web interface and go to the
FXS PORT section.
- In the Primary SIP Server field, enter the IP address of the FXO gateway to the Grandstream GXW4104.

- In the SIP Registration field, select No

- In the Dial Plan Prefix field, enter 991 for the first point (telephone 301), 992 for the second (302) and 993 for the third (303). Based on this prefix, the FXO gateway in the head office will understand through which port the call should be sent to the PBX.

If in the settings
FXO Lines> Dialing Grandstream GXW4104 in the
Stage Method field
(1/2) is specified
ch1-4: 1 , and in the
Prefix to Specify Port field is indicated
99 , then calls from the subscribers of remote points to the side of the PBX will also work.
We use IP phones
In this task, the FXO gateway installed in the head office is a key element, which we cannot refuse, since the central PBX, under the terms of the task, does not support the SIP protocol. If replacing a central PBX is a time consuming and expensive procedure, then replacing analog telephones with SIP-enabled devices in remote branches is quite easy and many of our customers do. This simplifies the scheme somewhat:

The settings for the GXW4104 do not change compared to the previous example. IP phone settings consider the example of the model
Grandstream GXP1620 . Open the Web-interface and go to the section
Accounts - Account 1 - General Settings .
- In the Account Name field, enter the phone number - 301, 302 or 303.
- In the SIP Server field, enter the IP address of the FXO gateway of the Grandstream GXW4104.

- Let's go to the Account 1 - SIP Settings - Basic Settings section and select No in the SIP Registration field.

- Let's go to the Account 1 - Call Settings section and in the Dial Plan Prefix field, enter the value 991 for the phone 301, 992 for the phone 302 and 993 for the phone 303.

This completes the configuration of the IP phone - now you can make calls to the phones of subscribers of the central PBX. It should be noted that not all phones can work in this configuration. The main requirement for devices - the ability to make calls without registration. Also, phones must be able to add a prefix to the dialed number. The second requirement is not mandatory, because instead of using a dialplan, you can route calls from different IP phones to different SIP ports of the FXO gateway, which will allow the latter to send calls to the PBX correctly. You can also use 2-stage dialing, which, however, is less convenient. The most popular brands of IP-phones, such as Grandstream, Yealink, Fanvil, Linksys meet the specified requirements and support the work in this configuration.