I have issue in Ubuntu 18.04 Server to configurate internal and external network. Case is that i have Gateway device which has DHCP service to lease IP addresses for wlan connected devices. Gateway device eth0 IP address is and Gateway device wlan0 has static IP address and first wlan client gets IP address. Gateway device eth0 has internet access. But wlan0 connected devices should only have access to Gateway device services e.g. MySql or custom REST API's.

Rule 1: Gateway device should have access to internet.


Rule 2: Wlan connected devices should have only access to Gateway device services.


What i have done is that i have installed Ubuntu 18.04 Server and installed basic services and now i'm in point that i should create network restrictions.

I have done following settings to get wlan0 connected devices to be able to use Gateway device services. But also wlan0 connected devices has now internet access which should be restricted.



iptables configuration

iptables -F
iptables -t nat -F
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables-save  > /etc/iptables/rules.v4
iptables-restore  < /etc/iptables/rules.v4

Can some one help me with the configuration?

1 Answer 1


To solve your problematic, you have to work with the FORWARD chain of the filter table. The FORWARD tables is used to filter every packet that are to or from the host. (At contrary, the INPUT table is for incoming trafic, OUTPUT table for outgoing trafic). There's actually two approaches:

1/ You limit all the trafic and open on a per-need basis:

iptables -t filter -P FORWARD DROP

iptables -t filter -A FORWARD [your rule #1 to match allowed streams(s)] -j ACCEPT

2/ You limit the trafic only for the devices you want restrict access:

iptables -t filter -P FORWARD ACCEPT
iptables -t filter -A FORWARD [your rule #1 to match forbidden stream(s)] -j REJECT --reject-with admin-prohib

Usually, the good practice in terms of security is the 1st approach.

  • Thanks a lot. I got it work as planned. Apr 18, 2020 at 13:40

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.