Centos 7.3からインターネットにルーティング

Centos 7.3からインターネットにルーティング

検索しましたが、試行したすべての項目は機能しません。

2つのCentosマシンがあります。マシン1enp0s3192.168.56.99 IP)とマシン2そして(enp0s8 192.168.56.101そしてenp0s3 10.0.2.15 IPs)。ご覧のとおり、私の内部ネットワークは、192.168.56.0/24マシン1をマシン2を介してインターネットに接続したいと思います。

重要な場合は、Windows 10 ホストの VirtualBox で実行される仮想マシンです。

どうすればいいですか?ありがとうございます。

ベストアンサー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

おすすめ記事