0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

直接WANに繋がずにラズパイのaptをアップデートする話

Last updated at Posted at 2022-05-16

動機

LANでラズパイをたくさん繋げて遊んでたら他にもパッケージが欲しくなったestis.
ラズパイを外部に出してあげるにはWiFiを使うしかなかったが,認証に必要な情報をラズパイに渡したくなかったので仕方なくProxyを使うことに.
道行く道に立ちはだかるよくわからないエラー.
estisは解決して目的を達成できるのか!(できました)

あくまで成功事例の一つです.ご注意ください.

マシンとネットワークの構成

proxy_real.png

プロキシを入れるマシン: 192.168.13.1
ラズパイ: 192.168.12.4

IPアドレスの振り方が気持ち悪かったり,ネットワークがこんなことになってることには目を瞑りましょう.

手法

squidの準備

1: squidをインストールする

sudo apt install squid -y

2: squidの設定ファイル(/etc/squid/squid.conf)をいじる

# line 1197
# 2022-05-12 added for raspi
acl localnet src 192.168.12.0/24
acl localnet src 192.168.13.0/24
# line 1415
# Example rule allowing access from your local networks.
# Adapt localnet in the ACL section to list your (internal) IP networks
# from where browsing should be allowed
http_access allow localnet
# http_access allow localhost

3: squidの起動

sudo systemctl start squid

4: 動作確認
サーバのマシンで

curl -x 192.168.13.1:3128 -sS https://www.yahoo.co.jp | head -n 10

を叩いて返ってきたらok!

以下はラズパイ側の設定

1: aptでproxyを使うように設定ファイル(/etc/apt/apt.conf/80proxy)を作成していじる.

# line 1
Acquire::http::proxy "http://192.168.13.1:3128/";
Acquire::https::proxy "https://192.168.13.1:3128/";
Acquire::ftp::proxy "ftp://192.168.13.1:3128/";
Acquire::socks::proxy "socks://192.168.13.1:3128/";

詰まった点

  1. squidのデフォルト設定でlocalhostしかhttp_accessが許可されてなかったのでうまく通信できなかった.
    1197行付近で設定されているのはlocalnetに関するものなので,それを許可してあげないといけない.
    • /var/log/squid/access.logにログがあるので,ここにあるエラーから調べて原因を探った.
  2. proxyだけだとDNSがうまくいかないので,ラズパイでは4.のコマンドがうまくいかない.次に進む.

DNSサーバ(bind)の準備

いつものサイトを参考に設定.
動くことを目標にしたので設定の最小性は保証できません.

1: bindのインストール

sudo apt -y install bind9 bind9utils

2: bindの設定ファイルの一つ(/etc/bind/named.conf.options)をいじる

# line 1
acl internal-network {
        192.168.12.0/24;
        192.168.13.0/24;
};
    # line 30
    allow-query { localhost; internal-network; };
    allow-transfer { localhost; };
    recursion yes;

3: 実行

sudo systemctl restart named

以下はラズパイ側の設定

1: DHCPの設定ファイル(/etc/dhcpcd.conf)をいじる.

# line 55
static domain_name_servers = 192.168.13.1

2: dhcpcdの再起動

sudo systemctl restart dhcpcd

3: 動作確認
ラズパイで

curl -x 192.168.13.1:3128 -sS https://www.yahoo.co.jp | head -n 10

を叩いて返ってきたらok!

詰まった点

そろそろapt-updateするか,と思ってしたら以下のエラーが出た.

raspi2@raspberrypi:~ $ sudo apt update
Get:1 http://archive.raspberrypi.org/debian bullseye InRelease [23.7 kB]
Get:2 http://raspbian.raspberrypi.org/raspbian bullseye InRelease [15.0 kB]
Reading package lists... Done     
E: Release file for http://archive.raspberrypi.org/debian/dists/bullseye/InRelease is not valid yet (invalid for another 34d 17h 39min 8s). Updates for this repository will not be applied.
E: Release file for http://raspbian.raspberrypi.org/raspbian/dists/bullseye/InRelease is not valid yet (invalid for another 37d 11h 38min 19s). Updates for this repository will not be applied.

dateコマンドを叩くと時間がえらいことになってるのでNTPが必要とわかったが,どうやらproxy下では簡単に解決できるいい方法はなさそう.
仕方ないのでNTPサーバも立てた.次に進む.

NTPサーバの準備

いつものサイト2を参考に設定.

1: ntpdのインストール

sudo apt -y install ntp

2: ntpdの設定ファイル(/etc/ntp.conf
)をいじる

# line 16
# Specify one or more NTP servers.

# Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board
# on 2011-02-08 (LP: #104525). See http://www.pool.ntp.org/join.html for
# more information.
# pool 0.ubuntu.pool.ntp.org iburst
# pool 1.ubuntu.pool.ntp.org iburst
# pool 2.ubuntu.pool.ntp.org iburst
# pool 3.ubuntu.pool.ntp.org iburst

# Use Ubuntu's ntp server as a fallback.
# pool ntp.ubuntu.com
pool ntp.nict.jp iburst

3: ntpdの起動

sudo systemctl start ntp

以下はラズパイ側の設定

1: timesyncedの設定ファイル(/etc/systemd/timesyncd.conf)をいじる.

# line 15
NTP=192.168.13.1

2: NTPの設定の有効化

sudo timedatectl set-ntp true
sudo systemctl daemon-reload
sudo systemctl restart systemd-timesyncd.service
sudo systemctl status systemd-timesyncd

dateコマンドを叩いて正しい時間になってたらok!
なってない場合はtimezoneを確認するといいかもしれない.

参考文献

疑問点

reverse shellというのがあるけど,あれってこういう問題をなんとか踏み倒せたりしないのかな

ノート

ラズパイにはdhcpでipアドレスを配ってるので,配る時にdnsサーバのipアドレスも渡しといて上げると楽になって良い.

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?