1

How can I configure iptables firewall on my Ubuntu virtual machine that has IP address 192.168.36.51 to allow a webserver running on port 8888 on the host machine to be only accessible from another machine on the network with the following IP address 192.168.36.202.

Considering the firewall is running the default settings.

I have a virtual lab that has Kali Linux, Windows 8 and Ubuntu. On the Ubuntu I have apache server running and I did this command to block the traffic:

sudo iptables -A INPUT -p tcp -s 192.168.36.202 --dport 8888 -j ACCEPT
sudo iptables -A OUTPUT -d 192.168.36.202 -j ACCEPT
sudo iptables -P INPUT DROP
sudo iptables -P OUTPUT DROP 
4
  • Are you sure that what you've shown us doesn't do what you need? Commented Oct 30, 2020 at 21:30
  • 1
    That first sentence if very long. It is hard to keep it all in by head and decode it. It would be much easier to read if you broke that paragraph into 2 or 3 sentances. Commented Nov 7, 2020 at 22:51
  • Which one is the "host" machine? Commented Nov 7, 2020 at 22:52
  • You told us what you tired, but what happened? Commented Nov 7, 2020 at 22:55

1 Answer 1

2

You are almost there. The rules on Ubuntu server should look like this:

# Flush away previous broken rules
 sudo iptables -F
# Allow SSH
 sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
# Allow HTTP on TCP 8888   
 sudo iptables -A INPUT -p tcp -s 192.168.36.202 --dport 8888 -j ACCEPT
# Allow return traffic
 sudo iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
# And finally deny everything (inbound)
 sudo iptables -A INPUT -j DROP
2
  • Thank you so much Bruce, I was close, but I was missing the -m state command. Thanks again for you help Commented Nov 2, 2020 at 16:49
  • 2
    Thanks Khedir, and you are welcome. Please mark the question as solved Commented Nov 2, 2020 at 18:46

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.