Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I use a proxy server settings at work but when i get home, my network connection uses no proxy settings.

every time i get home and use the proxy settings under settings->networks->Network Proxy to set to "none", the file /etc/apt/apt.conf gets cleared and the following day in the morning i have to edit the file and type in the command again, or at least copy paste from a backup file.

How can i avoid this situation, its tiring, how can i make the proxy settings gui write to this file for apt-get and software center to work when i set proxy under network settings?

share|improve this question
add comment

2 Answers

You could put the proxy configuration in /etc/apt/apt.conf.d/70proxy.conf, create this file and put your proxy config in there.

Acquire::http::Proxy "http://whatever:port"

Then when you get home, you can just rename that file. Note that only files ending in .conf (or files with no extension) will be considered by apt, so you can potentially just rename it to /etc/apt/apt.conf.d/70proxy.disabled and it will not be considered.

You can then automate it with stuff like this, you can create a .bash_aliases file in your home directory and put this in it:

export APT_PROXY_BASE=/etc/apt/apt.conf.d/70proxy
alias enable-proxy="[ -f ${APT_PROXY_BASE}.disabled ] && sudo mv ${APT_PROXY_BASE}.disabled ${APT_PROXY_BASE}.conf"
alias disable-proxy="[ -f ${APT_PROXY_BASE}.conf ] && sudo mv ${APT_PROXY_BASE}.conf ${APT_PROXY_BASE}.disabled"

To enable the proxy, just issue

enable-proxy

and to disable:

disable-proxy

Beware, I didn't test it :) it's just meant to get you on the right track.

share|improve this answer
    
thanks for pointing me on the right track. i thought Aliases are used to rename commands, and sometimes to include options, and the general format is alias mycommand='UNIXcommand' if so then i have problems understanding the ones you gave for enable-proxy and disable-proxy, i dont see an "=" sign, instead it's a whitespace and the commands aren't in quotation. i also dont quite understand what -f option is used for here. If you could please elaborate a little more, i'd appreciate a lot. –  Muriuki David Apr 19 '12 at 13:35
    
Like I said, I didn't test it :) yes, I'm missing the '=' sign. I fixed it now. –  roadmr Apr 19 '12 at 13:52
    
the [ -f $filename ] construct returns a "true" or success value if the named file exists. I'm using this to avoid errors if you try to move a non-existing file; this could happen if you issued 'disable-proxy' twice in a row. So if the file does not exist, the alias will not even attempt to move it. –  roadmr Apr 19 '12 at 13:55
    
yeah, thats much better, didnt work though, logged out, logged back in and in terminal, disable-proxy or enable-proxy are not found. I ma thinking setting this up for at environment level would make sure wen i open a new terminal, its available. dont know how to do that though. FYI, it works if i do the commands in a terminal session. –  Muriuki David Apr 19 '12 at 14:44
    
Apologies again, I updated with the correct location to put the aliases (.bash_aliases). –  roadmr Apr 19 '12 at 15:18
show 2 more comments

In Ubuntu 12.04 LTS:

When you come home, try not applying no-proxy system-wide. This doesn't edit the apt.conf file, yet software center uses no proxy. Works for me, dunno how.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.