Routing auf Centos 7.3 zum Internet

Routing auf Centos 7.3 zum Internet

Ich habe gesucht, aber alles, was ich versucht habe, funktioniert nicht

Ich habe zwei Maschinen mit Centos,Maschine 1mit einemenp0s3( 192.168.56.99 IP), und dasMaschine 2mit (enp0s8 192.168.56.101Undenp0s3 10.0.2.15 IPs). Wie Sie sehen, ist mein internes Netzwerk das 192.168.56.0/24, und ich möchte Maschine 1 über Maschine 2 mit dem Internet verbinden.

Falls es von Bedeutung ist: Dies sind VMs, die in VirtualBox auf einem Windows 10-Host ausgeführt werden.

Wie könnte ich das machen? Danke.

Antwort1

iptablessollte Ihr Freund für Ihre Gateway-Maschine sein, z. B. konfiguriert ähnlich wiedieser Debian-Leitfaden zum Einrichten eines Gateways, das eth0 als interne Netzwerkkarte und eth1 als externe Adresse verwendet und dann folgendes Skript bereitstellt:

#!/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

verwandte Informationen