Downloading an eSIM profile through a USB Modem without a second network device
Ironically, activating an eSIM requires an internet connection. Usually a USB modem is used in cases where another internet access isn't available. So if you need to get a new eSIM, how can you download it? Let's see how to download an eSIM profile on a USB modem without another network device. This requires having a working eSIM profile, but can help to download a new eSIM before an old eSIM expires. (A JMP eSIM is a great choice for a fallback eSIM because it doesn't expire.)
Overview
Stop ModemManager from accessing the USB modem
- Use qmicli to establish a temporary network connection via the USB modem
- Configure the temporary network connection
- Download the eSIM profile
Restart ModemManager
Instructions
On a system with a functioning eSIM, stop the ModemManager from accessing the USB modem:
sudo systemctl stop ModemManager
The system will loose internet connectivity.
- Find the USB modem's interface name:
sudo qmicli --device=/dev/cdc-wdm0 --device-open-proxy --get-wwan-iface
Keep this interface name handy and use it in place of wwp0 below.
The following steps are only necessary if the file /sys/class/net/wwp0s20u1u4u2i4/qmi/raw_ip doesn't already contain "Y"
sudo ip link set dev wwp0 down sudo sh -c "echo Y > /sys/class/net/wwp0/qmi/raw_ip"
- Bring up the interface
sudo ip link set dev wwp0 up
- Next we'll use qmicli to tell the modem to start a network connection using the example APN "myoldapn". Substitute it with the APN for your existing eSIM.
sudo qmicli --device=/dev/cdc-wdm0 --device-open-proxy --wds-start-network="ip-type=4,apn=myoldapn" --client-no-release-cid
- Check the modem's network configuration
sudo qmicli --device=/dev/cdc-wdm0 --device-open-proxy --wds-get-current-settings
Record the IP address, gateway and DNS address
- Manually set the IP address of the interface. Substitute the IP address from above for 777.777.777.777
sudo ip address add 777.777.777.777 dev wwp0
- Add a default route so network traffic is routed to the USB modem's network interface
sudo ip route add default dev wwp0
- Test the network by pinging the gateway's IP address. Substitute the gateway address from above for 888.888.888.888
ping -I wwp0 888.888.888.888
- Check whether DNS is working.
curl wiki.soprani.ca
This should output "301 Moved Permanently" or some HTML.
- If DNS isn't working, first test the DNS address found above. Substitute the DNS address from above (i.e. --wds-current-settings) for 999.999.999.999
dig @999.999.999.999 wiki.soprani.ca
If this works but curl wiki.soprani.ca gives a name server error, we'll need to configure DNS.
- Different linux distributions use different mechanisms for DNS (e.g. resolv.conf resolvectl and systemd-resolved). If your system uses systemd-resolved,
edit the file /etc/systemd/resolved.conf
- find the line starting with DNS= or #DNS=
- remove the # and add the DNS address from above, for example
DNS=999.999.999.999
- restart systemd-resolved
sudo systemctl restart systemd-resolved
- verify DNS works
curl wiki.soprani.ca
- Test that lpac can still access the modem via serial port
LPAC_APDU=at AT_DEVICE=/dev/ttyUSB2 output/lpac profile list
Now return to the instructions for using lpac with a USB modem to download an eSIM profile using this network you just set up. After downloading the eSIM profile, restart ModemManager with
sudo systemctl start ModemManager
See also https://www.thinkpenguin.com/gnu-linux/using-your-usb-4g-lte-modem-terminal-tpe-usb4g2us