Although iOS (and macOS) is based on a flavor of nix, changing the network settings
from the command line is not as simple as executing ifconfig. Changing system
wide persistent proxy settings, for example, is not done by modifying a file.
To persist network configuration changes, use the Apple scutil cli tool (see
man scutil).
...
NAME
scutil – Manage system configuration parameters
SYNOPSIS
scutil
scutil --prefs [preference-file]
scutil -r [-W] { nodename | address | local-address remote-address }
scutil -w dynamic-store-key [-t timeout]
scutil --get pref
scutil --set pref [newval]
scutil --dns
scutil --proxy
scutil --nc nc-arguments
...
scutil --proxy gives information about the current configuration for
the network proxy.
A key observation is to scutil is that entries are stored as dictionary
entries. It is similar to JSON maps.
To set a proxy, you will need to create a new dictionary entry and set the entry.
You need to create dictionaries (d.init) if one didn't exist before,
add key-values to dictionaries (d.add),
use get State:/Network/Global/Proxies and d.show to get the current running config, and
set State:/Network/Global/Proxies to change the current running config.
Likewise, to remove a proxy, you would need to
use get State:/Network/Global/Proxies to get the current running config,
use d.remove to remove dictionary keys, and
use set State:/Network/Global/Proxies to set the current running config.
Persisted configuration (i.e., not the current running configuration) is stored
under the keys starting with Setup:. Use the scutil's list command to
enumerate all the subkeys.
Example:
#!/bin/sh
proxy_host=$1
proxy_port=$2
# Find UUID of the primary IPv4 iface
output=$(scutil<< EOF
get State:/Network/Global/IPv4
d.show
quit
EOF)
iface_uuid=$(echo $output | grep -o -E '\b[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}\b')
# Update proxy settings for the primary IPv4 iface
scutil<< EOF
get State:/Network/Global/Proxies
d.add HTTPEnable # 1
d.add HTTPPort # $proxy_port
d.add HTTPProxy $proxy_host
d.add HTTPSEnable # 1
d.add HTTPSPort # $proxy_port
d.add HTTPSProxy $proxy_host
set State:/Network/Global/Proxies
get Setup:/Network/Service/$iface_uuid/Proxies
d.add HTTPEnable # 1
d.add HTTPPort # $proxy_port
d.add HTTPProxy $proxy_host
d.add HTTPSEnable # 1
d.add HTTPSPort # $proxy_port
d.add HTTPSProxy $proxy_host
set Setup:/Network/Service/$iface_uuid/Proxies
quit
EOF
echo "done.. $?"