Score:0

Use online VM as default Gateway (Jump box)

ru flag

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.

la flag
try this on jumpbox: iptables -t nat -A POSTROUTING -o public_internet_interface -j MASQUERADE
GeoCom avatar
ru flag
@MartynasSaint I will get error when I add the interface name _No ... by that name_
GeoCom avatar
ru flag
Fixed above issue but still no ping from offline VM.
la flag
try to see if the rule is hit - iptables -vL . maybe docker puts some rules that are matched first
GeoCom avatar
ru flag
yes it is there, ip range for docker is in different range
Score:0
za flag

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.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.