Skip to content

Part 5: Local DNS

The lab server is only reachable by its IP address. In this part you’ll give it a name on your gateway’s DNS server.

src/lab.ts
import * as UnifiNetwork from "@alchemy-unifi/network";
import * as Config from "effect/Config";
import * as Effect from "effect/Effect";
export const Lab = Effect.gen(function* () {
const zone = yield* UnifiNetwork.FirewallZone("lab-zone", { name: "Lab" });
const network = yield* UnifiNetwork.Network("lab", {
management: "GATEWAY",
name: "Lab",
vlanId: 50,
enabled: true,
cellularBackupEnabled: false,
internetAccessEnabled: true,
isolationEnabled: false,
zone: zone,
ipv4Configuration: {
autoScaleEnabled: false,
hostIpAddress: "192.168.50.1",
prefixLength: 24,
dhcpConfiguration: {
mode: "SERVER",
ipAddressRange: { start: "192.168.50.100", stop: "192.168.50.250" },
leaseTimeSeconds: 86400,
pingConflictDetectionEnabled: true,
},
},
});
yield* UnifiNetwork.WifiBroadcast("lab-wifi", {
type: "STANDARD",
name: "Lab",
enabled: true,
network,
securityConfiguration: {
type: "WPA2_PERSONAL",
passphrase: yield* Config.Redacted("LAB_WIFI_PASSPHRASE"),
fastRoamingEnabled: false,
},
broadcastingFrequenciesGHz: [2.4, 5],
hideName: false,
clientIsolationEnabled: false,
multicastToUnicastConversionEnabled: false,
uapsdEnabled: false,
channel2gLockedTo6: false,
dtimPeriod2gLockedTo3: false,
advertiseDeviceName: false,
arpProxyEnabled: false,
bssTransitionEnabled: true,
});
yield* UnifiNetwork.DnsPolicy("lab-server", {
type: "A_RECORD",
enabled: true,
domain: "server.lab.home.arpa",
ipv4Address: "192.168.50.10",
ttlSeconds: 300,
});
return { network, zone };
});

Devices that use the gateway for DNS now resolve server.lab.home.arpa to 192.168.50.10. home.arpa is the domain set aside for home networks, so it never clashes with a real one.

A CNAME points another name at the same server:

src/lab.ts
import * as UnifiNetwork from "@alchemy-unifi/network";
import * as Config from "effect/Config";
import * as Effect from "effect/Effect";
export const Lab = Effect.gen(function* () {
const zone = yield* UnifiNetwork.FirewallZone("lab-zone", { name: "Lab" });
const network = yield* UnifiNetwork.Network("lab", {
management: "GATEWAY",
name: "Lab",
vlanId: 50,
enabled: true,
cellularBackupEnabled: false,
internetAccessEnabled: true,
isolationEnabled: false,
zone: zone,
ipv4Configuration: {
autoScaleEnabled: false,
hostIpAddress: "192.168.50.1",
prefixLength: 24,
dhcpConfiguration: {
mode: "SERVER",
ipAddressRange: { start: "192.168.50.100", stop: "192.168.50.250" },
leaseTimeSeconds: 86400,
pingConflictDetectionEnabled: true,
},
},
});
yield* UnifiNetwork.WifiBroadcast("lab-wifi", {
type: "STANDARD",
name: "Lab",
enabled: true,
network,
securityConfiguration: {
type: "WPA2_PERSONAL",
passphrase: yield* Config.Redacted("LAB_WIFI_PASSPHRASE"),
fastRoamingEnabled: false,
},
broadcastingFrequenciesGHz: [2.4, 5],
hideName: false,
clientIsolationEnabled: false,
multicastToUnicastConversionEnabled: false,
uapsdEnabled: false,
channel2gLockedTo6: false,
dtimPeriod2gLockedTo3: false,
advertiseDeviceName: false,
arpProxyEnabled: false,
bssTransitionEnabled: true,
});
yield* UnifiNetwork.DnsPolicy("lab-server", {
type: "A_RECORD",
enabled: true,
domain: "server.lab.home.arpa",
ipv4Address: "192.168.50.10",
ttlSeconds: 300,
});
yield* UnifiNetwork.DnsPolicy("lab-files", {
type: "CNAME_RECORD",
enabled: true,
domain: "files.lab.home.arpa",
targetDomain: "server.lab.home.arpa",
ttlSeconds: 300,
});
return { network, zone };
});
Terminal window
npx alchemy deploy --stage home
Terminal window
nslookup files.lab.home.arpa 192.168.1.1

The answer is server.lab.home.arpa, at 192.168.50.10.

You added local DNS records. Next, in Part 6, you’ll deploy the same lab to a second site.