Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I have to use proxy servers to connect to the internet. I have set all proxies in my system proxy settings. Now I can connect to Internet using my browser and applications.

But I cannot connect to internet from my terminal.

I tried

export http_proxy="http://username:password@proxyserver:port/" 

But still terminal applications cannot connect to the internet.

share|improve this question
1  
Which command are you executing in Terminal to "connect to the internet"? Or how do you see that you are not able to connect? –  patrix Aug 22 '13 at 6:03
1  
The proxy server(with no s) you are talking of here is relaying your web connexions, not all your Internet connexions. web connexions are using ports 80, 443…. Internet connexions may use all the remaining ports of the 65536 set. As an example an ssh connexion will use port 22 which won't go through your http proxy server. Hence the question of patrix to help you get a better answer. –  daniel Azuelos Aug 22 '13 at 6:43
    
@patrix ping google.com –  TLE Aug 22 '13 at 10:25
    
@TLE Ping is an exception to the rule and actually does not use the proxy at all, even if http_proxy is set. Ping expects a direct connection, and in a lot of cases when a proxy is being used, ping will fail although the proxy will still successfully connect. –  Diago Aug 22 '13 at 10:46
2  
try curl -o /dev/null www.google.com instead of ping –  patrix Aug 22 '13 at 10:57
show 3 more comments

2 Answers 2

up vote 3 down vote accepted

Terminal does not use proxy settings configured in the network preferences pane because it doesn't do any connection. Terminal just let you fire commands which will use the network in different ways.

When setting your http_proxy and https_proxy environment variables should not include the http: or https: prefixes.

Therefore the environment variable in your case should read:

http_proxy=username:password@proxyserver:port

Note: many old programs have issues with connecting through proxy servers which require authentication before connecting.

Additional Tip:

Due to our infrastructure we found it much easier to have users run SquidMan locally and have it configured to connect to our main proxy. This allows the local machine to act as a proxy directly, and eliminates a lot of authentication issues etc when using proxy servers on Mac machines, especially in a mixed and AD environments.

In the case of using this method our http_proxy and https_proxy would be:

http_proxy=localhost:3128
share|improve this answer
    
you mean I have to write export http_proxy="username:password@proxyserver:port" –  TLE Aug 22 '13 at 10:24
    
@TLE Correct. Terminal does not need to know the protocol since it already knows it's a HTTP connection. –  Diago Aug 22 '13 at 10:41
    
But still I am unable to connect to the Internet. –  TLE Aug 22 '13 at 10:43
    
@TLE Then the problem most likely with the authentication. Try setting the proxy without including the username and password, which means you will be prompted for the information when trying to connect. It normally indicates the proxy itself does not support the connection from Terminal. We had a similar problem internally which is why I suggested the SquidMan solution. –  Diago Aug 22 '13 at 10:45
    
still not working?? –  TLE Aug 22 '13 at 10:47
show 10 more comments

You can use the following command in the Terminal Window.

networksetup -setairportnetwork $Interface $ssID $Password

Here, $Interface is the "enX" style identifier for your AirPort card (usually en1, but it's en0 on MacBook Airs and en2 on Mac Pros, and can vary for other reasons as well)

$ssID is your network name, such as "Simon's SSID". Enclose it in quotes if it contains spaces.

$Password is your WEP, WPA-PSK, or WPA2-PSK password.

share|improve this answer
    
This configures the network, it does not allow the terminal itself to connect via a proxy. –  Diago Aug 22 '13 at 7:57
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.