S7-1200 VPN Access via Scalance M874-3: Firewall Fix

David Krause13 min read
S7-1200SiemensTroubleshooting
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

Overview

The S7-1200 CPU 1215C is frequently deployed in remote sites that must be commissioned, monitored, or reprogrammed over a public or cellular backhaul. The SCALANCE M874-3 (Siemens order number 6GK5874-3AA00-2AA2, variants exist for UMTS and LTE) is a compact industrial cellular router with integrated IPsec VPN endpoint, designed for exactly this use case. A common fault symptom is that ICMP ping between the engineering station and the CPU succeeds through the tunnel, yet TIA Portal cannot go online, the program cannot be loaded, and the Web server of the CPU returns no page. The root cause in nearly every case is not the VPN tunnel itself (which is implicitly proven by working ping) but a combination of (a) firewall rules inside the SCALANCE M874-3 and Windows firewall on the engineering station, (b) IP subnet boundary mismatches that block the higher-layer protocols, and (c) the CPU's Web server and S7 communication ports not being explicitly allowed through the Security settings of the cellular router.

This reference walks through the layered troubleshooting path, presents the exact TCP/UDP port matrix that must be permitted, and shows how to verify each protocol path independently. The same logic applies to the S7-1500 family; the official TIA Portal documentation on creating a VPN tunnel between S7-1500 stations describes the conceptual model that this article extends to the S7-1200 with the SCALANCE M874-3.

Reference Architecture

The reference deployment described in the source case has the following topology:

  • Remote site (Server side): CPU 1215C → Ethernet → SCALANCE M874-3 (configured as VPN server, IPsec endpoint, public/operator-supplied SIM address). The CPU's PROFINET interface and the M874-3 LAN port are in the same /24 subnet (e.g. 192.168.1.0/24). CPU default IP: 192.168.0.1 or a project-assigned address inside that subnet.
  • Engineering site (Client side): Engineering PC → Ethernet → SCALANCE M874-3 (configured as VPN client). The PC and the M874-3 LAN port are in a second subnet (e.g. 192.168.2.0/24).
  • Transport: Cellular (UMTS/LTE) bearer, IPsec ESP tunnel in tunnel mode, IKEv1 or IKEv2 with PSK or certificate authentication.

The IPsec tunnel terminates on the WAN (mobile) side of each M874-3, while the engineering traffic is carried inside the encrypted tunnel to the remote LAN. The reference VPN setup model for S7-1500 stations documented in the TIA Portal manual collection uses an analogous CP 1543-1; the M874-3 substitutes the same role with a different configuration UI (Web Based Management, WBM).

Prerequisites

  1. Firmware on M874-3: Use the latest released firmware for 6GK5874-3AA00-2AA2 from the Siemens Industry Online Support. Older firmware versions had bugs in IPsec NAT-Traversal that prevented ESP-UDP encapsulation when both peers were behind mobile NAT.
  2. CPU 1215C firmware: V4.2 or later is recommended to match TIA Portal V16+ project settings; the Web server functionality is present from firmware V2.0 onward.
  3. TIA Portal: V15.1 or later on the engineering station, matching the project version used to program the CPU.
  4. Valid SIM and APN: With public APN, the M874-3 receives a dynamic WAN IP. With private APN, the operator provides a static or pseudo-static IP; document the IP plan before commissioning.
  5. Web server activation in the CPU: In TIA Portal, project tree → CPU → Properties → Web server, tick Enable Web server on this module, choose HTTP only (port 80), HTTPS only (port 443), or both, and assign user rights to at least the Read role. Compile and download the configuration; the Web server is only active after the new hardware configuration is loaded.
Critical commissioning note: TIA Portal's "Go online" search reaches the CPU using a directed UDP/TCP broadcast on the local subnet, and the S7 protocol uses a connection-oriented ISO-on-TCP or TCP channel on port 102. ICMP is a stateless, low-privilege probe and is frequently the only protocol that survives a default-deny firewall rule. Always treat "ping works" as necessary but not sufficient evidence of full connectivity.

Step 1: Verify the IP Plan and Subnet Boundaries

The first observation in the field report was that the original 255.255.255.0 subnet mask forced two distinct subnets to be routed explicitly. While the M874-3 does support static routes, a far simpler architecture is to keep both LAN segments inside a common 255.255.0.0 (/16) or to define explicit routes in both M874-3 instances.

Side Device IP address Mask Notes
Server LAN CPU 1215C PROFINET interface 192.168.1.10 255.255.255.0 Project-assigned, must be unique on the LAN
Server LAN M874-3 LAN port 192.168.1.1 255.255.255.0 Default gateway for the CPU
Client LAN Engineering PC 192.168.2.20 255.255.255.0 Static IP recommended for VPN client peer
Client LAN M874-3 LAN port 192.168.2.1 255.255.255.0 Default gateway for the engineering PC
WAN Both M874-3 mobile interfaces Assigned by operator n/a Verify APN settings; document public/operator IP

Once the IP plan is fixed, the M874-3 must contain a static route from the client subnet (192.168.2.0/24) to the tunnel interface, and vice versa. In the M874-3 WBM this is configured under Layer 3 → Static Routes; the gateway for the remote subnet is the tunnel's virtual IP (assigned inside the IPsec configuration as the "Remote virtual IP" or "Inner IP").

Step 2: Build the IPsec Tunnel

Open the WBM of the server-side M874-3 (default address https://192.168.1.1, default user admin). Navigate to Security → VPN → IPsec → Connections and create a new connection profile:

  1. Connection type: Remote (client-to-site).
  2. Authentication: Pre-Shared Key (PSK) for first commissioning, certificate for production. The PSK must be at least 32 characters of random data per RFC 4303 guidance.
  3. IKE version: IKEv2 preferred (RFC 7296); fall back to IKEv1 only if the operator's APN interferes with IKEv2 cookie exchange.
  4. Phase 1 (IKE SA): AES-256 / SHA-256 / DH group 14, lifetime 86400 s.
  5. Phase 2 (ESP SA): AES-256 / SHA-256, lifetime 28800 s, perfect forward secrecy enabled.
  6. Local ID / Remote ID: Use FQDN or User-FQDN ID type, not IP, because both peers are behind mobile NAT.
  7. NAT-Traversal: Enabled (forces UDP encapsulation on port 4500).
  8. DPD (Dead Peer Detection): Enabled, 30 s interval, 5 retries.

On the client-side M874-3, mirror the configuration: enter the server's public FQDN or IP as the remote gateway, paste the same PSK, and match every algorithm. Once saved, the WBM should report Phase 1 & 2 established within 10 s. Ping from the engineering PC to 192.168.1.10 will then succeed. If it does not, the problem is at the IPsec layer, not at the firewall layer, and you must check the operator's port restrictions: most cellular APNs allow only UDP/500, UDP/4500, and ESP (protocol 50). Some APNs block ESP entirely; in that case IPsec must operate in NAT-T mode exclusively.

Step 3: Configure Firewall Rules on the M874-3

This is the decisive step. By default, the SCALANCE M874-3 ships with a stateful firewall that blocks all inbound traffic from the VPN tunnel toward the LAN except for connections that match an explicit rule. The ping is permitted because ICMP echo is implicitly allowed by the default ICMP pass-through rule (a common SCALANCE default), but TCP services are not. You must add a dedicated firewall rule for each protocol the CPU must expose.

M874-3 firewall rules for S7-1200 access
Service Protocol Port Source Destination Action
TIA Portal S7 communication TCP 102 Client LAN / engineering PC CPU 1215C ACCEPT
Web server (HTTP) TCP 80 Client LAN / engineering PC CPU 1215C ACCEPT
Web server (HTTPS) TCP 443 Client LAN / engineering PC CPU 1215C ACCEPT
HMI communication (optional) TCP 102 HMI panels CPU 1215C ACCEPT
OPC UA server (CPU V4.4+) TCP 4840 OPC clients CPU 1215C ACCEPT
SNMP (optional) UDP 161 NMS station CPU 1215C ACCEPT
IPsec IKE UDP 500 Peer M874-3 WAN Local WAN ACCEPT
IPsec NAT-T UDP 4500 Peer M874-3 WAN Local WAN ACCEPT

In the WBM, these rules live under Security → Firewall → IPv4 Rules. Apply rules in order of specificity (specific service first, generic deny last). Commit with Save → To device and survive reboot; live changes do not persist across power-cycles without this final commit.

Security warning: Do not set the source to "any" on TCP/102. Port 102 is the S7 protocol port and is the same channel used for unauthorized read/write attacks. Restrict the source to the engineering station's IP or, better, to the inner tunnel address of the client-side M874-3.

Step 4: CPU Web Server and TIA Portal Reachability Settings

Even with the tunnel up and the M874-3 firewall open, the CPU itself performs a second layer of filtering:

  1. In the CPU's properties → Protection & Security → Connection mechanisms, ensure Permit access with PUT/GET is enabled if you intend to use that mechanism; Web server access is independent.
  2. In Web server → User management, define at least one user with the Read role (default user admin is preconfigured but with full rights; the password must be set, otherwise the Web server refuses all browser logins).
  3. Set the CPU's Time of day synchronisation; the Web server HTTPS certificate validity is checked against the CPU clock and an out-of-range clock will block browser logins even when the page is reachable.
  4. Under Web server → Automatic update, enable Enable automatic update of the Web pages only after the first successful page load; otherwise stale HTML can mask the underlying reachability status.

Step 5: Windows Firewall on the Engineering Station

TIA Portal's online services are split across several executables (S7PCT, S7WscanX, dotnet for OPC UA, the Siemens.Automation.Portal host). A default Windows 10/11 firewall profile can block the outbound side of the connection. Open Windows Defender Firewall with Advanced Security and add the following outbound rules:

  • Allow %ProgramFiles%\Siemens\Automation\Portal V1x\bin\S7PCT.exe on TCP any.
  • Allow %ProgramFiles%\Siemens\Automation\Portal V1x\bin\S7WscanX.exe on UDP/TCP any.
  • Allow System on TCP 102 outbound (this is the channel S7Comm uses once the connection is established).

If the engineering station is on a corporate domain, group policy may override these rules; verify with gpresult /h gpresult.html and check the applied firewall policy.

Troubleshooting Matrix

Symptom-to-cause matrix for S7-1200 over SCALANCE M874-3 VPN
Symptom First verification Most likely cause Fix
Ping from PC to CPU fails WBM → IPsec → Status Phase 2 not established, or no static route on the M874-3 Re-check PSK, IKE IDs, lifetime. Add static route to 192.168.1.0/24 via the tunnel's inner IP.
Ping works, Web server URL times out telnet 192.168.1.10 80 from PC M874-3 firewall blocks TCP 80 / 443 Add ACCEPT rules for TCP 80 and TCP 443 from the engineering PC to the CPU.
Ping works, TIA Portal "Go online" fails with "connection to partner could not be established" telnet 192.168.1.10 102 from PC M874-3 firewall blocks TCP 102, or Windows firewall blocks outbound TCP 102 Add ACCEPT rule for TCP 102 on both sides.
Web server returns HTTP 401/403 Browser developer tools → Network CPU user not configured, or HTTPS certificate rejected by clock skew Create Web server user in TIA project, download configuration, sync CPU time.
Web server loads, but TIA Portal still cannot go online TIA Portal &rquo Diagnostics → Online → Accessible nodes Routing asymmetry: M874-3 sends return traffic on wrong SA Disable IPsec anti-replay window mismatch by matching lifetime / PFS settings on both M874-3.
Tunnel flaps every 5-10 min WBM → Logs → IKE DPD timeout, cellular NAT re-binding Reduce DPD interval to 10 s, enable IKEv2 re-keying, or assign static APN IP.

Step-by-Step Verification Procedure

  1. Layer 1 - Physical and link: On the engineering PC, ping -t 192.168.2.1 (the local M874-3). Should reply in < 1 ms. Loss ⇒ check Ethernet cable and PC IP.
  2. Layer 2 - Tunnel: From PC, ping 192.168.1.1 (the remote M874-3 LAN). Should reply in 30-300 ms over LTE. Loss ⇒ check IPsec status in WBM.
  3. Layer 3 - CPU reachability: From PC, ping 192.168.1.10. Should reply. Loss with step 2 ok ⇒ static route missing on the remote M874-3.
  4. Layer 4 - S7 port: From PC, Test-NetConnection 192.168.1.10 -Port 102 (PowerShell) or telnet 192.168.1.10 102. TcpTestSucceeded: True ⇒ firewall open.
  5. Layer 5 - Web server: From PC browser, navigate to http://192.168.1.10. The Siemens landing page should appear. If browser shows "connection refused" while step 4 succeeds ⇒ Web server is not activated or compiled into the CPU project.
  6. Layer 6 - TIA Portal: Online → Accessible devices → show all accessible devices. The CPU should appear with its MAC and IP. Double-click to go online. If TIA reports "target device not reachable" while steps 1-5 all succeed ⇒ TIA Portal version mismatch with CPU firmware; upgrade TIA to match or, less preferably, downgrade the CPU firmware.

Advanced: Avoid Subnet Boundary Pitfalls

The contributor's observation about the subnet mask is technically a routing statement, not a firewall statement. If the engineering PC is on 192.168.2.0/24 and the CPU on 192.168.1.0/24, the PC's default gateway (192.168.2.1, the client M874-3) must know how to reach 192.168.1.0/24. The M874-3 achieves this with a static route entry of the form:

ip route 192.168.1.0 255.255.255.0 <tunnel-inner-ip-of-remote-m874>

If the engineering PC itself is in the same /24 as the remote CPU (e.g. both 192.168.1.0/24) but the PC's adapter does not have a route to the remote LAN, TIA Portal will fail to discover the CPU. The most robust solution is to give each M874-3 a LAN address in a separate /24, configure static routes in each, and keep the engineering PC in its own /24 with a default gateway pointing to the local M874-3.

Advanced: Securing the Tunnel in Production

After the engineering channel is proven, harden the deployment:

  • Replace the PSK with X.509 certificates issued by an internal CA; distribute via SCEP or by manual import.
  • Restrict the M874-3 firewall source to the engineering station's static tunnel address, not to a subnet.
  • Disable HTTP (port 80) on the CPU Web server; keep HTTPS only and install a CA-signed certificate into the CPU.
  • Enable the CPU's Access protection (CPU properties → Protection → Know-how protection and copy protection) to prevent program extraction even if the tunnel is compromised.
  • Enable logging on both M874-3 instances and forward to a central syslog server for audit trail.

Diagnostic Reference: Key Ports and Protocols

Port Protocol Function Required for
TCP 102 S7Comm / ISO-on-TCP Online, download, HMI TIA Portal, WinCC, HMI panels
TCP 80 HTTP CPU Web server (unencrypted) Web server, S7-Graph HTML views
TCP 443 HTTPS / TLS CPU Web server (encrypted) Web server with TLS
TCP 4840 OPC UA Binary OPC UA server (CPU V4.4+) OPC UA clients
UDP 161 SNMP Network management Optional NMS
UDP 500 IKE IPsec key exchange VPN tunnel establishment
UDP 4500 NAT-T IPsec ESP-in-UDP encapsulation VPN through cellular NAT
IP proto 50 ESP IPsec encrypted payload VPN through public IP

Why does ping work through the SCALANCE M874-3 VPN but the Web server and TIA Portal do not?

ICMP echo is typically permitted by the M874-3's default firewall policy, while TCP services (port 80, 443, 102) are blocked unless an explicit ACCEPT rule exists. Add firewall rules for TCP 80/443 (Web server) and TCP 102 (S7 communication) from the engineering station's IP to the CPU's IP, and verify that the CPU's Web server is activated and a user is configured in the TIA project.

Which TCP port does TIA Portal use to reach a CPU 1215C?

TIA Portal uses TCP port 102 (ISO-on-TCP and TCP variants of the S7 protocol) for online access, program download, and HMI data exchange. This port must be permitted through every firewall on the path, including the M874-3, the Windows firewall on the engineering PC, and any corporate firewall.

What subnet mask is recommended when the two SCALANCE M874-3 LANs are in different ranges?

Use 255.255.255.0 (/24) on each side with non-overlapping network IDs (e.g. 192.168.1.0/24 and 192.168.2.0/24), and configure explicit static routes on both M874-3 instances pointing the remote subnet to the tunnel's inner IP. Avoid 255.255.0.0 unless the entire network is under your administrative control; overlapping /16 networks with managed switches elsewhere will produce unpredictable ARP behaviour.

Does the CPU 1215C Web server require any specific TIA Portal settings?

Yes. In the device configuration, enable Web server on this module, choose HTTP and/or HTTPS, create at least one user under User management with a password and a role, compile the hardware configuration, and download it to the CPU. The Web server becomes active only after the download; an older configuration in the CPU will not enable it.

Why does my VPN tunnel drop every few minutes over cellular?

Cellular carriers frequently re-bind NAT sessions when the mobile IP changes, even if the IP lease appears stable. Enable IPsec DPD (Dead Peer Detection) at 10-30 s intervals, prefer IKEv2 with re-keying, and request a static or pseudo-static IP from the operator. If the APN blocks ESP (protocol 50), force NAT-Traversal so the tunnel uses UDP 4500, which is always permitted.

Back to blog