Hyper-Vを利用したサーバ検証環境の構築 その4 VyOSの設定とSquid構築

1. 前書き

前回の続きです。
前回はHyper-Vの仮想スイッチにNATネットワークの設定をし、VyOSからインターネット接続を確認しました。
今回はDMZにProxyを構築し、internalのWindowsからProxy経由でWebアクセスができるところまでを書きます。

2.構成

今回はVyOSの設定変更と、WebProxyの新規作成、Win10の配置変更とProxyの設定を行い、internalのネットワークからインターネット接続を確認します。

3.VyOSの設定追加

構成図となるようにVlanの設定をします。

vyos@vyos# set interfaces ethernet eth1 vif 2
vyos@vyos# set interfaces ethernet eth2 vif 3

DMZセグメントからインターネットに出るため、DynamicNATの設定をします。

vyos@vyos# set nat source rule 100 outbound-interface eth0
vyos@vyos# set nat source rule 100 source address 10.24.1.0/24
vyos@vyos# set nat source rule 100 translation address masquerade

4.Ubuntuをインストール

第一世代、動的メモリをOFFでUbuntuを構築します。
バージョンはubuntu-22.04.2です。
Try or Install Ubuntu Server を選択 Englishを選択 キーボードはお好みで。Englishが無難。 Ubuntu Serverを選択 IPアドレスの設定、Edit IPv4を選択 Manualを選択 SubnetはVlan3の10.24.1.0/24
AddressはProxyサーバのアドレスである10.24.1.10
GatewayはVyOSのeth2に割り当てた10.24.1.2
を設定します。(DNSGoogle Proxyは指定せず次へ ここは何も変更せず次へ Diskも次へ すべてのDisk領域を使うための選択 SizeをMaxにする Done&Continue サーバ名:proxy
ユーザ名:user
パスワード:お好きなパスワードを。
ubuntu proはスキップ

OpenSSHはインストールしておく

インストールが終わったら再起動し、シャットダウンする

Hyper-Vの設定でVlan3を設定する

5.SquidをインストールしforwardProxyを構築

Squidのインストール

下記のコマンドでsquidをインストールします。

user@proxy:/$ sudo apt install squid

Squidの設定

Squidの設定ファイルを編集します。

user@proxy:/$ sudo vi /etc/squid/squid.conf

/should be allowedで検索し、aclを追加します。
Allow_DMZ_NetworkとAllow_internal_Networkを追加しています。

# Example rule allowing access from your local networks.
# Adapt to list your (internal) IP networks from where browsing
# should be allowed
acl localnet src 0.0.0.1-0.255.255.255  # RFC 1122 "this" network (LAN)
acl localnet src 10.0.0.0/8             # RFC 1918 local private network (LAN)
acl localnet src 100.64.0.0/10          # RFC 6598 shared address space (CGN)
acl localnet src 169.254.0.0/16         # RFC 3927 link-local (directly plugged) machines
acl localnet src 172.16.0.0/12          # RFC 1918 local private network (LAN)
acl localnet src 192.168.0.0/16         # RFC 1918 local private network (LAN)
acl localnet src fc00::/7               # RFC 4193 local private network range
acl localnet src fe80::/10              # RFC 4291 link-local (directly plugged) machines
+ acl Allow_DMZ_Network src 10.24.1.0/24 #DMZ Local Network
+ acl Allow_internal_Network src 10.24.2.0/24 #internal Local Network

acl SSL_ports port 443
acl Safe_ports port 80          # http
acl Safe_ports port 21          # ftp
acl Safe_ports port 443         # https
acl Safe_ports port 70          # gopher
acl Safe_ports port 210         # wais
acl Safe_ports port 1025-65535  # unregistered ports
acl Safe_ports port 280         # http-mgmt
/should be allowed

/http_access deny to_localhostで検索し、コメントを外します。

# We strongly recommend the following be uncommented to protect innocent
# web applications running on the proxy server who think the only
# one who can access services on "localhost" is a local user
- # http_access deny to_localhost
+ http_access deny to_localhost

/http_access allow localhostで検索し、先ほど追加したaclのAllow_DMZ_NetworkとAllow_internal_Networkを追加します。
このときhttp_access deny allよりも前にルールを記載しないと通信ができないので注意します。

# 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
+ http_access allow Allow_DMZ_Network
+ http_access allow Allow_internal_Network

# And finally deny all other access to this proxy
http_access deny all

Proxyのポートを変更します。
/http_port 3128で検索し、値を8080に変更します。(正直好みです)

# Squid normally listens to port 3128
- http_port 3128
+ http_port 8080

編集を保存して、squidを再起動します。

user@proxy:/$ sudo systemctl restart squid

squidの動作確認

internalの仮想スイッチに接続したWindows10からWebの接続確認をします。
Hyper-vネットワークアダプターのVlanIDに2を設定します。

IPアドレスの設定をします。

[設定]->[ネットワークとインターネット]->[プロキシ]を設定します。

インターネット接続が確認できました。

次回はついにRADIUSの構築となります。