Rename WiFi Interface on Ubuntu 20.04

During an experiment, I need to use three WiFi interfaces on a Raspberry Pi running Ubuntu 20.04. In addition to Raspberry Pi's internal WiFi interface, I added two USB WiFi adapters. Three network interfaces showed up in the system (ip link command), and they are named wlan0, wlan1, and wlan2 by default.

I often need to capture packets with tcpdump, and I often have to be type these interface names manually. It isn't easy to remember the purpose of each network interface, so I wanted to rename the interfaces to reflect their role in my application. However, this isn't as easy as it sounds.

🚫 Netplan

Ubuntu 20.04 configures network interfaces using Netplan, so my first thought was: I can write a Netplan configuration that matches network interfaces with their MAC addresses, and assigns the desired name to each network interface.

The config file would look like this:

Get Online in McDonald's with ESP8266

McDonald's used to be the largest chain of free restrooms in the world. Nowadays, they are the largest chain of free WiFi across the United States. Every McDonald's I've been to offers AT&T WiFi services. I can walk in, connect to "attwifi" on my phone, accept the license agreement, and I'm online.

attwifi captive portal in McDonald's

The license agreement page is called a captive portal, a web page displayed to newly connected users before they are granted broader access to network resource. While it's trivial to click through the captive portal on a smartphone, if you are wearing an ESP8266 as a connected jewelry, it would not connect successfully. When I encountered a captive portal in my apartment WiFi, I made an Arduino sketch to send the packets I found through Fiddler, but McDonald's WiFi is different:

  • Each McDonald's store hosts their captive portal on a different domain.
  • The form submission step needs several parameters from the HTML, but does not use cookies.

attwifi captive portal form HTML

Enter WiFi Credentials on ESP32 with One Button

It is considered bad practice to hard-code WiFi credentials into Arduino sketches. Typical recommendations include the WiFiManager library for ESP8266, and SmartConfig for ESP32. Both require the user to have a smartphone to send command to the ESP chip, which otherwise does not have any User Interface (UI).

My ESP32 board is the Heltec WiFi_Kit_32 (paid link) that comes with a 0.96 inch OLED display and a little PRG button connected to pin #0. Can I use these minimal UI to enter WiFi credentials without involving a smartphone?

Heltec WiFi_Kit_32 OLED board with one button

Design with Minimal UI

I took inspiration from Prof Stephen Hawking's computer:

How to Change the MAC Address of ESP8266?

Each ESP8266, like every other WiFi network interface card, comes with a MAC address that identifies itself to the network. Sometimes you want to change the MAC address of an ESP8266. How to do that?

ESP8266 has the built-in MAC address

ESP8266 Arduino core does not provide an API to change ESP8266's WiFi MAC address. While there is a WiFi.macAddress function, it actually retrieves the current WiFi MAC address, instead of setting it. However, Espressif SDK offers an API to change the WiFi STA MAC address:

bool wifi_set_macaddr(uint8 if_index, uint8 *macaddr);

This API is declared in user_interface.h. To get access in this API, you'll need to include this header.

How to Access Gogo Inflight WiFi on American Airlines for Free?

Gogo offers WiFi Internet access on American Airlines domestic flights within United States. The Internet services are provided through Air-To-Ground (ATG) technology: a cellular radio network of over 200 towers in North America points their antennas to the sky; a Gogo-equipped airliner connects to one of these cellular towers, and provides Internet to passengers via WiFi. Pricing for Internet access via Gogo in-flight WiFi starts at USD 4.95 for 30 minutes.

gogoinflight airborne splash page

American Airlines and Gogo also provide inflight personal device entertainment through the same gogoinflight Wi-Fi signal. This service is free of charge, and allows passengers to watch movies and TV episodes on their own smartphones and tablets. Presumably, contents are pre-downloaded to a server located inside the aircraft, and therefore accessing those contents do not consume radio bandwidth.

Rogue One: A Star Wars Story movie provided on gogoinflight

While watching videos are permitted during the flight, Gogo does not want passengers to download these copyrighted movies for watching later at home. Therefore, users must have the Gogo Entertainment app on their mobile devices in order to watch movies. The app is compatible with the Digital Rights Management technology used in the entertainment server, to ensure that the movies can be watched for free, but cannot be (easily) downloaded. But what if the device does not already have the Gogo Entertainment app?

"freewifi" via ESP8266 Captive Portal

Many outdoor places do not have permanent Wi-Fi access points. Occasionally I can get a weak unencrypted WiFi signal from a nearby shop; otherwise, I'll have to face the fact of not having WiFi, and resort to my slow and expensive SIM card for cellular Internet access.

Since I learned that the ESP8266 can serve as a WiFi hotspot, I got an idea. I can make an ESP8266 appear as a Wi-Fi access point (AP), and provide free WiFi to everyone at the outdoor venue. Except that, this is a freewifi prank: I am providing free WiFi, but my WiFi does not offer Internet access.

Screenshots

ESP8266 makes a freewifi WiFi access point SSID:

freewifi SSID

Do Evil with ESP8266: Slow Down the WiFi

While hackers do good most of the time, we occasionally do evil and play a prank. The ESP8266, unlike JSON, allows me to do evil. Thus, I programmed the microcontroller for an evil purpose: slow down the WiFi.

How it Works

802.11 WiFi typically operates in infrastructure mode, where a router acts as an access point, and other hosts (stations) connect to the router on a wireless frequency (a channel).

One property of the wireless channel is that, at any moment, only one party (station or access point) can be transmitting. If multiple senders are transmitting at the same time, the wireless signal will be jammed, and the recipient is unlikely to receive the packet correctly. In this case, the sender would have to transmit the packet again at a later time.

Packets can be transmitted at different speeds on the wireless channel. With 802.11g standard, the maximum speed is 54Mbps, and the minimum is as slow as 1Mbps. The sender (station or access point) dynamically chooses a speed for every packet depending on its perception of wireless channel quality. Usually, we prefer to transmit at a higher speed, so that the wireless channel can be freed as soon as possible for other senders to use. However, if the sender and recipient are far apart, high speed transmission is less likely to succeed because signals can be faded, and a slower speed is necessary to increase the chance of a successful transmission.