Tomcat on Port 80 – Setting Up on Amazon Linux 2 with Iptables

amazon-linuxamazon-linux-2iptablesport-forwardingtomcat

I'm configuring a new EC2 instance, which will be running Tomcat, and I want it accessible on Port 80.

Within Amazon Linux 1, the primary strategy I saw people using was to use iptables to do port forwarding. It's not my ideal strategy, but it has worked fine.

Setting up a new EC2 instances with Amazon Linux 2, it quickly became apparent that Amazon Linux 2 uses systemd. As a result, you definitely can't do service iptables save:

The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, force-reload, status). For other actions, please try to use systemctl.

Sure. So is there an iptables service like there seems to be in some distros? systemctl status iptables suggests no:

Unit iptables.service could not be found.

Is there a mechanism in Amazon Linux to to load iptables configuration from a file? I don't mind putting my configuration in a file, or doing an iptables-save to a file, but I haven't found any sign in Amazon Linux 2 that there's a mechanism already in place to use a file. If there isn't one, what's the best strategy — make my own iptables unit in systemd? Or is there a better way to make Tomcat accessible on Port 80 with Amazon Linux 2?

Best Answer

iptables isn't installed by default. You need to run:

yum install iptables-services

But, iptables is also deprecated, in favor if firewalld.

However, my personal preference to exposing tomcat on port 80 is to actually front it with apache httpd using mod_proxy. httpd listens on port 80, and proxies to port 8080.