株式会社ヴァンデミックシステム

Blog

<スポンサーリンク>

構成

大まかな手順

  1. パブリックサブネットにNATサーバを立てる(OUT→IN)
  2. FTPサーバに新たにネットワークインターフェースをアタッチして、2NICの構成にする
  3. vsftpdを2つ起動し、それぞれのネットワークインターフェースでListenできるようにする

環境

  • プライベートサブネットにあるFTPサーバに対して、内部からの経路と外部インターネットからの経路両方でアクセスできるようにする
  • 内部からは、LANあるいはVPCピアリング先のネットワークからのアクセス
  • 外部からは、インターネットを経由して、パブリックサブネットに配置するIPマスカレードサーバを通して、FTPサーバまでたどり着く
  • FTPサーバはパッシブモードで動作させる
  • FTPサーバは内部からFTP要求を受け付けるIPが172.16.0.1、外部からは172.16.0.2のてい
  • パッシブモードはクライアントからの要求のみで通信が確率するが、アクティブモード(古い)は、クライアントからの要求のあとにサーバからクライアントへの要求があるため、クライアント側にもポート開放したりする必要がある

まず、パブリックサブネットのIPマスカレードサーバを作る。
これは、Firewalldの機能を利用する。iptablesでもたぶんOK。使い慣れているほうで。

# firewalldインストール
yum -y  install firewalld
systemctl enable firewalld.service
systemctl start firewalld.service
systemctl status firewalld.service
# IPマスカレードを有効化
firewall-cmd  --add-masquerade --permanent
firewall-cmd --reload
firewall-cmd --query-masquerade
cat /proc/sys/net/ipv4/ip_forward
1
# 設定書き込み
firewall-cmd --runtime-to-permanent
firewall-cmd --reload
# FTP接続に必要なポートを内部サーバへ転送するための設定を投入
firewall-cmd  --add-forward-port=port=21:proto=tcp:toport=21:toaddr=172.16.0.2
firewall-cmd  --add-forward-port=port=60000-65000:proto=tcp:toport=60000-65000:toaddr=172.16.0.2

FTPサーバにネットワークインターフェースをアタッチする。
この際に、プライベートIPアドレスは固定化しておく。

FTPサーバにて、FTPプロセスを2つ動作させるようにする。
vsftpd.confをglobal.vsftpd.confなどでコピーして、それぞれ次のように設定する。

それぞれ次のように設定する。
vsftpd.conf(内部から)

listen_address=172.16.0.1
pasv_min_port=65000
pasv_max_port=65535

global.vsftpd.conf(外部から)

listen_address=172.16.0.2
pasv_address=108.XXX.XXX.XXX
pasv_min_port=65000
pasv_max_port=65535

 

confファイルのセットが完了したら、systemdユニットファイルを作る。

cp -p /etc/systemd/system/vsftpd.service /etc/systemd/system/global_vsftpd.service

このような感じで、読み込むファイルを変更する。

cat /etc/systemd/system/global_vsftpd.service
[Unit]
Description=Vsftpd ftp daemon
After=network.target

[Service]
Type=forking
ExecStart=/usr/sbin/vsftpd /etc/vsftpd/global.vsftpd.conf
#ExecStart=/usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf /etc/vsftpd/global.vsftpd.conf

[Install]
WantedBy=multi-user.target

systemdユニットファイルが完成したら、enableにして自動的に起動するようにする。

systemctl enable  global_vsftpd.service

最後は、プロセスが2つ起動していて、外部内部それぞれからアクセスできればOK。

sh-4.2$ ps -ef | grep ftp | grep -v grep
root      4557     1  0 08:18 ?        00:00:00 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
root      4939     1  0 08:29 ?        00:00:00 /usr/sbin/vsftpd /etc/vsftpd/global.vsftpd.conf

 

<スポンサーリンク>

コメントを残す

Allowed tags:  you may use these HTML tags and attributes: <a href="">, <strong>, <em>, <h1>, <h2>, <h3>
Please note:  all comments go through moderation.

*

日本語が含まれない投稿は無視されますのでご注意ください。(スパム対策)