SCALANCE M874-3 IPsec VPN Setup for S7 CPU Data Exchange

David Krause11 min read
Industrial NetworkingSiemensTutorial / How-to
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

SCALANCE M874-3 IPsec VPN Setup for S7 CPU Data Exchange

When two S7 controllers must exchange process data over a cellular link, two SCALANCE M874-3 GPRS/UMTS routers can be bridged by an IPsec VPN tunnel running across a Private APN. The cellular layer (modem, SIM, APN) only carries the encrypted IP packets; the application layer is plain ISO-on-TCP (S7) or S7-communication, exactly as if both controllers were on the same Layer 2 LAN. This article is the field-reference walk-through: hardware, addressing, IPsec phase 1/phase 2 parameters, S7 communication, diagnostics, and a fault matrix.

Assumption set. Both SIMs are issued with fixed public-routable IP addresses by the mobile operator (or by an MNO-hosted Private APN with private static IP pool). The two M874-3 units can already ping each other across the cellular bearer before VPN is enabled. No PC or SCADA server sits between the routers.

1. Hardware and Firmware Baseline

Item Value Notes
Router SCALANCE M874-3 (6GK5874-3AA00-2AA2 family) UMTS/HSPA+ quad-band, Ethernet, SIM holder, SMA antenna
Firmware ≥ V5.x (recommended V6.x or later) Earlier firmware lacked IKEv2 and AES-256
Power 24 V DC / 1 A typical Screw terminal on bottom
Ethernet ports 2 x RJ45 10/100 P1 = LAN side toward S7 CPU; P2 = not used in this topology
Antenna ANT794-4MR (multi-band) Connect to both ANT sockets for RX diversity
SIM Mini-SIM, 3 V Fixed IP subscription required
S7 CPU side S7-300/400 (CP343-1/CP443-1) or S7-1200/1500 PN interface Put on same subnet as M874-3 P1 port

2. Reference Topology

S7-1200/1500 CPU 192.168.1.10 M874-3 (Site A) WAN: 10.50.1.5 M874-3 (Site B) WAN: 10.50.1.6 S7-1200/1500 CPU 192.168.2.10 IPsec Tunnel / GPRS Site A LAN: 192.168.1.0/24 Site B LAN: 192.168.2.0/24

Site A and Site B each run one S7 controller and one M874-3. The router WAN IP is the fixed SIM IP supplied by the mobile operator on the Private APN. The LAN IP of the router is the default gateway for the S7 CPU at that site.

3. Prerequisites

  1. Both M874-3 units have a working GPRS/UMTS link with signal level ≥ -85 dBm (check via WBM » Information » Mobile). RSCP / Ec/Io must be acceptable to the operator.
  2. Each SIM is provisioned with a fixed IP on the same Private APN (or with globally routable static IPs). Confirm by pinging both public IPs from each M874-3 CLI.
  3. The two S7 CPUs are in different /24 LANs (recommended) so routing does not collide. Example: Site A 192.168.1.0/24, Site B 192.168.2.0/24.
  4. The NTP server (or operator NTP) is reachable, because IPsec lifetime calculation depends on a correct wall clock.
  5. The pre-shared key (PSK) string is at least 32 characters and shared via an out-of-band channel.
  6. Local PC for WBM access with a static IP in the same subnet as the LAN port (192.168.1.0/24 default).

4. IPsec VPN Concepts for M874-3

The M874-3 supports IPsec in tunnel mode. Frames from the S7 CPU are encapsulated by ESP (Encapsulating Security Payload) and forwarded to the peer WAN IP. Authentication is by Pre-Shared Key (PSK) or by X.509 certificates; for two-unit brownfield deployments PSK is the field default.

Parameter Recommended value Comment
IKE version IKEv2 Faster re-key, MOBIKE support, NAT-T embedded
Phase 1 encryption AES-256-CBC Phase 1 (IKE_SA)
Phase 1 integrity SHA-2-256 HMAC-SHA-256
Phase 1 DH group Group 14 (2048-bit) Group 5 (1536) still works but discouraged
Phase 1 lifetime 28800 s (8 h) Triggers re-authentication
Phase 2 transform ESP-AES-256-CBC + ESP-SHA256-HMAC Combined-mode (AES-GCM-128/256) optional
Phase 2 lifetime 3600 s (1 h) Triggers re-key without re-auth
PFS Group 14 Perfect Forward Secrecy
Authentication Pre-Shared Key Certificates are an alternative if PKI exists
NAT-T Enabled Required if Private APN performs carrier-grade NAT
DPD On, 30 s interval, 5 retries Dead Peer Detection
MTU on cellular WAN 1400 bytes GPRS/UMTS typical cell MTU ~1430, leave headroom
MTU pitfall. ISO-on-TCP S7 frames are usually < 500 bytes, so they fit any cell MTU after IPsec encapsulation. Setting the WAN MTU too low forces fragmentation; setting it too high causes silent drop on the radio bearer. 1400 bytes is the field-tested default.

5. Step-by-Step Configuration via Web-Based Management

Connect a service PC to the M874-3 LAN port, assign it a static IP such as 192.168.1.99/24, and open https://192.168.1.1. Default credentials are admin / admin. Apply the procedure on Site A, then mirror on Site B (swap the role of Local/Remote).

5.1 WAN interface and APN

  1. WBM » Interfaces » Mobile.
  2. Set APN to the value supplied by the mobile operator (Private APN string, e.g. siemens.m2m.private).
  3. Authentication: CHAP (preferred) or PAP. Enter user/password if the SIM requires them.
  4. PDP type: IPv4.
  5. Click Save and Load. The router dials the APN; the WBM status page must show a non-zero WAN IP.

5.2 LAN interface

  1. WBM » Interfaces » Ethernet P1.
  2. Site A: IP 192.168.1.1, mask 255.255.255.0.
  3. Site B: IP 192.168.2.1, mask 255.255.255.0.
  4. Disable DHCP on P1 (S7 controllers must have static IPs).

5.3 Firewall - allow S7 traffic

Before the tunnel can carry S7 traffic the firewall must permit ESP, IKE, NAT-T, and outbound ISO-on-TCP (TCP/102) from the S7 CPU.

# Action From To Service Comment
1 Accept WAN peer WAN local UDP/500 IKEv2
2 Accept WAN peer WAN local UDP/4500 NAT-T
3 Accept WAN peer WAN local ESP (protocol 50) IPsec data
4 Accept LAN (S7 CPU) Remote LAN TCP/102 S7-comm / PUT-GET

5.4 IPsec Phase 1 (IKE_SA)

  1. WBM » Security » IPsec VPN » Phase 1.
  2. Name: S7_SiteB.
  3. Remote endpoint: 10.50.1.6 (Site B fixed SIM IP).
  4. IKE version: IKEv2.
  5. Authentication: Pre-Shared Key. PSK: minimum 32 chars, e.g. 7Hf!9xLq2pVb#rT4zYc&Mn8BwQe6DsUa.
  6. Local ID: 10.50.1.5; Remote ID: 10.50.1.6 (or FQDN if cert-based).
  7. Encryption: AES-256-CBC; Integrity: SHA-256; DH group: 14.
  8. Lifetime: 28800 s. DPD: on, 30 s / 5 retries.
  9. Save.

5.5 IPsec Phase 2 (CHILD_SA)

  1. WBM » Security » IPsec VPN » Phase 2.
  2. Bind to Phase 1 S7_SiteB.
  3. Mode: Tunnel.
  4. Local subnet: 192.168.1.0/24; Remote subnet: 192.168.2.0/24.
  5. Transform: ESP-AES-256-CBC + ESP-SHA256-HMAC (or AES-256-GCM if combined-mode is supported by the firmware).
  6. PFS group: 14.
  7. Lifetime: 3600 s.
  8. Save and activate.

Official reference for the IPsec VPN menu tree and parameter meanings on SCALANCE X/W/M routers (which share the WBM structure with M874-3) is the Siemens TIA Portal Cloud documentation: Configuring IPsec VPN on SCALANCE X/W/M.

5.6 Default route and policy routing

The M874-3 default route points to the cellular interface for Internet-bound traffic. S7 traffic destined for the remote LAN must be steered into the IPsec tunnel via a policy route: WBM » Layer 3 » Static Routes » add route 192.168.2.0/24 via IPsec tunnel S7_SiteB.

6. S7 CPU-to-CPU Communication

Once the IPsec tunnel is up and the firewall permits TCP/102, the two S7 controllers behave as if they were on the same LAN. Choose the protocol family by controller generation:

6.1 S7-1200 / S7-1500 (TIA Portal)

  1. In the device properties of the partner CPU, tick "Permit access with PUT/GET communication from remote partner (PLC, HMI, OPC, ...)" under Connection mechanisms. Without this flag the CPU rejects all PUT/GET requests, regardless of VPN.
  2. Open Instructions » Communication » S7 Communication and drag the PUT / GET block into the active program.
  3. Sample call on Site A (SCL):
    // Site A pulls 16 bytes from Site B DB10 starting at byte 0
    "GET_DB"(REQ := TRUE,
             ID   := 1,
             ADDR := P#DB10.DBX0.0 BYTE 16,
             RD_I := "rxBuf",
             DONE => #done,
             BUSY => #busy,
             ERROR => #err,
             STATUS => #status);
    
  4. Configure the connection in the block header: partner IP 192.168.2.10, local TSAP 01.01, partner TSAP 01.01, connection type S7.

6.2 S7-300 / S7-400 (STEP 7 V5)

  1. Insert an S7 connection in NetPro with partner IP 192.168.2.10 and TSAPs matching both CP configurations.
  2. Use blocks FB15 PUT / FB14 GET from the standard library, or FB12 BSEND / FB13 BRCV for larger payloads (> 32 KB on S7-400).
  3. CP343-1 / CP443-1: enable S7 communication in the CP properties; otherwise the CP blocks ISO-on-TCP at port 102 even with VPN up.
TSAP reminder. The TSAP is two bytes. Convention is Connection number . CPU slot. If both CPUs are slot 1 and the configured connection number is 1 on each side, use 01.01 on both ends.

7. Verification

  1. Tunnel up? WBM » Information » IPsec shows the SAs active. Status: ESTABLISHED for Phase 1, INSTALLED for Phase 2.
  2. Encrypted ping? From a service PC on Site A, ping the Site B S7 CPU (192.168.2.10). If the IPsec tunnel is up the ping succeeds. Run tracert 192.168.2.10 on Windows or traceroute on the M874-3 CLI to confirm the path goes through the IPsec interface.
  3. S7 online? TIA Portal » Online » Accessible nodes must list the remote CPU under its LAN IP.
  4. Application data? Trigger PUT/GET; monitor DONE rising edge once per request and STATUS = 0000h.
  5. Tunnel counters: WBM » Information » Statistics » IPsec shows the byte counter monotonically increasing in both directions.

8. IPsec State Machine (Simplified)

Idle / Down IKE_SA_INIT IKE_AUTH ESTABLISHED REKEY SA: DH + NONCE AUTH + ID CHILD_SA created lifetime expire

9. Troubleshooting Matrix

Symptom Diagnostic step Likely root cause Remedy
Phase 1 stuck in IKE_SA_INIT WBM » IPsec » Logs UDP/500 blocked by APN or firewall; PSK mismatch; clock skew > 300 s Open UDP/500, re-enter PSK on both sides, set NTP
Phase 1 up, Phase 2 fails Logs show NO_PROPOSAL_CHOSEN Mismatched encryption / DH / PFS proposals Force identical transform set on both peers
Tunnel up but ping fails WBM » Diagnostics » Firewall hits Firewall dropping ESP or TCP/102 Add explicit rules for ESP (proto 50), UDP/4500, TCP/102
Tunnel flaps every few minutes WBM » Mobile statistics Low RSRP, bearer re-selection, NAT-T not negotiated Improve antenna, force LTE/3G lock, enable NAT-T
S7 STATUS = 8304h Online diagnostics of the S7 connection CPU partner TSAP / connection resource unreachable Verify partner TSAP, enable "Permit access with PUT/GET", check CP S7-comm flag
S7 STATUS = 80B1h TIA Portal » Online » Accessible nodes No route to remote LAN because policy route missing Add static route remote_subnet via IPsec
Tunnel up but no application data CLI: show ipsec sa Phase 2 proxy ID mismatch (e.g. /24 vs /32) Match local/remote subnet exactly on both peers
High retransmits on GPRS WBM » Mobile » Radio Cell congestion, weak signal Mount external antenna, use directional Yagi, raise to LOS

10. Security Hardening Notes

  • Replace default admin password on first commissioning (WBM » System » Passwords). Empty default admin/admin allows anyone on the LAN to reconfigure the tunnel.
  • Disable HTTP, enable HTTPS only, and restrict WBM access to the LAN port (WBM » System » HTTP).
  • Restrict management to a single trusted source IP if the LAN has more than the S7 CPU.
  • Rotate PSK every 12 months or after any operator change. Treat the SIM APN password with the same care.
  • Enable syslog forwarding to a central log host for IPsec NEGOTIATION events (WBM » Diagnostics » Syslog).

11. Field-Proven Caveats

  • Two M874-3 units on the same Private APN with the same /30 from the operator will ping even without IPsec. Do not mistake that for a working S7 path; without tunnel encapsulation, public-routable SIMs expose the CPUs to anyone else on the APN.
  • If the operator issues IPv6 PDP, set the IPsec phase 2 to IPv4 only and route IPv6 separately; mixed stacks double the failure modes.
  • Some operators strip ESP. If you see the tunnel come up and immediately drop with ESP_NOT_SUPPORTED, switch to NAT-T (UDP/4500) transport.
  • For S7-1200 firmware < V4.0 the GET/PUT blocks have a bug that aborts on transient GPRS drop. Update the CPU firmware.
  • DPD interval below 10 s burns cellular data budget on keepalives; do not go below 30 s in production.

12. FAQ

Do I really need IPsec if both SIMs are on a Private APN?

Yes. A Private APN is a private IP network but it is still shared with every other customer on that APN. IPsec provides device-to-device authentication and payload confidentiality, which the cellular bearer cannot guarantee. Without IPsec any other APN tenant can route traffic to your SIM IP and reach TCP/102 on the S7 CPU.

Can I use certificates instead of a Pre-Shared Key?

Yes. The M874-3 supports X.509 certificates via PKCS#12 import (WBM » Certificates). Use certificates when you have more than two sites or rotate keys frequently. For two-site brownfield projects PSK is faster to commission.

Which TCP port does S7-communication use across the tunnel?

ISO-on-TCP (S7-comm, PUT/GET, BSEND/BRCV) uses TCP port 102. The M874-3 firewall must allow TCP/102 from the local LAN to the remote LAN over the IPsec interface, and the S7 CPU must permit PUT/GET access in its protection settings.

Why does my tunnel come up but the S7 connection still fails with STATUS 80B1?

STATUS 80B1h means the CPU has no IP route to the partner subnet. On the M874-3 add a static / policy route that puts the remote LAN subnet behind the IPsec tunnel, otherwise return traffic from the CPU is sent to the default WAN route and dropped.

What is the minimum cellular signal for a stable IPsec link?

For UMTS/HSPA the M874-3 should report RSCP ≥ -95 dBm and Ec/No ≥ -9 dB; for LTE (M876-4 class) RSRP ≥ -105 dBm and RSRQ ≥ -12 dB. Below those thresholds DPD will time out, the tunnel will flap, and S7-comm will fail intermittently.

Back to blog