1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Linux】Proxy適用

Last updated at Posted at 2020-07-17

プライベートなサーバからProxy経由で外に出たい!な場合
確認OSはRHEL9.4
いくつか設定できる箇所がある。

/etc/environment

適用範囲: システム全体
読み込みタイミング: シェルに依存せず主にログイン時に読み込まれる。シェルスクリプトから直接は読み込まれない
特性:
環境変数を設定するためのファイル。システム全体で共通の環境変数を設定するため、各ユーザーに対して一貫している。コンテナからも参照できる

/etc/environment
HTTP_PROXY="http://proxy.example.com:port"
HTTPS_PROXY="http://proxy.example.com:port"
NO_PROXY=.local,172.10.0.0/24,host01
http_proxy="http://proxy.example.com:port"
https_proxy="http://proxy.example.com:port"
no_proxy=.local,172.10.0.0/24,host01

no_proxyはproxy経由させたくない場合に使用。(ローカル通信など)
カンマで区切って複数指定できる

/etc/profile

適用範囲: ログインシェル
読み込みタイミング: ログインシェルが起動される際に読み込まれる
特性:
Bashやその他のシェルの設定を行うためのファイル。ユーザーがログインしたときに実行されるスクリプトで、一般的にユーザーごとに異なる環境設定を行うことができる。
他のスクリプトや設定ファイル(/etc/profile.d/ 内のファイル)を呼び出すこともできる。

/etc/profile
export HTTP_PROXY="http://proxy.example.com:port"
export HTTPS_PROXY="http://proxy.example.com:port"
export NO_PROXY=.local,172.10.0.0/24,host01
export http_proxy="http://proxy.example.com:port"
export https_proxy="http://proxy.example.com:port"
export no_proxy=.local,172.10.0.0/24,host01

/etc/profile.d/ 内のファイルも記載内容としては同様

ユーザ毎に設定したい場合は、bashrc.bash_profile
以下がわかりやすいです

特定のプログラムやデーモンには個別にプロキシ設定が必要な場合もあるため、その場合は該当アプリケーションの設定ファイルを編集すること。

例)
redhat subscription managerの参照先をプロキシにしたい場合は/etc/rhsm/rhsm.conf
dockerでも以下の設定が必要。

[root@host01 docker.service.d]# pwd
/etc/systemd/system/docker.service.d
[root@host01 docker.service.d]# ls
override.conf
[root@host01 docker.service.d]# cat override.conf
[Service]
Environment = 'http_proxy=http://user:P@ssw0rd@172.21.0.254:8080' 'https_proxy=http://user:P@ssw0rd@172.21.0.254:8080' 'no_proxy=localhost,127.0.0.1'

[root@host01 docker.service.d]# systemctl daemon-reload
[root@host01 docker.service.d]# systemctl restart docker

適用の順番(上から)

ログインシェル=ユーザーがログインする際に起動するシェル(SSH/コンソールでのログイン、su - など)

/etc/environment (環境変数の設定)
/etc/profile (システム全体のログインシェル用設定)
/etc/profile.d/*.sh (追加の設定スクリプト)
~/.bash_profile (ユーザー個別のログインシェル用設定)
~/.bashrc (ユーザー個別の非ログインシェル用設定、~/.bash_profile 内で呼び出されることが多い)

非ログインシェル=既存のシェルから新たに起動されたシェル(端末エミュレータを開いたときやスクリプトから呼び出されたとき)

/etc/environment (環境変数の設定)
~/.bashrc (ユーザー個別の非ログインシェル用設定)

適用・確認

即時反映させるには以下コマンド

# source /etc/environment

確認

# printenv

ちなみにproxypac等を利用していた場合、PROXYにpacのパスをそのままいれても効かないので注意です。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?