
我已經尋找過,但我嘗試過的一切都不起作用
我有兩台 Centos 機器,機器1與一個enp0s3( 192.168.56.99 IP
) 和機器2和 (enp0s8 192.168.56.101
和enp0s3 10.0.2.15 IPs
)。如您所見,我的內部網路是192.168.56.0/24
,我想透過機器 2 將機器 1 連接到網路。
如果重要的話,這些是在 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