How to restrict SIP gatewary access astersik by IP address

How can i restrict SIP gateway accessing to my asterisk server by IP address?

I have two questions:

  1. My asterisk server can receive call from SIP gateway and see the caller id, but when the call routed to my PBX the caller id is losed. My asterisk connected to PBX through PRI E1.
    2、How can i restrict SIP gateway accessing to my asterisk server by IP address?

When you Dial() the pbx, use the ‘o’ flag. THis preserves the caller id of the Originating channel.

when you define the sip.conf [entry] for the pbx, define host=x.x.x.x replace the x.x with your gateway’s IP address.

Hoep that helps!

Below is the entry in sip.conf for SIP gateway. it only allow
to access my system, but really, any ip can access my asterisk system.


For the more, how to use the ‘o’ flag when i dial() the pbx.

replace deny= and permit= with host=.

What do you mean by ‘use’? If you mean anybody ends up able to place a sip call into the system, are you sure they are not matching the guest context? in the general section, set context= to something that doesn’t exist or goes nowhere, and set allowguest=no. This will prevent connections that do not match one of the users/peers. It will also mean that nobody except a registered user/peer can place a call into your system. This may or may not be what you want.

You can also use IPtables firewall to prevent any connections to port 5060 other than from this host, but that will disable ALL sip traffic not from your router, including phones/providers/etc.