Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
HOWTO: Automatically set proxies based on network
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
therealpete
n00b
n00b


Joined: 02 Feb 2004
Posts: 5

PostPosted: Thu Nov 23, 2006 9:37 am    Post subject: HOWTO: Automatically set proxies based on network Reply with quote

If you have to change locations a lot with your laptop (different companies, different networks, different proxy settings), this tip is for you:

A lot of programs can get their proxy settings from environment variables (http_proxy, ftp_proxy etc.). Amongst them are Gaim, wget, Google Earth, portage and Firefox/Thunderbird with this extension.

To automatically set these variables based on the network, follow these steps (this assumes that you use dhcpcd as your dhcp client):

  • Create a directory /etc/proxy.d
  • for each network, you want a proxy set, create a file in this directory with the ip address of the network, like /etc/proxy.d/20.15.50.0
    Code:
    export RSYNC_PROXY="<yourproxy>:<yourport>"
    export http_proxy="<yourproxy>:<yourport>"
    export https_proxy="<yourproxy>:<yourport>"
    export ftp_proxy="<yourproxy>:<yourport>"
    export no_proxy="127.0.0.1,localhost"

  • create a file /etc/proxy.d/noproxy
    Code:
    unset RSYNC_PROXY
    unset http_proxy
    unset ftp_proxy
    unset https_proxy
    unset no_proxy

  • create the following script /etc/dhcpc/dhcpcd.exe (it has to have that name, even it is not a binary) and make it executable
    Code:
    #!/bin/bash

    if [ "$2" = "new" ]
       then
          source $1;
          if [ -r /etc/proxy.d/$NETWORK ]
             then
                ln -sf /etc/proxy.d/$NETWORK /etc/profile.d/proxy.sh;
             else
                ln -sf /etc/proxy.d/noproxy /etc/profile.d/proxy.sh;
          fi
    fi



Now everytime you get a new ip address, your proxy settings change. If you move locations without rebooting, you have to log out and back in to get the new profile.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum