Switch ports
About 1633 words
The ports subject manages the ports of switches and gateways by name. You name the device and the port the way you named them in the UniFi application, so the camera on the driveway is "Core Switch" "Camera Driveway" and you never look up a port number or a device ID.
The faceplate of a switch, a rename, PoE off and back on, and a power cycle of two ports, all by name.
Address a port
Every ports command takes the device first and the port second.
- A device answers to its name, MAC address or IP address.
- A port answers to its name or its number:
NASand26are the same port on the demo's Core Switch. - Verbs that act on several ports take lists and ranges:
5,6,7,9-12, or a mix such as1-4,NAS.
Quote names that contain spaces. Shell completion fills in device and port names from the controller, which saves the quoting.
See the ports
Without arguments, unifi ports get draws every switch and gateway as its faceplate. With a device, a table of its ports follows the faceplate:
$ unifi ports get "Garage Switch"
╭─ Garage Switch ─────────────────── 4/8 up · PoE 4.4 W ─╮
│ 1 2 3 4 5 6 7 8 │
│ □ ▂ϟ □ □ ▂ ▂ × ▄↑ │
│ │
│ ▄ 1 GbE ▂ 100 FE □ down × disabled ϟ PoE ↑ uplink │
╰────────────────────────────────────────────────────────╯
# NAME STATUS SPEED POE PROFILE NETWORK CONNECTED TO DOWN UP
1 AP Garden Down - auto Trunk Default - - -
2 Camera Garage Up 100 FE auto 4.4 W IoT IoT Camera Garage 33 kbps 2.3 Mbps
3 Port 3 Down - auto All Default - - -
4 Port 4 Down - auto All Default - - -
5 Wallbox Up 100 FE - IoT IoT Wallbox 1 kbps 2 kbps
6 Garage Door Up 100 FE - IoT IoT Garage Door 1 kbps 1 kbps
7 Old Printer Disabled - - All Default - - -
8 Uplink Core Up ↑ 1 GbE - Trunk Default Core Switch 2.3 Mbps 35 kbpsRead the faceplate
The faceplate mirrors the physical layout: two-row switches are drawn in two rows with odd ports on top, and SFP cages sit apart on the right.
| Glyph | Meaning |
|---|---|
▂ ▄ ▆ █ | Link up. The taller the bar, the faster the link, and the legend below the ports names the speeds present. In a color terminal each speed has its own color too. |
□ | No link |
× | Port disabled |
ϟ | The port delivers PoE power |
↑ | The device's uplink |
The header carries the totals: ports up, and the PoE power the device delivers.
Narrow the list
unifi ports get "Core Switch" --poe # ports that deliver power
unifi ports get "Core Switch" --down # ports without link
unifi ports get "Core Switch" 9-12 # a range or a list of ports as a table
unifi ports get --up --output json # every linked port of every device
unifi ports get --filter 'speedMbps < 1000 && up' # links slower than gigabit
unifi ports get --filter 'profile == "IoT"'Filter fields are connectedTo, connector, enabled, fullDuplex, idx, maxSpeedMbps, name, nativeNetwork, poeActive, poeCapable, poeMode, poeWatts, profile, rxBytes, rxRateBps, speedMbps, txBytes, txRateBps, up and uplink.
The speedMbps<1000 filter is a quick way to find a bad cable: a gigabit device that negotiated 100 Mbit/s usually has a damaged pair.
One port in full
$ unifi ports get "Core Switch" NAS
NAS port 26 of Core Switch ● Up
Port Link
Number 26 Status Up
Connector SFP+ Enabled yes
Profile All Speed 10 GbE
Native network Servers Max speed 10 GbE
Connected to NAS Duplex full
Power over Ethernet Traffic
Capable no Down 38.4 Mbps
Up 4.2 Mbps
Sent 1.8 TB
Received 912 GBControl PoE
Start with the PoE budget of the whole site. --poe without a device lists, for every switch, the power it delivers and what each port draws, the hungriest first:
$ unifi ports get --poe
Core Switch 68.9 W in use across 6 ports
# NAME DRAW MODE CONNECTED TO
18 Office Switch ████████████ 38.5 W auto Office Switch
17 AP Living Room ████░░░░░░░░ 14.2 W auto AP Living Room
10 Camera Driveway ██░░░░░░░░░░ 5.3 W auto Camera Driveway
9 Camera Front Door █░░░░░░░░░░░ 4.1 W auto Camera Front Door
11 Camera Backyard █░░░░░░░░░░░ 3.9 W auto Camera Backyard
12 Intercom █░░░░░░░░░░░ 2.8 W auto Intercom
Garage Switch 4.4 W in use across 1 port
# NAME DRAW MODE CONNECTED TO
2 Camera Garage █░░░░░░░░░░░ 4.4 W auto Camera Garage
Office Switch 26.2 W in use across 3 ports
# NAME DRAW MODE CONNECTED TO
2 AP Office ██████░░░░░░ 17.8 W auto AP Office
6 Raspberry Pi Lab ██░░░░░░░░░░ 4.9 W auto Raspberry Pi Lab
5 Desk Phone █░░░░░░░░░░░ 3.4 W auto Desk PhoneThen change a port:
$ unifi ports poe "Core Switch" "Camera Driveway" off --yes
✓ Turned PoE off on port 10 "Camera Driveway" of Core Switch.
$ unifi ports poe "Core Switch" "Camera Driveway" off --yes
● PoE already is off on port 10 "Camera Driveway" of Core Switch.
$ unifi ports poe "Core Switch" 10 auto
✓ Turned PoE on (auto) on port 10 "Camera Driveway" of Core Switch.The last argument is the action:
| Action | Effect |
|---|---|
on, auto | Supply power when a PoE device asks for it |
off | Stop supplying power |
cycle | Cut the power for a moment, which restarts the powered device |
Cutting power to a port that is powering something asks for confirmation, because the camera, phone or access point behind it goes dark. Turning power on doesn't ask, and neither does a port that already is in the wanted mode: that one is left alone, with a notice and exit code 0.
Power-cycling is common enough to have its own verb, and it takes ranges like the others:
$ unifi ports cycle "Core Switch" 9-10 --yes
✓ Power-cycled ports 9-10 of Core Switch.
→ The powered device needs a minute to boot.Change a port
unifi ports set changes one port; pass a flag for everything that should change, and whatever you leave out stays as it is.
$ unifi ports set "Core Switch" 8 --name "Camera Porch" --profile IoT
✓ Renamed port 8 on Core Switch to "Camera Porch".
Assigned the port profile "IoT" to port 8 on Core Switch.| Flag | Changes |
|---|---|
--name <name> | The port's name |
--profile <profile> | The port profile; list them with unifi port-profiles get |
--network <network> | The native (untagged) network |
--poe <mode> | The PoE mode: auto, off, passthrough or 24v |
--enable, --disable | Whether the port is on |
unifi ports rename "Core Switch" 5 Printer is the short form of set --name.
A port profile bundles the native network, the tagged networks, PoE and isolation, and it's the better tool when several ports should behave the same. Create profiles with unifi port-profiles create; the settings guide covers that subject.
Turn ports off and on
unifi ports disable "Core Switch" Spare
unifi ports disable "Core Switch" 20-24 --yes
unifi ports enable "Garage Switch" "Old Printer"Disabling a port that has link or delivers power asks for confirmation, since whatever is plugged in goes offline. A port nothing hangs on is disabled without a question, and a port that already is disabled is left alone.
The uplink guard
Disabling the port a device reaches the network through cuts the device off from its controller, and then nobody can turn the port back on remotely. unifi-cli refuses:
$ unifi ports disable "Core Switch" 25 --yes
✗ Port 25 "Uplink UDM" is the uplink of "Core Switch", so the command would cut the device off from the
network.
Advice:
• Once the uplink is down the controller cannot reach "Core Switch" to turn it back on; someone has to do
that on site.
• Pass `--force` if you really want to disable the uplink.--yes doesn't override this; only --force does. The guard covers ports disable and ports set --disable. It doesn't cover a port that carries another switch's uplink: disabling port 18 of Core Switch takes Office Switch offline, and the confirmation prompt is the only thing between you and that.
Script it
Every ports command prints JSON with --output json, including the ones that change something. unifi ports get <device> prints an array of ports; without a device it prints one object per device, each with device, mac, model and its ports.
The commands that change something print an action result:
$ unifi ports poe "Core Switch" "Camera Driveway" off --yes --output json
{
"status": "ok",
"action": "poe",
"target": {
"kind": "port",
"name": "Core Switch",
"id": "608f48ee-fd3b-4ad9-a806-4a0e4feee429",
"mac": "02:15:6d:00:01:02",
"ports": [
10
]
},
"changes": [
"Turned PoE off on port 10 \"Camera Driveway\" of Core Switch."
],
"message": "Turned PoE off on port 10 \"Camera Driveway\" of Core Switch."
}status is ok when something changed, unchanged when the port already was in the wanted state, and failed otherwise. The output reference describes the shape, which every action of unifi-cli shares.
A nightly job that power-cycles every camera port could look like this:
#!/usr/bin/env bash
set -euo pipefail
unifi --context home ports get "Core Switch" --poe --output json \
| jq -r '.[] | select(.profile == "IoT") | .idx' \
| paste -sd, - \
| xargs -I{} unifi --context home ports cycle "Core Switch" {} --yesPort changes go through the controller's internal API, because the official API offers the power-cycle action only. They are verified against the mock controller, not yet against hardware, so try a change on a spare port first.
The same thing in the shell
If you've configured switches on a serial console, unifi shell may feel more natural for port work:
demo/Default> configure terminal
demo/Default(config)# interface "Core Switch" 8
demo/Default(config-if:Core Switch/Port 8)# description Camera Porch
demo/Default(config-if:Core Switch/Camera Porch)# poe autoSee the shell guide.
