0

I have two Ubuntu servers:

  • Server 1 (IP: 192.168.10.11) is online and connect to two network interface (internal, public)

  • Server 2 (IP: 192.168.10.10) with no public access (internal)

I am trying to use server1 as a default gateway for server2, and this is what I've done:

# on online server (Jumpbox)
iptables -t nat -A POSTROUTING -s 192.168.10.10 ! -d 192.168.30.1/24 -j MASQUERADE
echo 1 > /proc/sys/net/ipv4/ip_forward

# On offline server
route add default gw 192.168.10.11

Docker is installed on both (172.17.0.0)

They can PING each other, but from server2 it is not possible to PING Google.

Dave M
  • 4,514
  • 22
  • 31
  • 30
GeoCom
  • 101
  • 1

1 Answers1

0

Debian Style (the lazy way):

edit /etc/network/interfaces

iface eth0 inet static
address  10.0.0.1
netmask  255.0.0.0
post-up   echo 1 > /proc/sys/net/ipv4/ip_forward
post-up   iptables -t nat -A POSTROUTING -s '10.0.0.0/8' -o eth0 -j MASQUERADE
post-down iptables -t nat -D POSTROUTING -s '10.0.0.0/8' -o eth0 -j MASQUERADE

The Lazy Crontab Way:

edit /etc/crontab

@reboot root "echo 1 > /proc/sys/net/ipv4/ip_forward; iptables -t nat -A POSTROUTING -s '10.0.0.0/8' -o eth0 -j MASQUERADE; iptables -t nat -D POSTROUTING -s '10.0.0.0/8' -o eth0 -j MASQUERADE"

Bash Style:

nano /root/allow_lan_nat.sh
You have to ajust the correct LAN that fits to you which might
192.168.0.0/24 (One Lan Subnet, Default Class C)
192.168.0.0/16 (all Subnets of 192.168)
172.16.0.0/16 (Default Class B)
10.0.0.0/8 (Default Class A)

#!/bin/bash
#Ajust the LAN, as above shown
MYLANIP=10.0.0.0/8

#The IFACE that has Internet.
MYINETIFACE=eth0
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -s $MYLANIP -o $MYINETIFACE -j MASQUERADE
iptables -t nat -D POSTROUTING -s $MYLANIP -o $MYINETIFACE -j MASQUERADE 

run bash /root/allow_lan_nat.sh

Direct answer to your question

Remind, that at i state this Answer, i dont know the Interface, so i assume ens3 s your interface that face to the internet, else update it like above

echo 1 > /proc/sys/net/ipv4/ip_forward  
iptables -t nat -A POSTROUTING -s '192.168.10.0/24' -o ens3 -j MASQUERADE  
iptables -t nat -D POSTROUTING -s '192.168.10.0/24' -o ens3 -j MASQUERADE  

REMIND, ens3 must be the internet facing interface so update it to your needs.

djdomi
  • 1,599
  • 3
  • 12
  • 19