
探してみたけど、試した方法がすべてうまくいかなかった
Centosを搭載したマシンが2台あります。マシン1とともにえんぷ0s3(192.168.56.99 IP
)、 そしてそのマシン2と (えんぷ0s8 192.168.56.101
そしてえんぷ0s3 10.0.2.15 IPs
)。ご覧のとおり、私の内部ネットワークは であり192.168.56.0/24
、マシン 1 をマシン 2 経由でインターネットに接続したいと考えています。
重要であれば、これらは Windows 10 ホスト上の VirtualBox で実行されている VM です。
どうすればいいでしょうか? ありがとうございます。
答え1
iptables
ゲートウェイマシンのフレンドになるはずです。例えば、次のように設定します。ゲートウェイを設定するためのDebianガイドは、eth0 を内部ネットワーク カードとして使用し、eth1 を外部アドレスとして使用し、次のスクリプトを提供します。
#!/bin/sh
# run as root
#
# delete all existing rules.
#
iptables -F
iptables -t nat -F
iptables -t mangle -F
iptables -X
# Always accept loopback traffic
iptables -A INPUT -i lo -j ACCEPT
# Allow established connections, and those not coming from the outside
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -m state --state NEW -i ! eth1 -j ACCEPT
iptables -A FORWARD -i eth1 -o eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT
# Allow outgoing connections from the LAN side.
iptables -A FORWARD -i eth0 -o eth1 -j ACCEPT
# Masquerade.
iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
# Don't forward from the outside to the inside.
iptables -A FORWARD -i eth1 -o eth1 -j REJECT
# Enable routing.
echo 1 > /proc/sys/net/ipv4/ip_forward