Problem Overview
Connecting an OPC UA client (Kepware, UA Expert, TIA Portal, custom SCADA) to the embedded OPC UA server of a SIMATIC S7-1200 CPU across a WAN link is a frequent requirement for remote service, telemetry, and inter-site SCADA. LAN operation typically succeeds without manual intervention. Once the OPC UA client and the CPU are placed on different IP networks, however, the session fails during the TCP transport, ServiceHello, or OpenSecureChannel step even though local authentication works fine.
The most common cause is a missing Use IP router setting on the S7-1200 CPU. With this option disabled, the CPU treats the configured gateway as unreachable, will not forward any TCP traffic (including OPC UA on port 4840) outside its own subnet, and drops every inbound packet that arrives through the boundary router. A secondary layer of failures usually appears at the WAN router: NAT port-forwarding, SIP/ALG filtering, default-deny firewall rules, or missing outbound return routes. This article covers both layers and the security settings inside TIA Portal required for a stable remote OPC UA link.
OPC UA Server Capability on the S7-1200
The S7-1200 OPC UA server is a licensed, firmware-gated feature. Confirm the prerequisites before chasing a network problem:
| Requirement | Value / Reference |
|---|---|
| Minimum firmware | Firmware 4.4 or higher (per Siemens application note 109781701) |
| Tested firmware in field | FW 4.5 with TIA Portal V17 |
| Supported TIA Portal | V15.1 and later; V17 used in the verified scenario |
| Default endpoint port | TCP 4840 (opc.tcp://<host>:4840) |
| Max sessions / subscriptions | Per CPU type; see TIA Portal "OPC UA > Server > Runtime settings" |
| Supported security policies | None, Basic128Rsa15, Basic256, Basic256Sha256 (signature + encrypt) |
| Authentication modes | Anonymous, Username/Password, Certificate |
The official Siemens documentation step for enabling the server is:
- Select the S7-1200 CPU in the network view or device tree.
- Open Properties > OPC UA > Server.
- Activate Activate OPC UA server.
- Select the runtime license (trial or purchased).
- Configure security policy, authentication, and the exposed tag namespace.
- Compile and download the project to the CPU.
Refer to the Siemens TIA Portal online help: Enabling the OPC UA Server (S7-1200).
Root Cause Analysis
The TCP/IP stack on the S7-1200 follows standard host behavior: a packet destined to an off-subnet address is forwarded to the configured default gateway. The CPU does not implement proxy ARP or automatic gateway discovery. If the Use IP router checkbox is not set in TIA Portal (and consequently the gateway IP is empty in the PROFINET interface), the following sequence occurs:
- CPU receives a SYN on TCP 4840 from the boundary router (which has performed NAT/port-forwarding).
- CPU inspects the destination IP (its own public-facing address, mapped to its private IP).
- Stack determines the destination is reachable directly on the local subnet.
- TCP handshake completes (in some firmware versions), but the response cannot be routed back through the gateway because no default route exists.
- The OPC UA client never sees the ServiceHello ACK; the session times out.
When Use IP router is enabled and the gateway IP is correct, the CPU creates a default route, the SYN-ACK travels back through the boundary router, and the OPC UA handshake proceeds normally.
Network Architecture and Addressing
Use the following reference topology when commissioning a remote OPC UA link. The boundary router does double duty: it terminates the ISP-issued public IP and performs 1:1 NAT (or PAT) toward the S7-1200.
IP Plan Template
| Element | Parameter | Example | Notes |
|---|---|---|---|
| S7-1200 PROFINET interface | IPv4 address | 192.168.1.10 | Static, not DHCP |
| S7-1200 PROFINET interface | Subnet mask | 255.255.255.0 | /24 |
| S7-1200 PROFINET interface | Use IP router | Enabled | This is the critical fix |
| S7-1200 PROFINET interface | Router address | 192.168.1.1 | Must be the LAN-side address of the boundary router |
| Boundary router LAN | IPv4 address | 192.168.1.1 | Same subnet as CPU |
| Boundary router WAN | Public IPv4 | 203.0.113.20 | Static or dynamic DNS |
| Boundary router NAT | External port | 4840 | OPC UA default; can be remapped |
| Boundary router NAT | Internal host/port | 192.168.1.10:4840 | 1:1 or PAT |
| Remote client | Endpoint URL | opc.tcp://203.0.113.20:4840 | Host resolves to public IP |
TIA Portal Configuration: Enabling the IP Router
This is the change that resolved the field case. The setting is hidden under the PROFINET interface properties of the CPU.
- Open the S7-1200 project in TIA Portal (V17 or later).
- Select the CPU in the device tree.
- Open Properties > PROFINET interface [X1] > Ethernet addresses.
- Expand IP protocol.
- Tick the checkbox Use IP router.
- Enter the Router address field with the LAN IP of the boundary router (in the example,
192.168.1.1). - Compile the hardware configuration and download to the CPU.
- Power-cycle the CPU if the interface does not pick up the new route immediately on older firmware.
After download, verify on the CPU's web server (http://192.168.1.10) under Diagnostics > Routing table that a default route via 192.168.1.1 is present.
Boundary Router Configuration: Port Forwarding and NAT
The OPC UA server listens on TCP 4840. The boundary router must satisfy three conditions:
- Allow inbound TCP 4840 from the public side (or from the client IP).
-
DNAT / port forward TCP 4840 to
192.168.1.10:4840. - Permit the return path; many consumer routers use connection tracking that handles this automatically once the DNAT rule exists.
Most ISP-grade routers expose a Virtual Server, Port Forwarding, or NAT/PAT page. The minimum rule set:
Service: OPC UA
External port: 4840
Internal host: 192.168.1.10
Internal port: 4840
Protocol: TCP
Source IP: <remote-client-CIDR> (optional, recommended)
Status: Enabled
If the OPC UA client is behind another NAT (e.g., a corporate proxy or 4G carrier-grade NAT), confirm outbound reachability with a quick test:
- From the remote PC, run
telnet 203.0.113.20 4840orTest-NetConnection 203.0.113.20 -Port 4840(PowerShell). - A successful banner / open socket proves the port forward works.
- A timeout indicates either a missing forward, a stateful firewall, or an ISP blocking port 4840 (some carriers block low ports or unusual services).
OPC UA Endpoint and Security Settings
The WAN link does not change the OPC UA security model. Configure the server with at least Basic256Sha256 + SignAndEncrypt when exposing it across an untrusted network. The following table maps each setting to its WAN impact:
| TIA Portal field | Recommended WAN value | Reason |
|---|---|---|
| Security policy | Basic256Sha256 | Strongest profile shipped with S7-1200 OPC UA |
| Message security mode | SignAndEncrypt | Prevents replay/injection from the WAN |
| User authentication | Username + Password | Passwords are salted & hashed server-side |
| Anonymous login | Disabled | Closes unauthenticated access from WAN |
| Server certificate | Self-signed with stable subject | Import into UA Expert trusted store once |
| Discovery URL | opc.tcp://<public-DNS>:4840 | Used by OPC UA clients that resolve the LDS first |
After TIA Portal compile/download, export the server certificate from the CPU web server (OPC UA > Certificates) or directly from TIA Portal, and import it into UA Expert under Settings > Certificate Manager > Trusted Clients / Trusted Servers. Kepware uses the Windows certificate store; install to Trusted People.
Firewall and Windows Configuration
Disable the Windows Defender firewall only as a last resort. A scoped inbound rule is more secure and equally effective:
New-NetFirewallRule -DisplayName "OPC UA Outbound 4840" \
-Direction Outbound -RemotePort 4840 -RemoteAddress 203.0.113.20 \
-Protocol TCP -Action Allow -Profile Any
The matching inbound rule is rarely needed because UA Expert/Kepware initiate as the client. If a SCADA is acting as both client and server (aggregation), add a corresponding inbound rule on the SCADA host.
On the boundary router, log dropped packets to confirm whether the firewall, NAT, or ALG is the offender. A 30-second trace is enough to see whether the SYN reaches the LAN side and whether the SYN-ACK leaves the CPU.
Verification Procedure
Run this checklist top-to-bottom. Each step has an expected outcome; if the outcome is not observed, the failure point is isolated.
-
Local ping. From a LAN PC,
ping 192.168.1.10. Expected: reply < 5 ms. -
CPU web server. Browse to
http://192.168.1.10. Expected: S7-1200 web page loads. -
OPC UA LAN connect. In UA Expert, connect to
opc.tcp://192.168.1.10:4840. Expected: connected, tags browseable. - Routing table. On the CPU web server, Diagnostics > Routing. Expected: default route via 192.168.1.1.
-
Remote port test. From the remote client PC,
Test-NetConnection 203.0.113.20 -Port 4840. Expected: TcpTestSucceeded: True. -
OPC UA WAN connect. In UA Expert on the remote PC, connect to
opc.tcp://203.0.113.20:4840. Expected: connected, same tag tree as LAN. - Sustained read. Add a tag to UA Expert's data view and confirm continuous updates for > 5 minutes. Expected: no disconnects; value updates > 0.5 Hz.
- Security audit. With Wireshark on the remote side, capture the TCP 4840 session and confirm ApplicationUri, EndpointUrl, and certificate subject match the TIA Portal export.
Troubleshooting Matrix
| Observed symptom | Most likely cause | Corrective action |
|---|---|---|
| LAN works, WAN times out at ServiceHello | CPU has no default route (Use IP router disabled) | Enable Use IP router in TIA Portal; enter LAN router IP |
| Telnet on 4840 fails from WAN | Boundary router firewall or missing DNAT | Add port-forward 4840 -> 192.168.1.10; open inbound TCP |
| Telnet succeeds, OPC UA fails to negotiate | SIP/ALG mangles OPC UA binary | Disable ALG on boundary router |
| OPC UA connects, then drops every ~60 s | Session timeout, no keep-alive, or NAT idle expiry | Enable OPC UA keep-alive (publishing interval < NAT idle); reduce NAT idle timer on router |
| BadCertificate error on connect | Server cert not trusted by client | Export CPU cert, import to UA Expert Trusted Servers / Windows Trusted People |
| BadIdentityTokenRejected | User authentication mismatch | Match username/password between TIA Portal user management and UA Expert credentials |
| Connection succeeds, no tags | OPC UA namespace not exposed in TIA Portal | Enable server interface & mark DBs/tags as "accessible from OPC UA" |
| Random disconnect under load | Too many subscriptions / monitored items | Reduce sampling interval or split across clients; respect CPU subscription limits |
| Works from 4G but not corporate VPN | Corporate firewall blocks outbound 4840 | Use a non-standard external port (e.g., 14840) or coordinate with IT for an exception |
Security Hardening Notes
Direct WAN exposure of an industrial protocol is acceptable when compensating controls are in place. The recommended baseline for an S7-1200 OPC UA server exposed on the public Internet:
- Use Basic256Sha256 / SignAndEncrypt only; remove None from the endpoint.
- Disable anonymous authentication; require username/password.
- Restrict the inbound rule to the specific remote client IP or ASN.
- Replace the default self-signed certificate with one signed by an internal CA; rotate annually.
- Enable intrusion detection on the boundary router and alert on TCP 4840 scans.
- Keep the CPU firmware current; OPC UA security fixes ship with firmware updates.
For long-term deployments, a VPN (IPsec or WireGuard) with split tunneling that carries only OPC UA is the most defensible architecture. The direct-WAN pattern documented here is appropriate for service windows, ad-hoc commissioning, or sites without managed VPN infrastructure.
Field Proven Caveats
- Some ISP CPE routers drop long-lived TCP sessions after 5 minutes of idle. Either reduce the OPC UA publishing interval or shorten the router's NAT entry lifetime.
- Carrier-grade NAT (CGNAT) prevents inbound connections from the public Internet. The remote client must be on a routable public IP, or you must deploy on a VPS / VPN concentrator.
- The S7-1200 CPU accepts only one default route. If the LAN has multiple VLANs, the gateway must be the inter-VLAN router address, not the workstation gateway.
- Firmware 4.4 has a known quirk where the IP router change requires a power-cycle to take effect. Firmware 4.5 and later accept the change online.
- If the OPC UA endpoint URL contains the CPU's private IP, regenerate it via TIA Portal's "OPC UA > Server > Endpoint configuration" before going live, otherwise clients will reject the URL mismatch with the certificate.
FAQ
What is the minimum S7-1200 firmware for OPC UA server?
Firmware 4.4 or higher. Firmware 4.5 was used in the verified field case. See the Siemens application note "OPC UA Access to S7-1200 PLC" (entry 109781701).
Why does OPC UA work on LAN but fail on WAN even with the firewall disabled?
The S7-1200 CPU does not accept inbound traffic from outside its subnet unless the Use IP router option is enabled in TIA Portal and a valid gateway IP is configured. Without a default route, the CPU cannot return OPC UA ServiceHello ACKs to the remote client.
Which TCP port does the S7-1200 OPC UA server use?
TCP 4840 by default. The port can be remapped on the OPC UA server endpoint configuration page in TIA Portal, and the boundary router must DNAT the same port.
Is a VPN required for WAN access to the S7-1200 OPC UA server?
A VPN is the most defensible architecture but is not strictly required. With Basic256Sha256 / SignAndEncrypt, certificate trust, and IP-restricted port forwarding, direct WAN access is acceptable for service and commissioning scenarios.
How do I verify that the gateway IP is correct in the CPU?
Open the CPU's web server at http://<CPU-IP>, go to Diagnostics > Routing, and confirm a default route exists via the boundary router's LAN IP (for example 0.0.0.0/0 via 192.168.1.1).
What causes OPC UA sessions to drop after exactly 60 seconds over WAN?
It is typically the NAT idle timer on the boundary router. Reduce the OPC UA publishing interval in the client to below the NAT idle timeout, or raise the router's session lifetime, or use a VPN that maintains the session.
Can SIP ALG on a router break OPC UA?
Yes. SIP ALG inspects TCP payloads looking for SIP headers and frequently corrupts the binary OPC UA handshake. Disable ALG on the boundary router or use a router that does not implement ALG.