Creating Ubuntu 18.04 Masquerade



  • Ubuntu 18.04.5 Installed
  • Updated Operating to current patch level
  • Both iptables-persistent & netfilter-persistent packages

System Details 

  • Ubuntu 18.04.5
  • Internet interface: eno1
  • Ubuntu 18.04.5 IP Address: <-- we use the host IP as the gateway on all clients wanting Internet.

Update Ubuntu 18.04 


Edit /etc/sysctl.conf and insert the line below for IP forwarding 

Add below line inside sysctl.conf like example below 


Apply the settings by typing the below command 

Startup Requirements 

You must have an idea of which interfaces you want to route traffic through for the masquerade.

Please see command below for Masquerade Command reference.

Installing Software 

Install the software by typing below commands 

Masquerade Commands 

The server or machine that will provide internet to other client machines. The active interface we specified below is where the host get it's active Internet from which is eno1 interface.

iptables -t nat --append POSTROUTING --out-interface eno1 -j MASQUERADE
iptables --append FORWARD --in-interface eno1 -j ACCEPT

You can usually find the active internet interface by using the route command with the -n switch. The example below shows gateway is using interface eno1 just like we have in our iptables commands above. 

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface         UG    600    0        0 eno1   U     0      0        0 pan1   U     0      0        0 vmnet8   U     600    0        0 eno1   U     0      0        0 vmnet1   U     0      0        0 virbr0 

Save & Apply iptable rules 

Enable the rules during startup using below command for every boot. 

Client Machine Setup

The client machine is the machine on the same network as the masqueraded server machine that needs access through the host machine to get Internet.

The below netplan configuration is an example of how you should setup IPv4 gateway.

# This is the network config written by 'subiquity'

  version: 2
      dhcp4: true
      dhcp4: no
              addresses: [,] 

The above netplan example shows we specified the gateway4: parameter with the hosts IP as the gateway. 

Font size: +
Report Print

By accepting you will be accessing a service provided by a third-party external to