Interview Prep/Linux/Networking, DNS and firewalls

A service can't connect to an external API only from inside a systemd unit, but works from your shell.

IntermediateTroubleshootingNetworking, DNS and firewalls
Answer

Likely causes → Proxy variables exist in your shell profile but not in the unit; or IPAddressDeny=/RestrictAddressFamilies=/PrivateNetwork= in the unit blocks it.

Diagnose →

env | grep -i proxy
systemctl show myapp -p Environment -p IPAddressDeny -p PrivateNetwork -p RestrictAddressFamilies

Fix → Add Environment=HTTPS_PROXY=http://proxy:3128 NO_PROXY=.internal to the unit, or relax the sandbox option.

Prevent → Define required environment in units explicitly; never rely on login profiles.

All Linux questions Roadmap: Linux

More on Networking, DNS and firewalls