Creating a Kamailio configuration to forward calls to a specific IP address while preserving the original caller’s IP can involve several steps. Here’s a minimalistic example to get you started. Note that this is a basic example; for a production setup, you would need to consider security, logging, error handling, and other aspects.
kamailio.cfg
cfg
# Kamailio SIP server configuration script
# This is a simple example to forward calls to a specific IP with the original caller's IP.
# Load necessary modules
loadmodule "tm.so"
loadmodule "sl.so"
loadmodule "rr.so"
loadmodule "maxfwd.so"
loadmodule "usrloc.so"
loadmodule "registrar.so"
loadmodule "textops.so"
loadmodule "siputils.so"
# Set core parameters
listen=udp:YOUR_KAMAILIO_IP:5060
# Request route
request_route {
# Handle OPTIONS requests
if (is_method("OPTIONS")) {
sl_send_reply("200", "Keepalive");
exit;
}
# Drop SIP messages with max-forwards=0
if (!mf_process_maxfwd_header("10")) {
sl_send_reply("483", "Too Many Hops");
exit;
}
# Handle initial INVITE requests
if (is_method("INVITE")) {
# Save the original caller's IP
if (!add_rcv_param("src_ip")) {
xlog("L_ERR", "Failed to save original caller's IP.");
}
# Forward the call to the specific IP
if (!forward_caller("15.235.2.155:5060")) {
xlog("L_ERR", "Failed to forward call.");
}
exit;
}
# Default action for other requests
sl_send_reply("501", "Not Implemented");
exit;
}
# Set parameters for user location
modparam("usrloc", "db_mode", 0)
modparam("registrar", "method_filter", "REGISTER")
# Handle incoming REGISTER requests
route[REGISTRAR] {
save("location");
}
# Loose routing for in-dialog requests
route[WITHINDLG] {
if (loose_route()) {
if ($ci !~ "^([A-Za-z0-9]){4,32}@(.{34,34})$") {
sl_send_reply("403", "Forbidden - Invalid Call-ID format");
exit;
}
route(RELAY);
exit;
}
if (is_method("ACK")) {
route(RELAY);
exit;
}
}
# Relay route for forwarding requests
route[RELAY] {
if (!t_relay()) {
sl_reply_error();
}
exit;
}
Explanations:
Load Necessary Modules:
These modules are required for handling basic SIP functionalities.
Core Parameters:
listen=udp:YOUR_KAMAILIO_IP:5060 - Kamailio listens on this IP and port.
Request Route:
Handles various SIP requests (INVITE, OPTIONS, etc.) and forwards INVITE requests to 15.235.2.155:5060.
Original Caller’s IP:
add_rcv_param("src_ip") adds the original caller’s IP to the message.
Forward Calls:
forward_caller("15.235.2.155:5060") forwards the call while keeping the original caller’s IP in the headers.
User Location Parameters:
Handles user location saving for registrations.
Registrar Route:
Saves user registration details.
Loose Routing:
Handles in-dialog requests and routes them correctly.
Relay Route:
Relays SIP requests while error handling.
Important:
Security:
Add necessary security configurations (ACLs, DNS filtering, etc.).
Logging and Error Handling:
Enhance logging and error handling as needed.
Testing:
Thoroughly test the configuration in a staging environment before deploying it to production.
Modules:
Ensure all necessary modules are installed and configured correctly.
Notes:
Replace YOUR_KAMAILIO_IP with the IP address of your Kamailio server.
This script assumes basic SIP knowledge and may need adjustments based on your specific needs and environment.
If you have any more specific requirements or face any issues, do let me know!