NetworkTraining Part.3 - careerbeat/dit-ehime GitHub Wiki
クライアントからWebサーバへNATして接続できるか検証
仮想マシン | インターフェイス |
---|---|
example2.local | eth0:192.168.1.2 |
example.local | eth0:192.168.1.1 eth1:192.168.0.30 |
web.local | eth0:192.168.0.45 |
example2からNATルーターを中継してWebサーバへ接続
クライアント:example2
NATルータ:example
サーバ:web
実行手順はNetworkTraining Part.2の知識でカバーできます。
そのため用語の解説等については
NetworkTraining Part.2 まとめを参考にしてください。
example# iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -d 192.168.0.0/24 -j MASQUERADE
example# service iptables save
※一時的に設定を変更する場合には必要ではない
example# iptables -t nat -nL -v
以下のように記載されていれば成功
pkts bytes target prot opt in out source destination
1 60 MASQUERADE all -- * * 192.168.1.0/24 192.168.0.0/24
example# vim /etc/sysctl.conf
net.ipv4.ip_forward = 1
初期の状態ではパラメータが0になっている
example# sysctl -p
example2# route add default gw 192.168.1.1
routeコマンドを実行して、
ルーティングテーブル内にdefaultがあれば成功
example2# route
web# route add default gw 192.168.0.30
routeコマンドを実行して、
ルーティングテーブル内にdefaultがあれば成功
web# route
web# service httpd start
example2# wget http://192.168.0.45/index.html
※クライアントのブラウザから
"http://192.168.0.45/index.html"
アクセスして確認すると良い
example2# vim /etc/httpd/conf/httpd.conf
HTTPの待ち受けポートを80から8080に変更する
Listen 8080
example2# service httpd restart
サーバから80ポートで接続した場合に、
8080接続にNATルータが変換できるようにする
example# iptables -t nat -A PREROUTING -s 0.0.0.0/0.0.0.0 -d 192.168.1.0/24 -p tcp --dport 80 -j DNAT --to 192.168.1.2:8080
example# iptables -t nat -A POSTROUTING -s 0.0.0.0/0.0.0.0 -d 192.168.1.0/24 -j MASQUERADE
example# service iptables save
※一時的に設定を変更する場合には必要ではない
example2# wget http://192.168.1.2/index.html
※サーバのブラウザから
"http://192.168.1.2/index.html"
アクセスして確認すると良い