0

My company uses a proxy configuration to access internal resources, and I'm the only dev using Ubuntu (20.04) so I've been rolling my own equivalent to their Mac script. I can get everything working using the Network system settings panel but clicking on "Network Proxy" and setting the "manual" configuration, but I want to set these settings via the CLI from a script. I've been searching for a while today but can't find anything that seems to explain how to set a system level proxy setting; so I turn to y'all.

Is there a CLI equivalent to the "Network Proxy" settings in the System > Network settings screen?

I specifically need to set SOCKS host & port, and ensure a list of Ignore Hosts is respected.

Any guidance greatly appreciated!

K. Adam
  • 103

1 Answers1

1

If you don't want to use a GUI, you've got a handful of options. First off, there's nmcli con edit [network-profile], and then there's nmcli con mod [network-profile], and finally you can edit raw text files directly (assuming you're running as root). By [network-profile], I mean the name of the network profile you want to configure.

The first wants to be used interactivity, but you can pass any/all options to stdin. In other words, you'll need to do something like `echo options | nmcli con edit [network-profile]".

The second lets you specify parameters via the command-line, but anything you don't specify may or may not be blanked out, removing pre-existing settings you didn't necessarily want. For instance, if you modify a VPN connection and change one thing in vpn.data, you have to change everything, or lose a bunch of settings.

The third means editing files in /etc/NetworkManager/system-connections/, and then reloading those file - either by restarting NetworkManager (thus temporarily loosing network connectivity), or by running nmcli con reload (as root).

Either way, you're going to have to mess things up a bit in order to learn. (I'm still learning.) If you do, it doesn't need to be the end of the world, but you're advised to keep backups in case things go south.

As for ignoring hosts, there's a file, /etc/hosts.deny, which is a text file that, as far as I know, doesn't come with any tools to automate the changes, you you'll need to code your way around that issue on your own. By default, the file comes with nothing but comments, which are meant to help users see how to use this file.

TSJNachos117
  • 1,444
  • 2
  • 15
  • 19