I have look for, but all I tried, doesn't work

I have two machines with Centos, Machine 1 with a enp0s3 ( IP), and the Machine 2 with (enp0s8 and enp0s3 IPs). As you can see, my internal network is the, and I want to connect the Machine 1 to internet through the Machine 2.

In case it matters, these are VMs running in VirtualBox on a Windows 10 host.

How could I do it? Thanks.

  • Your best bet is to used netcat – Rui F Ribeiro Dec 17 '16 at 20:14
  • @RuiFRibeiro Could you give me some web page, to help me? Thanks – Quico Llinares Llorens Dec 17 '16 at 20:45
  • CentOS 5, 6 or 7? – jsbillings Dec 17 '16 at 21:16
  • @jsbillings Centos 7.3 – Quico Llinares Llorens Dec 17 '16 at 21:19
  • looks like a VirtualBox network. Are these VMs? If so, is one the Host? – roaima Dec 17 '16 at 21:47

iptables should be your friend for your gateway machine, e.g. configured similar to this Debian guide for setting up a gateway, which uses eth0 to be the internal network card and eth1 as the external address and then provides following script:

# 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
  • When I try to do iptables -A INPUT -m state --state NEW -i ! enp0s3-j ACCEPT it says that enp0s3 is a bad argument – Quico Llinares Llorens Dec 17 '16 at 23:29
  • Doing in this way it doesn't show an error: iptables -A INPUT -m state --state NEW ! -i enp0s3-j ACCEPT, but I can't still do a ping to from my machine 1. Have I to execute the script when machine 1 is up, or have I to do something on machine 1? Thanks. – Quico Llinares Llorens Dec 18 '16 at 11:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.