Gateways, peers & protected traffic

What a VPN tunnel does

Lesson 1 of 20 · 10 min · Module 1: A private path over a public network

Two offices are connected to the internet, not to each other. A VPN tunnel lets their private networks talk as if a cable ran between them, and hides what they say from everyone in between.

Start this lesson →

Free. No installation: you write and run the code in your browser, and it is checked automatically.

By the end, you’ll be able to…

  • Explain what the two gateways of a site-to-site VPN do
  • Name the peer and the protected networks of a tunnel
  • Tell protected traffic from ordinary internet traffic

The idea

A site-to-site VPN runs between two gateways, usually the firewalls of the two sites. Each gateway needs to know two things before anything else: who is the other end (the peer, a public address) and which traffic belongs in the tunnel (a selector: the local network and the remote network).

peer 192.0.2.77
selector 10.0.1.0/24 10.2.0.0/24

01Follow a packet into the tunnel

A PC at the head office sends a packet to a server at the branch, 10.0.1.25 to 10.1.0.8. Those are private addresses, which the internet does not route. The head-office gateway encrypts the whole packet and wraps it in a new one, addressed from its own public address to the public address of the branch gateway. The branch gateway unwraps and decrypts it and delivers the original.

02Only selected traffic is protected

The selector says which packets get this treatment: here, traffic between 10.0.1.0/24 and 10.1.0.0/24. A packet from the same PC to a public website does not match, so it leaves for the internet as usual. In this lab the Output tab shows each test packet as TUNNEL, CLEAR or DROP.

03Peer and protected networks on real devices

Every product asks for the same two facts, under its own names.

# FortiGate
config vpn ipsec phase1-interface
    edit "to-branch"
        set interface "wan1"
        set remote-gw 198.51.100.2
    next
end
config vpn ipsec phase2-interface
    edit "to-branch-p2"
        set phase1name "to-branch"
        set src-subnet 10.0.1.0 255.255.255.0
        set dst-subnet 10.1.0.0 255.255.255.0
    next
end

# Huawei USG: the peer, and an ACL that selects the traffic
ike peer branch
 remote-address 198.51.100.2
acl number 3000
 rule 5 permit ip source 10.0.1.0 0.0.0.255 destination 10.1.0.0 0.0.0.255

# Cisco IOS (crypto map)
ip access-list extended VPN-TRAFFIC
 permit ip 10.0.1.0 0.0.0.255 10.1.0.0 0.0.0.255
crypto map VPN 10 ipsec-isakmp
 set peer 198.51.100.2
 match address VPN-TRAFFIC

Your turn

The tunnel to the branch office is almost configured. Add the two missing lines: the peer (the branch gateway is at 198.51.100.2) and the selector for traffic between the head-office network 10.0.1.0/24 and the branch network 10.1.0.0/24.

What the checks look for

  • The gateway talks to the branch gateway
  • The tunnel is up, with the selector exactly as configured
  • Traffic between the two offices is encrypted, in both directions
  • Ordinary internet traffic stays outside the tunnel
Try it in the editor →

Take this with you

A site-to-site tunnel is defined by its two gateways and by the networks whose traffic it protects.

Go a little further

Swap the two networks in your selector and run the lab. Read the stage at which the negotiation fails, and why the order matters.

Learn VPN & IPsec Foundations for free

20 short lessons with real code and instant checks.

See the whole course →