How to configure proxy in CentOS 7 and RHEL 7

In this tutorial we see, how to configure proxy in CentOS 7 and RHEL 7. We will also see proxy configuration through command line and yum.conf file. So let start and see proxy configuration in CentOS 7 and RHEL 7.

First of all we should know what is proxy server? So let’s explain it first.

What is Proxy Server

A proxy server intercepts all client requests, and provides responses from its cache or forwards the request to the real server. A client can request some service, such as a file, connection, web page, or other resource available from a different server and the proxy server evaluates the request as a way to simplify and control its complexity.

Verify proxy on your server before proxy setting

You can verify proxy on your system using echo command, if you have all ready proxy configured on your system. Like below:-

#echo $http_proxy
[[email protected] ~]# echo $http_proxy
[[email protected] ~]#

You can see we don’t have any proxy setting on our server in above screen shot.

Proxy Setting through Command line

The http_proxy environment variable is used to specify proxy settings to client programs such as curl and wget. You can see some proxy setting example in below through command line.

Configure proxy without username and password required

We can configure proxy without username and password like below:-

# export http_proxy=http://SERVER:PORT/
[[email protected] ~]# export http_proxy=http://192.168.30.50:80
[[email protected] ~]#
[[email protected] ~]# echo $http_proxy
http://192.168.30.50:80
[[email protected] ~]#

You can see in above screen shot we have successfully set proxy server with port.

Remove proxy using unset commands

We can also remove proxy with unset command. Like below:-

[[email protected] ~]# unset http_proxy
[[email protected] ~]# echo $http_proxy
[[email protected] ~]#

You can see in above we have remove proxy through unset proxy commands.

Configure proxy with username and password authentication

You can also configure proxy with username and password authentication like below:-

# export http_proxy=http://USERNAME:[email protected]:PORT/
[[email protected] ~]# export http_proxy=http://urclouds:[email protected]:80
[[email protected] ~]# echo $http_proxy
http://urclouds:[email protected]:80
[[email protected] ~]#

You can see we have successfully set proxy with username and password in above screen shot.

Configure proxy with domain, username and password required option

We can configure proxy with username/password authentication along with the Domain name. Like below:-

# export http_proxy=http://DOMAIN\\USERNAME:[email protected]:PORT/
[[email protected] ~]# export http_proxy=http://test\\urclouds:[email protected]:80
[[email protected] ~]# echo $http_proxy
http://test\urclouds:[email protected]:80
[[email protected] ~]#

You can see we have successfully set proxy with domain name username and password in above screen shot.

Special character handling in proxy setting

Literal backslash characters (\) need to be doubled escape them as shown below.

# export http_proxy=http://DOMAIN\\USERNAME:[email protected]:PORT/

If we have a @ symbol in our username and password then we need to add a backslash (\) before the @ you can see example below:-

# export http_proxy=http://DOMAIN\\USERN\@ME:[email protected]:PORT
[[email protected] ~]# export http_proxy=http://test\\urclouds\@ME:[email protected]:80
[[email protected] ~]# echo $http_proxy
http://test\[email protected]:[email protected]:80
[[email protected] ~]#

or

# export http_proxy=http://DOMAIN\\USERNAME:P\@[email protected]:PORT
[[email protected] ~]# export http_proxy=http://test\\urclouds:abc\@[email protected]:80
[[email protected] ~]# echo $http_proxy
http://test\urclouds:[email protected]@192.168.30.50:80
[[email protected] ~]#

You can see in above screen shot we have successfully set password or username where we have a @ symbol.

Permanently Proxy configuration in CentOS 7  and RHEL 7 (for processes without shell)

We can define the environment variables in /etc/environment file if we want to add a permanent proxy in the CentOS 7 and  RHEL 7. Like below:-

# echo "http_proxy=http://proxy.example.com:80/" > /etc/environment
[[email protected] ~]# echo "http_proxy=http://192.168.30.50:80/" > /etc/environment
[[email protected] ~]# cat /etc/environment
http_proxy=http://192.168.30.50:80/
[[email protected] ~]#

You can see we have successfully added proxy in /etc/environment file in above screen shot.

Note that unlike a shell script in /etc/profile.d described in the next section, the /etc/environment file is NOT a shell script and applies to all processes without a shell.

Configuring proxy for processes with SHELL

For bash and sh users, add the export line given above into a new file called /etc/profile.d/http_proxy.sh file:

# echo "export http_proxy=http://proxy.example.com:80/" > /etc/profile.d/http_proxy.sh
[[email protected] ~]# echo "export http_proxy=http://192.168.30.50:80/" > /etc/profile.d/http_proxy.sh
[[email protected] ~]# ls -l /etc/profile.d/http_proxy.sh
-rw-r--r-- 1 root root 43 Jan 12 18:00 /etc/profile.d/http_proxy.sh
[[email protected] ~]# cat /etc/profile.d/http_proxy.sh
export http_proxy=http://192.168.30.50:80/
[[email protected] ~]#

Proxy setting for other programs

If we want to use yum program to install package through internet repository or any local repository then we need to set proxy into  /etc/yum.conf. like below:-

[[email protected] ~]# cat /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=5
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release
#  This is the default, if you make this bigger yum won't see if the metadata
# is newer on the remote and so you'll "gain" the bandwidth of not having to
# download the new metadata and "pay" for it by yum not having correct
# information.
#  It is esp. important, to have correct metadata, for distributions like
# Fedora which don't keep old packages around. If you don't like this checking
# interupting your command line usage, it's much better to have something
# manually check the metadata once an hour (yum-updatesd will do this).
# metadata_expire=90m
# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d
proxy=http://192.168.30.50:80
proxy_username=urclouds
proxy_password=abc123

[[email protected] ~]#

Proxy setting in Mozilla browser in CentOS 7 and RHEL 7

First of all click on Applications then click on Firefox web browser. Then your Firefox we browser will be open. Now you have to click open menu on right side top corner. Then you have to select preferences. After that we need to click on Advance then we have to select network and click on setting. After that we can get a windows where we can set proxy. Like below:-

That’s all we have configure proxy in CentOS 7 and RHEL 7 in this tutorial.

How to configure VLAN network in RHEL 7 and CentOS 7

25 thoughts on “How to configure proxy in CentOS 7 and RHEL 7

  1. Hi guys! Just wanted to drop you a line to say that I really enjoyed reading your guest article on Peaches and Screams UK site! Great perspective. Have an awesome day!

  2. Wow, marvelous blog layout! How long have you been blogging for? you make blogging look easy. The overall look of your web site is magnificent, let alone the content!

  3. Very nice post. I just stumbled upon your weblog and wanted to mention that I have reallyloved surfing around your blog posts. In any case I’ll be subscribingfor your rss feed and I am hoping you write oncemore soon!

  4. I was suggested this blog by my cousin. I’m not sure whether this post is written by him as nobody else know such detailed about my trouble. You are incredible! Thanks!

  5. Superb blog! Do you have any helpful hints for aspiring writers? I’m hoping to start my own blog soon but I’m a little lost on everything. Would you advise starting with a free platform like WordPress or go for a paid option? There are so many choices out there that I’m completely confused .. Any ideas? Appreciate it!

  6. Its like you read my mind! You appear to know a lot about this, like you wrote the book in it or something. I think that you can do with a few pics to drive the message home a little bit, but other than that, this is excellent blog. An excellent read. I’ll certainly be back.

  7. You have observed very interesting details ! ps nice site. “Become addicted to constant and never-ending self improvement.” by Anthony D’Angelo.

  8. I take pleasure in, result in I discovered just what I used to be having a look for. You have ended my 4 day lengthy hunt! God Bless you man. Have a great day. Bye

  9. This is very interesting, You are a very skilled blogger. I have joined your rss feed and look forward to seeking more of your wonderful post. Also, I’ve shared your web site in my social networks!

  10. Excellent blog! Do you have any tips for aspiring writers? I’m hoping to start my own site soon but I’m a little lost on everything. Would you suggest starting with a free platform like WordPress or go for a paid option? There are so many choices out there that I’m totally overwhelmed .. Any suggestions? Kudos!

  11. As I site possessor I believe the content material here is rattling great , appreciate it for your hard work. You should keep it up forever! Good Luck.

  12. Hi, I do think this is a great site. I stumbledupon it 😉 I’m going to
    come back once again since I saved as a favorite it. Money and freedom is the greatest
    way to change, may you be rich and continue to help other people.

  13. Hello I am so excited I found your website, I really found you
    by accident, while I was browsing on Google for something else, Anyhow I am here now and would just like to say thanks for
    a fantastic post and a all round exciting blog (I
    also love the theme/design), I don’t have time to go through it
    all at the moment but I have bookmarked it and also included your RSS feeds,
    so when I have time I will be back to read
    a great deal more, Please do keep up the fantastic jo.

  14. hey there and thank you for your info – I have definitely picked up anything new from right here.
    I did however expertise some technical points using this web site, as I experienced to
    reload the website many times previous to I could get it to load properly.
    I had been wondering if your hosting is OK? Not
    that I’m complaining, but slow loading instances times will often affect your placement in google
    and can damage your quality score if advertising and marketing with Adwords.

    Well I’m adding this RSS to my e-mail and can look out for a lot more of your respective
    fascinating content. Make sure you update this again very soon.

  15. Hello! This is my 1st comment here so I just wanted to give a quick shout
    out and say I really enjoy reading through your articles.
    Can you recommend any other blogs/websites/forums that go over the same topics?
    Appreciate it!

  16. I read this paragraph completely regarding the resemblance of
    newest and earlier technologies, it’s remarkable article.

  17. Hello, Neat post. There is a problem with your website in internet
    explorer, may check this? IE still is the market leader and a huge part of folks will leave
    out your great writing because of this problem.

  18. hi!,I love your writing so much! percentage we be in contact more about your article on AOL?

    I require an expert on this house to solve my problem.
    May be that’s you! Looking ahead to look you.

  19. I blog often and I seriously appreciate your information. This article has truly peaked my interest. I am going to take a note of your website and keep checking for new information about once per week. I opted in for your Feed too.

Leave a Reply

Your email address will not be published. Required fields are marked *