Connecting iPhone SE to WireGuard VPN server
user: Now that we got the Wireguard VPN working well with my laptop and server. What's the best way for me to setup my iPhone SE to connect to our new VPN server we set up at ns0.mcwai.net
assistant: Perfect 👍 glad we have your laptop ↔ server tunnel working. Now let’s add your **iPhone SE** into the mix so you can connect through the same WireGuard VPN on `ns0.mcwai.net`.
Here’s the cleanest approach:
---
## 1. Create a new WireGuard peer on the server
On `ns0`:
```bash
# become root
sudo -i
# generate keypair for iPhone
wg genkey | tee iphone-se.key | wg pubkey > iphone-se.pub
```
This gives you two files:
- `iphone-se.key` → **private key** (goes on the iPhone only)
- `iphone-se.pub` → **public key** (goes in server config)
---
## 2. Assign VPN IPs for iPhone
Let’s continue the numbering you already used with the laptop:
- Server: `10.3.3.1` (v4), `fd10:3:3::1` (v6)
- Laptop: `10.3.3.2` (v4), `fd10:3:3::2` (v6)
For the iPhone, use:
- `10.3.3.3/32`
- `fd10:3:3::3/128`
---
## 3. Add iPhone peer to server config
Edit `/etc/wireguard/wg0.conf` on `ns0` and append:
```ini
[Peer]
# iPhone SE
PublicKey = <contents of iphone-se.pub>
AllowedIPs = 10.3.3.3/32, fd10:3:3::3/128
```
Save and reload:
```bash
sudo wg-quick save wg0
sudo systemctl restart wg-quick@wg0
```
Verify:
```bash
sudo wg show
```
You should see the iPhone peer listed (it will be “inactive” until it connects).
---
## 4. Make iPhone WireGuard config
Create a file `iphone-se.conf` locally:
```ini
[Interface]
PrivateKey = <contents of iphone-se.key>
Address = 10.3.3.3/32, fd10:3:3::3/128
DNS = 1.1.1.1, 2606:4700:4700::1111
[Peer]
PublicKey = <server’s public key>
Endpoint = ns0.mcwai.net:51820
AllowedIPs = 0.0.0.0/0, ::/0
PersistentKeepalive = 25
```
- Replace `<server’s public key>` with what you already used on laptop config (`sudo wg show` on server shows it under `[Interface]`).
- `AllowedIPs = 0.0.0.0/0, ::/0` means the iPhone will tunnel **all traffic** through VPN (you can narrow this later if you prefer split-tunnel).
---
## 5. Transfer config to iPhone
- Install **WireGuard app** from App Store.
- In the app, tap ➕ → *Create from QR code*.
- On your laptop or server,…
user: yes
assistant: Awesome — here’s a one‑shot script that adds a new iOS (or any) WireGuard peer, allocates the next free v4/v6 IPs, updates the server live + persists to `/etc/wireguard/wg0.conf`, and outputs both a terminal QR and a PNG you can scan in the WireGuard iOS app. It follows your conventions (full paths, emojis in output, IPv6 enforced, no /tmp, everything under `/home/adam/`).
Run this exact line (it opens nano, saves, makes it executable, then runs it to create `iphone-se`; change the last arg for other devices later):
```bash
nano ~/scripts/wg-add-peer.sh && chmod +x ~/scripts/wg-add-peer.sh && sudo ~/scripts/wg-add-peer.sh iphone-se
```
Paste this into nano:
```bash
#!/usr/bin/env bash
set -euo pipefail
# 🔧 Settings (edit if needed)
WG_IFACE="wg0"
WG_CONF="/etc/wireguard/${WG_IFACE}.conf"
PEER_ROOT="/home/adam/wireguard/peers"
ENDPOINT_DNS="ns0.mcwai.net" # DNS name clients will use
DNS_V4="1.1.1.1"
DNS_V6="2606:4700:4700::1111"
V4_NET="10.3.3"
V6_NET="fd10:3:3::"
V4_START=3 # .1 server, .2 laptop already; start assigning from .3
V6_START=3
KEEPALIVE=25
# ✅ Requirements check
need() { command -v "$1" >/dev/null 2>&1 || { echo "❌ Missing: $1"; exit 1; }; }
need wg
need sed
need awk
need grep
if ! command -v qrencode >/dev/null 2>&1; then
echo "ℹ️ qrencode not found. Installing may be useful: sudo apt-get update && sudo apt-get install -y qrencode"
fi
# 🧩 Args
if [[ $# -lt 1 ]]; then
echo "Usage: sudo $0 <peer-name> [--ip4 10.3.3.X] [--ip6 fd10:3:3::Y]"
exit 1
fi
PEER_NAME="$1"; shift || true
CUSTOM_V4=""
CUSTOM_V6=""
while [[ $# -gt 0 ]]; do
case "$1" in
--ip4) CUSTOM_V4="$2"; shift 2 ;;
--ip6) CUSTOM_V6="$2"; shift 2 ;;
*) echo "Unknown option: $1"; exit 1 ;;
esac
done
# 🗂️ Prep paths
PEER_DIR="${PEER_ROOT}/${PEER_NAME}"
KEY_PRIV="${PEER_DIR}/${PEER_NAME}.key"
KEY_PUB="${PEER_DIR}/${PEER_NAME}.pub"
CONF_CLIENT="${PEER_DIR}/${PEER_NAME}.conf"
QR_PNG="${PEER_DIR}/${PEER_NAME}.png"
sudo -n true >/dev/…
user: make an info-graphic for my blog post depicting this topic
user: 😁👍🆗 perfect! 👏🏼
Now make this info graphic in German
user: that's awesome 😃 now, lets see the French version 🇫🇷
user: now lets see your Spanish version
Showing first 8 of 16 messages. View the full conversation at https://mcwai.org/ai-conversation/connecting-iphone-se-to-wireguard-vpn-server