[Treble-Enabled Device Development A/AB ROMS] LSS4181:
The network mode can vary depending on your carrier and many aspects.

Previously I was looking for a way to disable 2G permanently on my current phone for security reasons, and I eventually was able to answer my own question after looking deeper into the Android source code.

In short, you need to change the contents in packages/services/Telephony/res/values/strings.xml to the values you want.

Look for these block (the examples are for GSM/4G ones, if your phone is CDMA you probably need to look for the blocks matching your subscription).

The first value (which maps to the LTE mode) is the one you usually need to edit.

<string-array name="enabled_networks_choices" translatable="false">
<item>@string/network_lte</item>
<item>@string/network_3G</item>
<item>@string/network_2G</item>
</string-array>
<string-array name="enabled_networks_4g_choices" translatable="false">
<item>@string/network_4G</item>
<item>@string/network_3G</item>
<item>@string/network_2G</item>
</string-array>
<string-array name="enabled_networks_values" translatable="false">
<item>"9"</item>
<item>"0"</item>
<item>"1"</item>
</string-array>

Here's a list of valid network mode values (can be found in frameworks/base/telephony/java/com/android/internal/telephony/RILConstants.java):

/* NETWORK_MODE_* See ril.h RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE */
int NETWORK_MODE_WCDMA_PREF = 0; /* GSM/WCDMA (WCDMA preferred) */
int NETWORK_MODE_GSM_ONLY = 1; /* GSM only */
int NETWORK_MODE_WCDMA_ONLY = 2; /* WCDMA only */
int NETWORK_MODE_GSM_UMTS = 3; /* GSM/WCDMA (auto mode, according to PRL)
AVAILABLE Application Settings menu*/
int NETWORK_MODE_CDMA = 4; /* CDMA and EvDo (auto mode, according to PRL)
AVAILABLE Application Settings menu*/
int NETWORK_MODE_CDMA_NO_EVDO = 5; /* CDMA only */
int NETWORK_MODE_EVDO_NO_CDMA = 6; /* EvDo only */
int NETWORK_MODE_GLOBAL = 7; /* GSM/WCDMA, CDMA, and EvDo (auto mode, according to PRL)
AVAILABLE Application Settings menu*/
int NETWORK_MODE_LTE_CDMA_EVDO = 8; /* LTE, CDMA and EvDo */
int NETWORK_MODE_LTE_GSM_WCDMA = 9; /* LTE, GSM/WCDMA */
int NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA = 10; /* LTE, CDMA, EvDo, GSM/WCDMA */
int NETWORK_MODE_LTE_ONLY = 11; /* LTE Only mode. */
int NETWORK_MODE_LTE_WCDMA = 12; /* LTE/WCDMA */
int NETWORK_MODE_TDSCDMA_ONLY = 13; /* TD-SCDMA only */
int NETWORK_MODE_TDSCDMA_WCDMA = 14; /* TD-SCDMA and WCDMA */
int NETWORK_MODE_LTE_TDSCDMA = 15; /* TD-SCDMA and LTE */
int NETWORK_MODE_TDSCDMA_GSM = 16; /* TD-SCDMA and GSM */
int NETWORK_MODE_LTE_TDSCDMA_GSM = 17; /* TD-SCDMA,GSM and LTE */
int NETWORK_MODE_TDSCDMA_GSM_WCDMA = 18; /* TD-SCDMA, GSM/WCDMA */
int NETWORK_MODE_LTE_TDSCDMA_WCDMA = 19; /* TD-SCDMA, WCDMA and LTE */
int NETWORK_MODE_LTE_TDSCDMA_GSM_WCDMA = 20; /* TD-SCDMA, GSM/WCDMA and LTE */
int NETWORK_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA = 21; /*TD-SCDMA,EvDo,CDMA,GSM/WCDMA*/
int NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA = 22; /* TD-SCDMA/LTE/GSM/WCDMA, CDMA, and EvDo */
int PREFERRED_NETWORK_MODE = Integer.parseInt(TelephonyManager.getTelephonyProperty(0,
"ro.telephony.default_network", Integer.toString(NETWORK_MODE_WCDMA_PREF)));

Aside from that, you'll also need to edit your build.prop file (system or vendor) if "ro.telephony.default_network" is in there (this seems to take a higher priority). Edit it to match the network mode you want to persist.