Edukasi

Port forwarding TPC traffic to another server with firewalld

During the first covid lockdown and while working from home, I had a requirement to access a web application running from a data centre to which I didn’t have direct access.

In the diagram below, the web application runs on the server marked by a green square. So let’s call this the target server.

I had access to our AWS servers via a bastion host, which had network access to the target server via a direct connect link.

This article demonstrates how I used firewalld to port forward traffic to the target server. In addition, it illustrates how I used an SSH tunnel to get traffic from my development machine to the server with firewalld installed. This SSH tunnel is depicted in the diagram by the red arrows.

Then we’ll look at the firewalld configuration, which forwards the traffic to the target server—depicted on the diagram with the blue lines.

The result being I was able to access the web service from my development machine using a local address of 127.0.0.1

Let’s assume the IP address of the bastion server is 3.8.8.8, and the IP address of the server running firewalld is 10.10.10.001. The command below creates an SSH tunnel mapping the local port 8443 on my development machine to the 8443 port on the firewalld server.

ssh -L 8443:10.10.10.001:8443 3.8.8.8 -l ec2-user -N

Installing firewalld

Depending on your Linux distribution, the installation of firewalld should be relativity easy using either apt-get or yum. You’ll need to elevate your privileges to root to install the service. Once installed, you’ll need to start the firewalld service and permanently add port 22 for SSH access and the port you want to reflect onto another server. In this case, port 8443.

systemctl start firewalld
firewall-cmd --zone=public --add-port=22/tcp --permanent
firewall-cmd --zone=public --add-port=8443/tcp --permanent

To allow the IP forwarding to work, you need to switch on IP masquerading by issuing the following command.

firewall-cmd --zone=public --add-masquerade

Forwarding the port traffic

Finally, we can add the rule to port forward traffic from the firewalld server to the target server’s final destination. In this example, the target servers IP address is 10.11.10.163

In this example, we’re mapping port 8443 directly to port 8443, but you could direct/forward the traffic to a different target port if you needed to.

firewall-cmd
   --zone=public 
   --add-forward-port=port=8443:proto=tcp:toport=8443:toaddr=10.11.10.163

Stopping firewalld

To stop the firewall from forwarding the traffic, use the system control command to stop it.

systemctl stop firewalld

Versions

  • 15.02.2023 – slight rewrite of document. Added link to firewalld’s project page.
  • 11.10.2020 – initial document created.
ryan

Recent Posts

Jadwal Imsak dan Buka Puasa Ramadhan 2025 Kota Serang Selama Sebulan

Berikut jadwal imsak dan buka puasa Ramadhan 2025 di Kota Serang dari tanggal 1 Ramadhan -…

4 hari ago

Jadwal Resmi Awal Puasa Ramadan 2025 Pemerintah, NU, Muhammadiyah

Jakarta - Pemerintah telah menetapkan awal Ramadan 2025 berdasarkan hasil sidang isbat oleh Kemenag. Begitu pula dengan organisasi masyarakat…

6 hari ago

Meta AI Ditanya Luas Kebakaran Los Angeles, Hasilnya Mengejutkan Sama dengan Luas Gaza

Siapa sangka, salah satu warganet justru mendapat informasi tak terduga yang berasal dari Meta AI.…

2 bulan ago

Tebak-tebakan pelesetan kata ini lucu abis, awas ketawa ngakak

Ketika menjalani rutinitas sehari-hari tentu saja kamu pernah merasa suntuk atau jenuh. Supaya kamu bisa…

2 bulan ago

Kapal China Diduga Biang Kerok Internet Mati Total di Berbagai Negara

Sebuah kapal kargo komersial China diduga sengaja menyeret jangkarnya untuk memotong kabel bawah laut yang…

3 bulan ago

Ini Sumber Kekayaan Nabi Sulaiman, Sungguh di Luar Dugaan

Nabi Sulaiman dikenal sebagai raja yang kaya raya. Para ilmuwan arkeologi kini mengungkap apa sumber kekayaannya,…

3 bulan ago